From 34e8fb8a504f29621046b728c8af433d0adc52ee Mon Sep 17 00:00:00 2001
From: TO
Date: Fri, 20 Nov 2026 21:07:52 +0100
Subject: [PATCH] Expose the Season Challenge figures of each champion card
(#72)
Add ChampionChallenge (Matches, Wins, best Placement, date of the first
top 1) and Marks (Played, Won, Completed) on ChampionRow::challenge. They
cover one Account and one Season across all Formats, so the Format filter
never changes them. Computed in the existing chronological pass.
The first top 1 date (#73) comes from the first top 1 by start time, with
the same day convention as the progress curve, so a later or out-of-order
import never changes it.
Co-Authored-By: Claude Opus 5.5
---
crates/app/src/champion_table.rs | 1 +
crates/core/src/lib.rs | 4 +-
crates/core/src/statistics.rs | 68 +++++++-
crates/core/tests/statistics.rs | 274 ++++++++++++++++++++++++++++++-
4 files changed, 337 insertions(+), 10 deletions(-)
diff --git a/crates/app/src/champion_table.rs b/crates/app/src/champion_table.rs
index 1448f66..75b5a9b 100644
--- a/crates/app/src/champion_table.rs
+++ b/crates/app/src/champion_table.rs
@@ -318,6 +318,7 @@ pub(crate) mod tests {
last_match_ms: None,
attempts: None,
state: None,
+ challenge: None,
}
}
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
index bbc3fce..effa473 100644
--- a/crates/core/src/lib.rs
+++ b/crates/core/src/lib.rs
@@ -30,8 +30,8 @@ pub use model::{Account, Format, Match, SyncProgress, SyncReport};
pub use riot::RiotApi;
pub use seasons::{Season, default_seasons, load_seasons};
pub use statistics::{
- ChallengeSummary, ChampionRow, ChampionState, Charts, Column, Scope, SeasonScope, StateFilter,
- Statistics, sort_rows,
+ ChallengeSummary, ChampionChallenge, ChampionRow, ChampionState, Charts, Column, Marks, Scope,
+ SeasonScope, StateFilter, Statistics, sort_rows,
};
pub use tracker::{MatchHistorySource, Tracker};
pub use update_package::{download_update, restart_to_update, update_at_launch, verify_release};
diff --git a/crates/core/src/statistics.rs b/crates/core/src/statistics.rs
index fdd2420..38f6226 100644
--- a/crates/core/src/statistics.rs
+++ b/crates/core/src/statistics.rs
@@ -71,6 +71,46 @@ pub struct ChampionRow {
/// Season scope: always `Some`, not affected by the Format filter. All Seasons:
/// `Some(NeverPlayed)` for a champion with no stored Match, otherwise `None`.
pub state: Option,
+ /// Season scope: always `Some`, zeros for a champion never played. All Seasons: `None`.
+ /// Not affected by the Format filter.
+ pub challenge: Option,
+}
+
+/// What the champion card shows: the Challenge figures of one champion for one Account and
+/// one Season, all Formats together. The statistics' Format filter never changes them.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub struct ChampionChallenge {
+ /// Matches in the Season, all Formats.
+ pub matches: usize,
+ /// Wins in the Season, all Formats.
+ pub wins: usize,
+ /// Best Placement in the Season, all Formats.
+ pub best_placement: Option,
+ /// The day of the first top 1 of the Season, by start time. Same day as the matching point
+ /// of `Charts::completed_over_time`. A later top 1 never changes it.
+ pub completed_on: Option,
+}
+
+/// The three Marks of the Challenge on a champion.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct Marks {
+ /// At least one Match.
+ pub played: bool,
+ /// At least one Win. A top 1 is always a Win.
+ pub won: bool,
+ /// At least one top 1: the champion is Completed.
+ pub completed: bool,
+}
+
+impl ChampionChallenge {
+ pub fn marks(&self) -> Marks {
+ let completed = self.completed_on.is_some();
+ Marks {
+ played: self.matches > 0,
+ won: self.wins > 0 || completed,
+ completed,
+ }
+ }
}
#[derive(Clone, Debug, PartialEq)]
@@ -187,14 +227,21 @@ pub(crate) fn collate(name: &str) -> String {
struct Progress {
attempts: usize,
completed_at_ms: Option,
+ /// Over every Match given, not only up to the first top 1.
+ matches: usize,
+ wins: usize,
+ best_placement: Option,
}
-/// Attempts per champion from Matches in chronological order: a champion's Matches count
-/// up to and including its first top 1.
+/// Progress per champion from Matches in chronological order: a champion's Attempts count
+/// its Matches up to and including its first top 1; the other figures count them all.
fn progress_by_champion(matches: &[&Match]) -> HashMap {
let mut progress: HashMap = HashMap::new();
for m in matches {
let p = progress.entry(m.champion_id).or_default();
+ p.matches += 1;
+ p.wins += usize::from(m.win);
+ p.best_placement = Some(p.best_placement.map_or(m.placement, |b| b.min(m.placement)));
if p.completed_at_ms.is_none() {
p.attempts += 1;
if m.placement == 1 {
@@ -247,7 +294,7 @@ pub(crate) fn compute(
.into_iter()
.map(|champion| {
let mine = by_champion.get(&champion.id).map_or(&[][..], Vec::as_slice);
- let (attempts, state) = match &progress {
+ let (attempts, state, challenge) = match &progress {
Some(progress) => {
let p = progress.get(&champion.id);
let state = match p {
@@ -258,11 +305,23 @@ pub(crate) fn compute(
Some(_) => ChampionState::InProgress,
None => ChampionState::NeverPlayed,
};
- (Some(p.map_or(0, |p| p.attempts)), Some(state))
+ let challenge =
+ p.map_or_else(ChampionChallenge::default, |p| ChampionChallenge {
+ matches: p.matches,
+ wins: p.wins,
+ best_placement: p.best_placement,
+ completed_on: p.completed_at_ms.map(Date::from_ms),
+ });
+ (
+ Some(p.map_or(0, |p| p.attempts)),
+ Some(state),
+ Some(challenge),
+ )
}
None => (
None,
(!ever_played.contains(&champion.id)).then_some(ChampionState::NeverPlayed),
+ None,
),
};
ChampionRow {
@@ -277,6 +336,7 @@ pub(crate) fn compute(
last_match_ms: mine.iter().map(|m| m.started_at_ms).max(),
attempts,
state,
+ challenge,
champion,
}
})
diff --git a/crates/core/tests/statistics.rs b/crates/core/tests/statistics.rs
index b86caaf..11de00a 100644
--- a/crates/core/tests/statistics.rs
+++ b/crates/core/tests/statistics.rs
@@ -1,13 +1,13 @@
mod common;
use arena_tracker_core::{
- Champion, ChampionRow, ChampionState, Column, Error, Format, Scope, Season, SeasonScope,
- StateFilter, Statistics, Tracker, sort_rows,
+ Account, Champion, ChampionChallenge, ChampionRow, ChampionState, Column, Error, Format, Marks,
+ Scope, Season, SeasonScope, StateFilter, Statistics, Tracker, sort_rows,
};
use common::jan_2026 as jan;
use common::{
- CATALOG, FakeHistory, RIOT_ID, S1, S2, SELF_PUUID, at, date, imported_tracker, payloads,
- played_match, recorded_account, run, seasons,
+ CATALOG, FakeChampions, FakeHistory, RIOT_ID, S1, S2, SELF_PUUID, at, date, imported_tracker,
+ payload, payloads, played_by, played_match, recorded_account, run, seasons,
};
use std::sync::atomic::Ordering;
@@ -430,6 +430,7 @@ fn bare_row(name: &str, id: u32) -> ChampionRow {
last_match_ms: None,
attempts: None,
state: None,
+ challenge: None,
}
}
@@ -593,3 +594,268 @@ fn attempts_follow_start_times_not_the_order_matches_were_stored_in() {
);
assert_eq!(stats.challenge.unwrap().average_attempts, Some(3.0));
}
+
+const NO_MARKS: Marks = Marks {
+ played: false,
+ won: false,
+ completed: false,
+};
+
+fn challenge(stats: &Statistics, champion_id: u32) -> ChampionChallenge {
+ row(stats, champion_id).challenge.unwrap()
+}
+
+#[test]
+fn a_2nd_place_is_a_win_that_leaves_the_champion_remaining() {
+ let dir = tempfile::tempdir().unwrap();
+ let tracker = imported_tracker(dir.path(), &[played_match(11, 2, jan(2, 0))]);
+
+ let stats = stats(&tracker, S1, None);
+
+ let yi = row(&stats, 11);
+ assert_eq!(yi.state, Some(ChampionState::InProgress));
+ let challenge = yi.challenge.unwrap();
+ assert_eq!(
+ (challenge.matches, challenge.wins, challenge.best_placement),
+ (1, 1, Some(2))
+ );
+ assert_eq!(challenge.completed_on, None);
+ assert_eq!(
+ challenge.marks(),
+ Marks {
+ played: true,
+ won: true,
+ completed: false
+ }
+ );
+}
+
+#[test]
+fn a_single_top_1_earns_the_three_marks() {
+ let dir = tempfile::tempdir().unwrap();
+ let tracker = imported_tracker(dir.path(), &[played_match(11, 1, jan(2, 5))]);
+
+ let stats = stats(&tracker, S1, None);
+
+ let yi = row(&stats, 11);
+ assert_eq!(yi.state, Some(ChampionState::Completed));
+ assert_eq!(yi.attempts, Some(1));
+ let challenge = yi.challenge.unwrap();
+ assert_eq!(challenge.completed_on, Some(date(2026, 1, 2)));
+ assert_eq!(
+ challenge.marks(),
+ Marks {
+ played: true,
+ won: true,
+ completed: true
+ }
+ );
+}
+
+#[test]
+fn a_played_champion_without_a_win_has_only_the_first_mark() {
+ let dir = tempfile::tempdir().unwrap();
+ let tracker = imported_tracker(dir.path(), &run(11, &[5, 4], jan(2, 0)));
+
+ let stats = stats(&tracker, S1, None);
+
+ let challenge = challenge(&stats, 11);
+ assert_eq!((challenge.matches, challenge.wins), (2, 0));
+ assert_eq!(challenge.best_placement, Some(4));
+ assert_eq!(
+ challenge.marks(),
+ Marks {
+ played: true,
+ won: false,
+ completed: false
+ }
+ );
+}
+
+#[test]
+fn a_never_played_champion_has_a_zeroed_challenge_and_no_marks() {
+ let dir = tempfile::tempdir().unwrap();
+ let tracker = imported_tracker(dir.path(), &run(11, &[1], jan(2, 0)));
+
+ let stats = stats(&tracker, S1, None);
+
+ let unplayed = challenge(&stats, 8);
+ assert_eq!(
+ unplayed,
+ ChampionChallenge {
+ matches: 0,
+ wins: 0,
+ best_placement: None,
+ completed_on: None
+ }
+ );
+ assert_eq!(unplayed.marks(), NO_MARKS);
+}
+
+#[test]
+fn the_all_seasons_view_has_no_champion_challenge() {
+ let dir = tempfile::tempdir().unwrap();
+ let tracker = imported_tracker(dir.path(), &run(11, &[1], jan(2, 0)));
+
+ let stats = all_seasons(&tracker);
+
+ assert!(stats.rows.iter().all(|r| r.challenge.is_none()));
+}
+
+#[test]
+fn the_format_filter_changes_the_columns_but_not_the_champion_challenge() {
+ let dir = tempfile::tempdir().unwrap();
+ let matches = vec![
+ played_match(11, 4, jan(2, 1)),
+ played_match(11, 1, jan(2, 2)).in_format(1740),
+ played_match(11, 2, jan(2, 3)),
+ played_match(222, 3, jan(2, 4)).in_format(1740),
+ ];
+ let tracker = imported_tracker(dir.path(), &matches);
+
+ let everything = stats(&tracker, S1, None);
+ let only_3x6 = stats(&tracker, S1, Some(Format::from_queue(1750).unwrap()));
+
+ let challenges =
+ |stats: &Statistics| -> Vec<_> { stats.rows.iter().map(|r| r.challenge).collect() };
+ assert_eq!(challenges(&everything), challenges(&only_3x6));
+ let yi = challenge(&only_3x6, 11);
+ assert_eq!((yi.matches, yi.wins, yi.best_placement), (3, 2, Some(1)));
+ assert_eq!(yi.completed_on, Some(date(2026, 1, 2)));
+ assert_eq!(challenge(&only_3x6, 222).matches, 1);
+ // The Format-scoped columns do change.
+ assert_eq!(row(&everything, 11).matches, 3);
+ assert_eq!(row(&only_3x6, 11).matches, 2);
+ assert_eq!(row(&only_3x6, 11).best_placement, Some(2));
+ assert_eq!(row(&only_3x6, 222).matches, 0);
+}
+
+#[test]
+fn the_champion_challenge_follows_the_season() {
+ let dir = tempfile::tempdir().unwrap();
+ let matches = [
+ run(11, &[1, 2], jan(2, 0)),
+ run(11, &[6], at(date(2026, 4, 2), 0)),
+ ]
+ .concat();
+ let tracker = imported_tracker(dir.path(), &matches);
+
+ let past = challenge(&stats(&tracker, S1, None), 11);
+ let current = challenge(&stats(&tracker, S2, None), 11);
+
+ assert_eq!((past.matches, past.wins), (2, 2));
+ assert_eq!(past.completed_on, Some(date(2026, 1, 2)));
+ assert_eq!(
+ current,
+ ChampionChallenge {
+ matches: 1,
+ wins: 0,
+ best_placement: Some(6),
+ completed_on: None
+ }
+ );
+ assert!(!current.marks().won);
+}
+
+#[test]
+fn the_champion_challenge_follows_the_account() {
+ const OTHER_PUUID: &str = "fixture-puuid-other";
+ let dir = tempfile::tempdir().unwrap();
+ let other = Account {
+ puuid: OTHER_PUUID.into(),
+ game_name: "Autre".into(),
+ tag_line: "FIX".into(),
+ };
+ let theirs = played_by(
+ &payload("EUW1_theirs", 1750, 11, "MasterYi", 1, true, jan(3, 0)),
+ OTHER_PUUID,
+ );
+ let history = FakeHistory::new(
+ recorded_account(),
+ payloads(&[played_match(11, 4, jan(2, 0))]),
+ )
+ .with_account(other, vec![theirs]);
+ let tracker = Tracker::open(&dir.path().join("arena.db"), Box::new(history))
+ .unwrap()
+ .with_seasons(seasons())
+ .with_champions(
+ Box::new(FakeChampions::new("1.0", &CATALOG)),
+ dir.path().join("portraits"),
+ );
+ tracker.refresh_champions().unwrap();
+ tracker.sync(RIOT_ID, &mut |_| {}).unwrap();
+ tracker.sync("Autre#FIX", &mut |_| {}).unwrap();
+ let scope = Scope {
+ season: SeasonScope::Season(S1.into()),
+ format: None,
+ };
+
+ let mine = tracker.statistics(SELF_PUUID, &scope).unwrap();
+ let theirs = tracker.statistics(OTHER_PUUID, &scope).unwrap();
+
+ let mine = challenge(&mine, 11);
+ assert_eq!((mine.matches, mine.wins, mine.completed_on), (1, 0, None));
+ let theirs = challenge(&theirs, 11);
+ assert_eq!(theirs.matches, 1);
+ assert_eq!(theirs.completed_on, Some(date(2026, 1, 3)));
+}
+
+#[test]
+fn two_top_1_imported_out_of_order_keep_the_earlier_day_and_one_completion() {
+ let dir = tempfile::tempdir().unwrap();
+ // Riot hands the newest Match over first: the later top 1 is stored before everything else.
+ let matches = [
+ played_match(11, 1, jan(9, 0)),
+ played_match(11, 1, jan(5, 22)),
+ played_match(11, 3, jan(4, 0)),
+ ];
+ let tracker = Tracker::open(
+ &dir.path().join("arena.db"),
+ Box::new(FakeHistory::new(recorded_account(), payloads(&matches)).delivered_as_given()),
+ )
+ .unwrap()
+ .with_seasons(seasons());
+ tracker.sync(RIOT_ID, &mut |_| {}).unwrap();
+
+ let stats = stats(&tracker, S1, None);
+
+ let yi = row(&stats, 11);
+ assert_eq!(yi.state, Some(ChampionState::Completed));
+ assert_eq!(yi.attempts, Some(2)); // the Win, then the first top 1
+ let challenge = yi.challenge.unwrap();
+ assert_eq!(challenge.completed_on, Some(date(2026, 1, 5)));
+ assert_eq!((challenge.matches, challenge.wins), (3, 3));
+ let summary = stats.challenge.unwrap();
+ assert_eq!((summary.completed, summary.attempts), (1, 2));
+ assert_eq!(stats.charts.completed_over_time, [(date(2026, 1, 5), 1)]);
+}
+
+#[test]
+fn the_first_top_1_day_matches_the_progress_curve() {
+ let dir = tempfile::tempdir().unwrap();
+ // The first top 1 of Maitre Yi is late in the evening: the day convention must agree.
+ let matches = [
+ run(1, &[1], jan(2, 1)),
+ run(11, &[4, 1, 1], jan(5, 23)),
+ run(222, &[1], jan(7, 0)),
+ ]
+ .concat();
+ let tracker = imported_tracker(dir.path(), &matches);
+
+ let stats = stats(&tracker, S1, None);
+
+ let mut days: Vec<_> = stats
+ .rows
+ .iter()
+ .filter_map(|r| r.challenge?.completed_on)
+ .collect();
+ days.sort();
+ let curve: Vec<_> = stats
+ .charts
+ .completed_over_time
+ .iter()
+ .map(|(d, _)| *d)
+ .collect();
+ assert_eq!(days, curve);
+ assert_eq!(challenge(&stats, 11).completed_on, Some(date(2026, 1, 6)));
+}