Global Stats

Analytics dashboard for finalised games
Auth Required Multi-endpoint
/app/stats.html

Aggregates performance, usage, and distribution metrics across all finalised games.

Source file

  • /app/stats.html (HTML + inline JS) [oai_citation:0‡stats.html](sediment://file_000000008cc0724380f7ae2513275d85)

APIs used

EndpointPurpose
stats/perf_by_race.phpPerformance by race
stats/perf_by_race_faction.phpPerformance by race + faction
stats/common.phpMost/least common races + factions
stats/unit_usage.phpUnit usage stats
race/list.phpPopulate race dropdown
factions/list.phpPopulate faction dropdown

Page structure

  • Topbar navigation (standard layout)
  • Filters section
  • Performance (race / race+faction)
  • Most / least common
  • Unit usage (race → faction → table)

Filters

  • Include archived → affects all queries
  • Performance view → race vs race+faction
  • Unit usage → race + faction dependent dropdown

Performance logic

  • Win: score diff > 100
  • Loss: score diff < -100
  • Draw: otherwise
  • Percentages calculated client-side
Matches backend scoring conventions. [oai_citation:1‡stats.html](sediment://file_000000008cc0724380f7ae2513275d85)

Common stats

  • Top + bottom races
  • Top + bottom factions
  • Pure count-based aggregation

Unit usage flow

  1. Load races → populate dropdown
  2. Select race → load factions
  3. Select faction → load usage
  4. Render full unit list (including zero usage)

Data flow

  • Initial load → init()
  • Load races
  • Load performance + common
  • User interaction triggers further API calls

State management

  • racesCache for dropdown reuse
  • DOM-driven state (no framework)
  • Button disabling during async calls

UX behaviour

  • Immediate refresh on filter change
  • Graceful empty states
  • Error messaging per section
  • Tables dynamically generated

Security

  • requireAuthOrRedirect() enforced
  • 401 → forced logout

Risks / observations

  • Large inline script (hard to maintain)
  • No pagination for large datasets
  • Repeated rendering logic (tables)
  • No loading indicators

Recommended improvements

  • Split into stats.js
  • Introduce reusable table renderer
  • Add loading states/spinners
  • Add caching for API responses
  • Consider chart visualisations (later)

Architecture note

This is your first true analytics dashboard page — multiple endpoints, aggregation logic, and dependent UI controls. It should be the template for future reporting features.