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 <noreply@anthropic.com>
This commit is contained in:
1 parent
209059cf10
commit
34e8fb8a50
4 files changed
+337
-10
No files matched your search
@@ -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};
|
||||
@@ -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<ChampionState>,
|
||||
/// Season scope: always `Some`, zeros for a champion never played. All Seasons: `None`.
|
||||
/// Not affected by the Format filter.
|
||||
pub challenge: Option<ChampionChallenge>,
|
||||
}
|
||||
|
||||
/// 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<u8>,
|
||||
/// 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<Date>,
|
||||
}
|
||||
|
||||
/// 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<i64>,
|
||||
/// Over every Match given, not only up to the first top 1.
|
||||
matches: usize,
|
||||
wins: usize,
|
||||
best_placement: Option<u8>,
|
||||
}
|
||||
|
||||
/// 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<u32, Progress> {
|
||||
let mut progress: HashMap<u32, Progress> = 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,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user