Skip to content

Add expanded card stats — /api/runs/card-stats + Stats tab block#264

Open
ptrlrd wants to merge 1 commit into
mainfrom
feat/card-stats-expanded
Open

Add expanded card stats — /api/runs/card-stats + Stats tab block#264
ptrlrd wants to merge 1 commit into
mainfrom
feat/card-stats-expanded

Conversation

@ptrlrd
Copy link
Copy Markdown
Owner

@ptrlrd ptrlrd commented May 14, 2026

Re-created after the 2026-05-14 12:42 UTC repo rollback closed the original #249.

Roadmap #2 of the stats expansion. New GET /api/runs/card-stats/{card_id} returning pick_rate, skip_rate, win_rate_when_in_deck, avg_copies_winning/_all, upgrade_rate, avg_ascension_picked, top_synergies (top 5 cards co-present in winning decks). Frontend EntityRunStats renders a 6-tile grid + synergy list for entityType==='cards'. Reuses run_cards + run_card_choices, no schema change.

…block

Roadmap #2 (after Codex Score). Adds richer per-card community-meta stats
to the card detail page Stats tab beyond the bulk Codex Score feed.

New endpoint GET /api/runs/card-stats/{card_id} backed by
get_card_stats() in services/runs_db.py. Aggregates from existing
run_cards + run_card_choices tables — no schema migration.

Returned fields:
  pick_rate / skip_rate                   from run_card_choices
  win_rate_when_in_deck                   runs containing card / total of those
  avg_copies_winning / avg_copies_all     deck composition signal
  upgrade_rate                            % of times upgraded when present
  avg_ascension_picked                    skews up for late-game darlings
  top_synergies (top 5)                   self-join on run_cards in wins

Computed on-demand. Each detail-page hit is one bounded SELECT + one
synergy self-join (rows for one card_id ~ low thousands, fans out to
~30 deck slots each). Well under the score-walker pre-warm budget.
Rate-limited at 120/min to match the existing /stats endpoints.

EntityRunStats now fetches /api/runs/card-stats/{id} additionally when
entityType === "cards" and renders a six-tile grid + top-5 synergy list
below the prose summary. Stat tile component lives in the same file
since it's not used elsewhere.

prettyId helper title-cases UPPER_SNAKE ids cheaply (no name-lookup
round-trip) — fine since synergy cards are clickable to their detail
pages where the canonical name lives.

contributing/API_REFERENCE.md gets a new row documenting the endpoint
and the field set.
@ptrlrd ptrlrd force-pushed the feat/card-stats-expanded branch from 624c9e1 to 2507327 Compare May 18, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant