Alvinn-aai commited on
Commit
9d4d10e
·
1 Parent(s): 0672532

fix cutoff computation

Browse files
Files changed (1) hide show
  1. src/submission/submit.py +9 -7
src/submission/submit.py CHANGED
@@ -19,7 +19,7 @@ from src.validation.validate import is_submission_file_valid, is_valid
19
 
20
  logger = get_logger(__name__)
21
 
22
- MIN_WAIT_TIME_PER_USER_HRS = 0.0001 # TODO set to 24 for production
23
  RATE_LIMIT_WINDOW_HRS = 24
24
  MAX_SUBMISSIONS_PER_WINDOW = 10
25
 
@@ -54,20 +54,22 @@ def add_new_solutions(
54
  }
55
  )
56
 
57
- cutoff = datetime.now(timezone.utc) - timedelta(hours=RATE_LIMIT_WINDOW_HRS)
58
- user_last_sub_date = sub_df[sub_df.user_id == user_id].timestamp.max()
 
59
 
60
- if pd.notna(user_last_sub_date) and user_last_sub_date > cutoff:
61
- remaining_hrs = MIN_WAIT_TIME_PER_USER_HRS - (user_last_sub_date - cutoff).total_seconds() / 3600
62
  logger.info(f"{username} must wait {remaining_hrs:.2f} more hours.")
63
  return styled_error(
64
  f"You must wait {MIN_WAIT_TIME_PER_USER_HRS} hours between submissions. "
65
  f"Remaining wait time: {remaining_hrs:.2f} hours"
66
  )
67
 
68
- if len(sub_df.timestamp > cutoff) >= MAX_SUBMISSIONS_PER_WINDOW:
 
69
  logger.info(
70
- f"Too many submissions in the last {RATE_LIMIT_WINDOW_HRS} hours: {len(sub_df.timestamp > cutoff)}."
71
  )
72
  return styled_error("The leaderboard has reached its submission capacity for now. Please try again later.")
73
 
 
19
 
20
  logger = get_logger(__name__)
21
 
22
+ MIN_WAIT_TIME_PER_USER_HRS = 0.1 # TODO set to 24 for production
23
  RATE_LIMIT_WINDOW_HRS = 24
24
  MAX_SUBMISSIONS_PER_WINDOW = 10
25
 
 
54
  }
55
  )
56
 
57
+ now = datetime.now(timezone.utc)
58
+ cutoff_user = now - timedelta(hours=MIN_WAIT_TIME_PER_USER_HRS)
59
+ user_last_submission_ts = sub_df[sub_df.user_id == user_id].timestamp.max()
60
 
61
+ if pd.notna(user_last_submission_ts) and user_last_submission_ts > cutoff_user:
62
+ remaining_hrs = (user_last_submission_ts - cutoff_user).total_seconds() / 3600
63
  logger.info(f"{username} must wait {remaining_hrs:.2f} more hours.")
64
  return styled_error(
65
  f"You must wait {MIN_WAIT_TIME_PER_USER_HRS} hours between submissions. "
66
  f"Remaining wait time: {remaining_hrs:.2f} hours"
67
  )
68
 
69
+ cutoff_overall = now - timedelta(hours=RATE_LIMIT_WINDOW_HRS)
70
+ if len(sub_df.timestamp > cutoff_overall) >= MAX_SUBMISSIONS_PER_WINDOW:
71
  logger.info(
72
+ f"Too many submissions in the last {RATE_LIMIT_WINDOW_HRS} hours: {len(sub_df.timestamp > cutoff_overall)}."
73
  )
74
  return styled_error("The leaderboard has reached its submission capacity for now. Please try again later.")
75