Expose the order of the completions and the Season's last Match (#84)

The Challenge's chronological pass that counts the Attempts now also
records the Completed champions in the order of their first top 1, and
what the Season's latest Match, all Formats, did to its champion: an
Attempt, the completing Match, or one played after completion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WYQB8paBcLk67XoAUYARBK
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-21 15:33:57 +01:00
1 parent cee9ff2989
commit e28aefc3bc
3 files changed
+152 -17

No files matched your search

+2 -2
View File
@@ -32,8 +32,8 @@ pub use riot::RiotApi;
pub use seasons::{Season, default_seasons, load_seasons};
pub use splash::{BannerFrame, Splash, SplashFocus};
pub use statistics::{
ChallengeSummary, ChampionChallenge, ChampionRow, ChampionState, Charts, Column, Marks, Scope,
SeasonScope, StateFilter, Statistics, sort_rows,
ChallengeSummary, ChampionChallenge, ChampionRow, ChampionState, Charts, Column, LastMatch,
Marks, MatchOutcome, 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};
+56 -11
View File
@@ -47,6 +47,29 @@ pub struct ChallengeSummary {
/// Over Completed champions only.
pub average_attempts: Option<f64>,
pub first_tries: usize,
/// The Completed champions' ids in the order of their first top 1, the earliest first.
pub completion_order: Vec<u32>,
/// The Season's latest Match, all Formats; `None` without any Match in the Season.
pub last_match: Option<LastMatch>,
}
/// A Match as the Challenge saw it.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct LastMatch {
pub champion_id: u32,
pub placement: u8,
pub outcome: MatchOutcome,
}
/// What a Match did to its champion's Challenge.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MatchOutcome {
/// The champion's Attempt of that number (1 for the first), which did not complete it.
Attempt(usize),
/// The champion's first top 1, after that many Attempts (1 for a First Try).
Completed(usize),
/// Played once the champion was already Completed: not an Attempt.
AfterCompletion,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -242,23 +265,42 @@ struct Progress {
best_placement: Option<u8>,
}
/// What one chronological pass over the Season's Matches gives the Challenge.
#[derive(Default)]
struct ChallengePass {
progress: HashMap<u32, Progress>,
completion_order: Vec<u32>,
last_match: Option<LastMatch>,
}
/// 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<u32, Progress> {
let mut progress: HashMap<u32, Progress> = HashMap::new();
fn challenge_pass(matches: &[&Match]) -> ChallengePass {
let mut pass = ChallengePass::default();
for m in matches {
let p = progress.entry(m.champion_id).or_default();
let p = pass.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() {
let outcome = if p.completed_at_ms.is_some() {
MatchOutcome::AfterCompletion
} else {
p.attempts += 1;
if m.placement == 1 {
p.completed_at_ms = Some(m.started_at_ms);
pass.completion_order.push(m.champion_id);
MatchOutcome::Completed(p.attempts)
} else {
MatchOutcome::Attempt(p.attempts)
}
}
};
pass.last_match = Some(LastMatch {
champion_id: m.champion_id,
placement: m.placement,
outcome,
});
}
progress
pass
}
/// `matches` are all the Account's stored Matches, oldest first. `period` is the Season's
@@ -296,16 +338,16 @@ pub(crate) fn compute(
for m in &in_scope {
by_champion.entry(m.champion_id).or_default().push(m);
}
let progress = period.is_some().then(|| progress_by_champion(&in_period));
let mut pass = period.is_some().then(|| challenge_pass(&in_period));
let ever_played: HashSet<u32> = matches.iter().map(|m| m.champion_id).collect();
let rows: Vec<ChampionRow> = champions
.into_iter()
.map(|champion| {
let mine = by_champion.get(&champion.id).map_or(&[][..], Vec::as_slice);
let (attempts, state, challenge) = match &progress {
Some(progress) => {
let p = progress.get(&champion.id);
let (attempts, state, challenge) = match &pass {
Some(pass) => {
let p = pass.progress.get(&champion.id);
let state = match p {
Some(Progress {
completed_at_ms: Some(_),
@@ -362,7 +404,8 @@ pub(crate) fn compute(
let mut challenge = None;
let mut completed_over_time = Vec::new();
let mut attempts_to_complete = [0; 5];
if let Some(progress) = &progress {
if let Some(pass) = &mut pass {
let progress = &pass.progress;
let completed: Vec<(usize, i64)> = progress
.values()
.filter_map(|p| Some((p.attempts, p.completed_at_ms?)))
@@ -375,6 +418,8 @@ pub(crate) fn compute(
completed.iter().map(|(n, _)| n).sum::<usize>() as f64 / completed.len() as f64
}),
first_tries: completed.iter().filter(|(n, _)| *n == 1).count(),
completion_order: std::mem::take(&mut pass.completion_order),
last_match: pass.last_match,
});
let mut per_day: BTreeMap<Date, usize> = BTreeMap::new();
for &(attempts, ms) in &completed {