Files
arena-tracker/crates/core/tests/common/scenarios.rs
T

126 lines
3.4 KiB
Rust

use super::*;
// Statistics scenarios: a small catalog, two Seasons and Matches described by champion and Placement.
pub const RIOT_ID: &str = "Joueur#EUW";
pub const HOUR_MS: i64 = 3_600_000;
pub const S1: &str = "Saison A";
pub const S2: &str = "Saison B";
/// The name of the progression track recorded from the real client for the Season 2 2026.
pub const S2_TRACK: &str = "2026 Season 2 Champs Completed Track";
/// (id, key, French name)
pub const CATALOG: [(u32, &str, &str); 6] = [
(1, "Annie", "Annie"),
(8, "Vladimir", "Vladimir"),
(11, "MasterYi", "Maître Yi"),
(19, "Warwick", "Warwick"),
(103, "Ahri", "Ahri"),
(222, "Jinx", "Jinx"),
];
pub fn date(year: i32, month: u8, day: u8) -> Date {
Date { year, month, day }
}
/// `hours` after 00:00 UTC of `date`.
pub fn at(date: Date, hours: i64) -> i64 {
date.start_ms() + hours * HOUR_MS
}
/// `hours` after 00:00 UTC on a day of January 2026 (inside S1).
pub fn jan_2026(day: u8, hours: i64) -> i64 {
at(date(2026, 1, day), hours)
}
/// S1 starts on 2026-01-01 and S2 on 2026-04-01; only S2 has an official track.
pub fn seasons() -> Vec<Season> {
vec![
Season {
name: S1.into(),
start: date(2026, 1, 1),
official_track: None,
},
Season {
name: S2.into(),
start: date(2026, 4, 1),
official_track: Some(S2_TRACK.into()),
},
]
}
#[derive(Clone)]
pub struct PlayedMatch {
pub champion: u32,
pub placement: u8,
pub queue_id: u32,
pub started_at_ms: i64,
}
/// An Arena 3x6 Match.
pub fn played_match(champion: u32, placement: u8, started_at_ms: i64) -> PlayedMatch {
PlayedMatch {
champion,
placement,
queue_id: 1750,
started_at_ms,
}
}
impl PlayedMatch {
pub fn in_format(mut self, queue_id: u32) -> PlayedMatch {
self.queue_id = queue_id;
self
}
}
/// One Match per Placement, an hour apart from `from_ms`.
pub fn run(champion: u32, placements: &[u8], from_ms: i64) -> Vec<PlayedMatch> {
(0..)
.zip(placements)
.map(|(i, &p)| played_match(champion, p, from_ms + i * HOUR_MS))
.collect()
}
/// The payloads of the Matches, as the Riot API would serve them (win = top 3).
pub fn payloads(matches: &[PlayedMatch]) -> Vec<String> {
(0..)
.zip(matches)
.map(|(i, m)| {
let key = CATALOG
.iter()
.find(|(id, _, _)| *id == m.champion)
.map_or("Unknown", |(_, key, _)| key);
payload(
&format!("EUW1_{i}"),
m.queue_id,
m.champion,
key,
m.placement,
m.placement <= 3,
m.started_at_ms,
)
})
.collect()
}
pub fn open_tracker(dir: &Path, matches: &[PlayedMatch]) -> Tracker {
Tracker::open(
&dir.join("arena.db"),
Box::new(FakeHistory::new(recorded_account(), payloads(matches))),
)
.unwrap()
.with_seasons(seasons())
}
/// A tracker with the six-champion catalog cached and the Matches imported.
pub fn imported_tracker(dir: &Path, matches: &[PlayedMatch]) -> Tracker {
let tracker = open_tracker(dir, matches).with_champions(
Box::new(FakeChampions::new("1.0", &CATALOG)),
dir.join("portraits"),
);
tracker.refresh_champions().unwrap();
tracker.sync(RIOT_ID, &mut |_| {}).unwrap();
tracker
}