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
| Endpoint | Purpose |
|---|---|
| stats/perf_by_race.php | Performance by race |
| stats/perf_by_race_faction.php | Performance by race + faction |
| stats/common.php | Most/least common races + factions |
| stats/unit_usage.php | Unit usage stats |
| race/list.php | Populate race dropdown |
| factions/list.php | Populate 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
- Load races → populate dropdown
- Select race → load factions
- Select faction → load usage
- 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
racesCachefor 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.