monkeytype
monkeytype copied to clipboard
Save speed stats in leaderboard update
Saves a histogram data structure of speeds for buckets rounded to the nearest 10.
Signed-off-by: Brian Evans [email protected]
Description
I have added to the leaderboard update function to save some global stats for all users.
It saves in public collection with type speedStats.
The data structure saved is:
{
"type":"speedStats",
"english_time_15":{"110":1},
"english_time_60":{"90":1}
}
Closes #3650
Status update
Finished:
- save public stats when leaderboard is calculated
- serve public stats on endpoint
- get data on frontend with Ape client
Still todo:
- implement histogram display logic (following https://github.com/monkeytypegame/monkeytype/commit/7dff50dc3032cd0c7a897da70825892745878a5b)
Should look something like this (but with users on the y axis):

The PR check action failed. Please review the logs and make the necessary changes. https://github.com/monkeytypegame/monkeytype/actions/runs/3255261581
Made some test data and this is what the graph looks like:

Perf
The performance of calculating the buckets when the leaderboard is updated: (using my test data set of ~50,000 users)
system_lb_update_english_time_60 "Aggregate 1.078039699971676s, loop 0.002202499985694885s, insert 2.367039000034332s, index 0.24052349996566771s, histogram 0.005574600040912628"
Only for comparison purposes, ignore absolute values. Takes 20x less time to calculate histogram buckets than to aggregate, so performance shouldn't be a problem.
I think this feature is ready to be merged, unless there are any requests for changes?
Thanks @Bruception for the feedback, I've implemented those points (except for the route change discussed on discord).
Looking good. Things left to do:
- [ ] Rename endpoint, rename dal and controller files
- [ ] Add an endpoint which gets the typing stats (started, completed, time typing)
- [ ] Add a section above the about section, call it stats
- [ ] Display tests started, completed, time typing in hours (3 columns)
- [ ] Display the time 60 histogram below the stats
- [ ] Make sure the about page is responsive (currently the histogram is causing an overflow)
The PR check action failed. Please review the logs and make the necessary changes. https://github.com/monkeytypegame/monkeytype/actions/runs/3266759160
The PR check action failed. Please review the logs and make the necessary changes. https://github.com/monkeytypegame/monkeytype/actions/runs/3266857729

Okay @Miodec , I've addressed all of your points. I hope this is what you had in mind, let me know if not or if anything needs changing.
I think it will be quite nice for users to be able to see these stats.
The PR check action failed. Please review the logs and make the necessary changes. https://github.com/monkeytypegame/monkeytype/actions/runs/3267158048