Skip to content

Add module-level stats to the background stats worker #1042

@adamdoupe

Description

@adamdoupe

Summary

The background stats worker currently only calculates stats at the dojo level (calculate_dojo_stats in dojo_plugin/worker/handlers/dojo_stats.py). We should extend it to also calculate and cache stats at the module level, then display them on the module page.

What exists today

  • Dojo-level stats: calculated by the background worker, cached in Redis (stats:dojo:{reference_id}), displayed via stat_dashboard.html on dojo.html
  • Module-level: module.solves() exists and can scope queries to a single module, but no stats are calculated or cached for modules
  • Module page: shows per-challenge solve counts and a scoreboard, but no aggregate stats dashboard

What needs to be done

Backend

  • Add calculate_module_stats(module) function (similar to calculate_dojo_stats but using module.solves())
  • Add a module stats event handler in the worker (e.g., handle_module_stats_update)
  • Cache module stats in Redis with key pattern stats:module:{dojo_reference_id}:{module_id}
  • Fan out stats events to affected modules when solves happen (the listener already triggers on solve inserts)
  • Add get_module_stats(module) retrieval function in dojo_plugin/utils/stats.py

Frontend

  • Pass module stats from view_module() in dojo_plugin/pages/dojo.py to module.html
  • Make stat_dashboard.html generic enough to render for either a dojo or a module (e.g., parameterize the header, conditionally show/hide cards like "Recent Awardees" which are dojo-specific)
  • Include the stats dashboard on module.html

Stats to include per module

  • Total Solves, Unique Hackers, Challenges count, Hacking Now (from container stats)
  • Activity History chart (daily solves/users at snapshot intervals)
  • Recent Solves
  • Trend indicators (week-over-week changes)

Key files

  • dojo_plugin/worker/handlers/dojo_stats.py - stats calculation and worker handler
  • dojo_plugin/utils/stats.py - stats retrieval
  • dojo_plugin/utils/listeners.py - event triggers
  • dojo_plugin/utils/events.py - event publishing
  • dojo_plugin/pages/dojo.py - view_module() controller
  • dojo_theme/templates/module.html - module page template
  • dojo_theme/templates/components/stat_dashboard.html - stats dashboard component

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions