-
Notifications
You must be signed in to change notification settings - Fork 19
add lb option to show-stats #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -530,32 +530,36 @@ def get_leaderboard_submissions( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| for submission in self.cursor.fetchall() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def generate_stats(self, last_day: bool): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def generate_stats(self, last_day: bool, leaderboard_name: Optional[str] = None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def generate_stats(self, last_day: bool, leaderboard_name: Optional[str] = None): | |
| def generate_stats(self, last_day: bool, leaderboard_name: Optional[str] = None): | |
| """ | |
| Generate statistics for submissions and runs. | |
| Args: | |
| last_day (bool): If True, only include data from the last 24 hours. | |
| leaderboard_name (Optional[str]): The name of the leaderboard to filter statistics for. | |
| If omitted, statistics are generated for all leaderboards. | |
| Returns: | |
| dict: A dictionary containing the generated statistics. | |
| """ |
Copilot
AI
May 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The leaderboard filter logic is duplicated across multiple methods; consider extracting a helper to build and append the WHERE/AND clauses.
Copilot
AI
May 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interpolating leaderboard_name directly into SQL with f-strings can lead to SQL injection. Use parameterized queries or query arguments instead.
| select_expr += f"AND s.leaderboard_id = (SELECT id FROM leaderboard.leaderboard WHERE name = '{leaderboard_name}')" | |
| if not last_day: | |
| select_expr = select_expr.replace("AND", "WHERE") | |
| # per-runner stats | |
| self.cursor.execute( | |
| f""" | |
| SELECT | |
| runner, | |
| COUNT(*), | |
| COUNT(*) FILTER (WHERE passed), | |
| COUNT(score), | |
| COUNT(*) FILTER (WHERE secret), | |
| MAX(runs.start_time - s.submission_time), | |
| AVG(runs.start_time - s.submission_time), | |
| SUM(runs.end_time - runs.start_time) | |
| FROM leaderboard.runs JOIN leaderboard.submission s ON submission_id = s.id | |
| {select_expr} | |
| GROUP BY runner; | |
| """ | |
| ) | |
| f""" | |
| select_expr += "AND s.leaderboard_id = (SELECT id FROM leaderboard.leaderboard WHERE name = %s)" | |
| if not last_day: | |
| select_expr = select_expr.replace("AND", "WHERE") | |
| # per-runner stats | |
| query = f""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider renaming
last_day_onlytolast_day(or vice versa) to match the database method’s parameter name and improve consistency.