-
Notifications
You must be signed in to change notification settings - Fork 150
Site: Optimize dojo stats and update dashboard layout #959
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: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
dojo_plugin/utils/stats.py
Outdated
| challenge_ids = [c.challenge_id for c in dojo.challenges] | ||
|
|
||
| stats = db.session.execute( | ||
| text(""" | ||
| SELECT | ||
| COUNT(DISTINCT user_id) as total_users, | ||
| COUNT(*) as total_solves | ||
| FROM submissions | ||
| WHERE type = 'correct' | ||
| AND challenge_id = ANY(:challenge_ids) | ||
| """), |
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.
Preserve visibility/admin filters in dojo stats queries
The new raw SQL in get_dojo_stats() now counts all correct submissions for the dojo’s challenge IDs without the filters that dojo.solves() previously applied. Admin solves, hidden users, challenges that aren’t yet visible, and optional challenges all contribute to total_users and total_solves, whereas the old implementation excluded them by default. This inflates the dashboard statistics and can leak activity for hidden or unreleased challenges. Consider reproducing the filter set from dojo.solves() so the numbers match what the rest of the site treats as public progress.
Useful? React with 👍 / 👎.
dojo_plugin/utils/stats.py
Outdated
| challenge_ids = [c.challenge_id for c in dojo.challenges] | ||
|
|
||
| stats = db.session.execute( | ||
| text(""" | ||
| SELECT | ||
| COUNT(DISTINCT user_id) as total_users, | ||
| COUNT(*) as total_solves | ||
| FROM submissions | ||
| WHERE type = 'correct' | ||
| AND challenge_id = ANY(:challenge_ids) | ||
| """), | ||
| {"challenge_ids": challenge_ids} |
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.
Handle dojos without challenges before executing ANY() query
When a dojo has no challenges, challenge_ids is an empty list. Executing challenge_id = ANY(:challenge_ids) with an empty list causes PostgreSQL to raise cannot determine type of empty array, resulting in a 500 when the stats page is rendered for a freshly created dojo. The previous implementation simply returned zeros in this case. Guard against an empty list (return zeros early or cast the parameter to a typed empty array) before running the SQL.
Useful? React with 👍 / 👎.
|
|

Updates the dojo stats function and updates the stats dashboard to simplify the displayed stats. The
get_dojo_stats()function now uses direct SQL queries, removed chart and trend data. The stat dashboard has been redesigned to fit the updated results of the stats function.(Award logic is unchanged; I do not have any awards data locally)
Backend stats calculation:
Frontend dashboard redesign:
UI and styling improvements: