Skip to content

Commit

Permalink
feat(download): add message if data is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Caceresenzo committed May 12, 2023
1 parent 203d29a commit 919c7c6
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crunch/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'crunch-cli'
__description__ = 'crunch-cli - CLI of the CrunchDAO Platform'
__version__ = '1.2.0'
__version__ = '1.2.1'
__author__ = 'Enzo CACERES'
__author_email__ = '[email protected]'
__url__ = 'https://github.com/crunchdao/crunch-cli'
4 changes: 4 additions & 0 deletions crunch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ def __init__(self, message: str):

class NeverSubmittedException(CrunchApiException):
pass


class CurrentCrunchNotFoundException(CrunchApiException):
pass
2 changes: 1 addition & 1 deletion crunch/command/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .convert import convert, convert_cells_to_file
from .download import download
from .download import download, download_no_data_available
from .push import push, push_summary
from .setup import setup
from .test import test
12 changes: 12 additions & 0 deletions crunch/command/download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import typing
import datetime

import click
import requests
Expand Down Expand Up @@ -129,3 +130,14 @@ def download(
y_train_path,
x_test_path
)

def download_no_data_available():
today = datetime.date.today()

print("\n---")

# competition lunch
if today <= datetime.date(2023, 5, 16):
print("The data will be released on May 16th, 2023, 05.00 PM CET")
else:
print("No data is available yet")
2 changes: 1 addition & 1 deletion crunch/command/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def _check_if_already_exists(directory: str, force: bool):
if os.path.exists(directory):
if force:
print(f"{directory}: deleting")
print(f"delete {directory}")
shutil.rmtree(directory)
else:
print(f"{directory}: already exists (use --force to override)")
Expand Down
20 changes: 12 additions & 8 deletions crunch/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import click
import pandas

from . import command, constants, tester, utils
from . import command, constants, tester, utils, api


class _Inline:
Expand All @@ -24,13 +24,17 @@ def __init__(self, module: typing.Any, model_directory: str):
print(f"loaded inline runner with module: {module}")

def load_data(self) -> typing.Tuple[pandas.DataFrame, pandas.DataFrame, pandas.DataFrame]:
(
_,
_,
x_train_path,
y_train_path,
x_test_path
) = command.download(self.session)
try:
(
_,
_,
x_train_path,
y_train_path,
x_test_path
) = command.download(self.session)
except api.CurrentCrunchNotFoundException:
command.download_no_data_available()
raise click.Abort()

x_train = utils.read(x_train_path)
y_train = utils.read(y_train_path)
Expand Down
13 changes: 10 additions & 3 deletions crunch/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import click

from . import command, constants, utils
from . import command, constants, utils, api

session = None
debug = False
Expand Down Expand Up @@ -65,7 +65,11 @@ def setup(

if not no_data:
os.chdir(directory)
command.download(session, force=True)

try:
command.download(session, force=True)
except api.CurrentCrunchNotFoundException:
command.download_no_data_available()

print("\n---")
print(f"Success! Your environment has been correctly setup.")
Expand Down Expand Up @@ -142,7 +146,10 @@ def test(
def download():
utils.change_root()

command.download(session)
try:
command.download(session)
except api.CurrentCrunchNotFoundException:
command.download_no_data_available()


@cli.command(help="Convert a notebook to a python script.")
Expand Down
21 changes: 13 additions & 8 deletions crunch/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import pandas
import psutil
import requests
import click

from . import command, constants, ensure, utils
from . import command, constants, ensure, utils, api


def _get_process_memory() -> int:
Expand Down Expand Up @@ -49,13 +50,17 @@ def run(
train_handler = ensure.is_function(module, "train")
infer_handler = ensure.is_function(module, "infer")

(
embargo,
moon_column_name,
x_train_path,
y_train_path,
x_test_path
) = command.download(session)
try:
(
embargo,
moon_column_name,
x_train_path,
y_train_path,
x_test_path
) = command.download(session)
except api.CurrentCrunchNotFoundException:
command.download_no_data_available()
raise click.Abort()

x_train = utils.read(x_train_path)
y_train = utils.read(y_train_path)
Expand Down
2 changes: 2 additions & 0 deletions crunch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def request(self, method, url, *args, **kwargs):
self.print_recopy_command()
elif code == "NEVER_SUBMITTED":
raise api.NeverSubmittedException(message)
elif code == "CURRENT_CRUNCH_NOT_FOUND":
raise api.CurrentCrunchNotFoundException(message)
else:
print(f"{method} {url}: {status_code}")
print(json.dumps(error, indent=4))
Expand Down

0 comments on commit 919c7c6

Please sign in to comment.