Files
arena-tracker/crates/core/src/model.rs
T
nessarandClaude Opus 5.5 44c2d10b3b
CI / core (pull_request) Successful in 1m40s
Play the strongest Match on its own champion and report every followed game (#89)
From the review of PR #99:
- Of several followed Matches waiting, the strongest plays on its own
  champion (tick, card and splash), the most recent among equals. The
  comet no longer flies to one champion's tick with another's splash.
- A game the client gave no id for, or seen before any Match gave the
  platform, is reported when the sync stores it: the client's id when
  it has one, else the newest Match newer than every one stored. A
  first import without that id stays history.
- What a Match brought comes from the Challenge's own Marks, with and
  without it, instead of a second set of rules in SQL; `fetch_and_store`
  is back to fetching and storing. `MatchEnd::Completed` takes the
  glossary's word, and its variants are documented again.
- Only the count of the banner's title rolls in, from 10 px below, as
  in the prototype; the « Dernière Partie » line still fades in.
- The Windows setting is checked where a Match is queued, and the tests
  now go through the follower round and the statistics; a test checks
  that the end state is what a reload shows.
- The Match's state is one `MatchPlayback`, ended in one place; the
  durations are named; `MarkFill`, `Changing` and `RevealFrame` replace
  bare tuples; a splash that cannot be read ends its reveal.
- `follow_client_with` takes the report itself, without a forwarding
  function. docs/performance.md describes the Match animation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:16:04 +01:00

128 lines
3.7 KiB
Rust

use crate::statistics::Marks;
use serde::Deserialize;
/// One Arena variant, derived from the game queue.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Format {
Arena3x6,
BraveryArena,
Arena16,
Other(u32),
}
impl Format {
/// `None` for queues that are not real Matches (1704 is the PBE test queue).
pub fn from_queue(queue_id: u32) -> Option<Format> {
match queue_id {
1750 => Some(Format::Arena3x6),
1740 => Some(Format::BraveryArena),
1700 | 1710 => Some(Format::Arena16),
1704 => None,
other => Some(Format::Other(other)),
}
}
pub fn name(&self) -> String {
match self {
Format::Arena3x6 => "Arena 3x6".into(),
Format::BraveryArena => "Bravery Arena".into(),
Format::Arena16 => "Arena 16 joueurs".into(),
Format::Other(queue) => format!("Arena (file {queue})"),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Account {
pub puuid: String,
pub game_name: String,
pub tag_line: String,
}
/// A stored Match as the user sees it.
#[derive(Clone, Debug, PartialEq)]
pub struct Match {
pub match_id: String,
pub format: Format,
pub champion_id: u32,
pub champion_name: String,
pub placement: u8,
pub win: bool,
pub started_at_ms: i64,
}
/// What a followed Match brought its champion's Challenge, from the weakest to the strongest:
/// the animation it plays on « Défi » is in proportion.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum MatchEnd {
/// Nothing new: the tick blinks.
Nothing,
/// A new Mark, « Joué » or « Victoire »: the tick steps up.
Mark,
/// The champion's first top 1, it is Completed: the comet.
Completed,
}
impl MatchEnd {
/// The strongest change from the champion's Marks without the Match to those with it.
pub fn between(without: Marks, with: Marks) -> MatchEnd {
if with.completed && !without.completed {
MatchEnd::Completed
} else if with != without {
MatchEnd::Mark
} else {
MatchEnd::Nothing
}
}
}
/// A Match the live follow saw end and stored, with what it brought its champion's Challenge
/// in its Season. A Match stored by a sync of the history is never one.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FollowedMatch {
pub puuid: String,
pub season: String,
pub champion_id: u32,
pub started_at_ms: i64,
pub end: MatchEnd,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SyncProgress {
pub fetched: usize,
pub to_fetch: usize,
}
#[derive(Clone, Debug)]
pub struct SyncReport {
pub account: Account,
/// Matches newly stored by this sync.
pub added: usize,
/// All Matches stored for the Account once the sync is done.
pub stored: usize,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn queues_map_to_formats() {
assert_eq!(Format::from_queue(1750), Some(Format::Arena3x6));
assert_eq!(Format::from_queue(1740), Some(Format::BraveryArena));
assert_eq!(Format::from_queue(1700), Some(Format::Arena16));
assert_eq!(Format::from_queue(1710), Some(Format::Arena16));
assert_eq!(Format::from_queue(1704), None);
assert_eq!(Format::from_queue(1800), Some(Format::Other(1800)));
}
#[test]
fn formats_have_french_facing_names() {
assert_eq!(Format::Arena3x6.name(), "Arena 3x6");
assert_eq!(Format::BraveryArena.name(), "Bravery Arena");
assert_eq!(Format::Arena16.name(), "Arena 16 joueurs");
assert_eq!(Format::Other(1800).name(), "Arena (file 1800)");
}
}