Maharshi Gor
commited on
Commit
·
419d0ad
1
Parent(s):
1eeda1d
submission formatting and error catching
Browse files- src/submission/submit.py +21 -17
src/submission/submit.py
CHANGED
@@ -51,25 +51,32 @@ def get_demo_example_submissions(competition_type: str) -> list[str]:
|
|
51 |
return [f"umdclip/{os.path.basename(f).removesuffix('.yaml')}" for f in glob.glob(f"{examples_dir}/*.yaml")]
|
52 |
|
53 |
|
54 |
-
def
|
|
|
|
|
55 |
"""Get all submissions for a user for a given competition type."""
|
56 |
-
|
57 |
-
if username is None:
|
58 |
-
raise gr.Error("Authentication required. Please log in to view your submissions.")
|
59 |
out_dir = f"{EVAL_REQUESTS_PATH}/{username}"
|
60 |
-
submissions = []
|
61 |
if not os.path.exists(out_dir):
|
62 |
-
return
|
|
|
63 |
for file in os.listdir(out_dir):
|
64 |
-
if
|
65 |
-
|
66 |
-
|
67 |
-
submission = Submission.from_dict(json.load(f))
|
68 |
-
if submission.created_at.startswith(today):
|
69 |
submissions.append(submission)
|
|
|
|
|
|
|
70 |
return submissions
|
71 |
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
def get_time_until_next_submission(tz: timezone = timezone.utc) -> str:
|
74 |
next_day_00 = datetime.now(tz) + timedelta(days=1)
|
75 |
next_day_00 = next_day_00.replace(hour=0, minute=0, second=0, microsecond=0)
|
@@ -149,9 +156,7 @@ def submit_model(
|
|
149 |
)
|
150 |
|
151 |
if f"{username}/{model_name}" in get_user_submission_names(competition_type, profile):
|
152 |
-
return styled_error(
|
153 |
-
f"Submission {model_name} already exists. Please use a different name for your submission."
|
154 |
-
)
|
155 |
|
156 |
try:
|
157 |
submission = create_submission(
|
@@ -178,9 +183,8 @@ def submit_model(
|
|
178 |
)
|
179 |
|
180 |
return styled_message(
|
181 |
-
f"Successfully submitted tossup model
|
182 |
-
f"Submission
|
183 |
-
f"Name: {username}/{model_name}\n"
|
184 |
f"Please wait for up to an hour for the model to show in the PENDING list."
|
185 |
)
|
186 |
|
|
|
51 |
return [f"umdclip/{os.path.basename(f).removesuffix('.yaml')}" for f in glob.glob(f"{examples_dir}/*.yaml")]
|
52 |
|
53 |
|
54 |
+
def get_user_submissions_by_date(
|
55 |
+
username: str, competition_type: str, year: int, month: int, day: int
|
56 |
+
) -> dict[str, list[Submission]]:
|
57 |
"""Get all submissions for a user for a given competition type."""
|
58 |
+
date_str = datetime(year, month, day).strftime("%Y%m%d")
|
|
|
|
|
59 |
out_dir = f"{EVAL_REQUESTS_PATH}/{username}"
|
|
|
60 |
if not os.path.exists(out_dir):
|
61 |
+
return {}
|
62 |
+
submissions = []
|
63 |
for file in os.listdir(out_dir):
|
64 |
+
if file.startswith(f"{competition_type}_") and date_str in file:
|
65 |
+
try:
|
66 |
+
submission = Submission.from_dict(json.load(open(os.path.join(out_dir, file))))
|
|
|
|
|
67 |
submissions.append(submission)
|
68 |
+
except Exception as e:
|
69 |
+
logger.exception(e)
|
70 |
+
logger.warning(f"Error loading submission {file}: {e}")
|
71 |
return submissions
|
72 |
|
73 |
|
74 |
+
def get_user_submissions_today(username: str, competition_type: str) -> list[Submission]:
|
75 |
+
"""Get all submissions for a user for a given competition type."""
|
76 |
+
today = datetime.now(timezone.utc)
|
77 |
+
return get_user_submissions_by_date(username, competition_type, today.year, today.month, today.day)
|
78 |
+
|
79 |
+
|
80 |
def get_time_until_next_submission(tz: timezone = timezone.utc) -> str:
|
81 |
next_day_00 = datetime.now(tz) + timedelta(days=1)
|
82 |
next_day_00 = next_day_00.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
|
156 |
)
|
157 |
|
158 |
if f"{username}/{model_name}" in get_user_submission_names(competition_type, profile):
|
159 |
+
return styled_error(f"'{model_name}' already exists. Please use a different name for your submission.")
|
|
|
|
|
160 |
|
161 |
try:
|
162 |
submission = create_submission(
|
|
|
183 |
)
|
184 |
|
185 |
return styled_message(
|
186 |
+
f"Successfully submitted tossup model!<br>"
|
187 |
+
f"Submission name: {username}/{model_name}<br>"
|
|
|
188 |
f"Please wait for up to an hour for the model to show in the PENDING list."
|
189 |
)
|
190 |
|