106 lines
3.2 KiB
Rust
106 lines
3.2 KiB
Rust
mod common;
|
|
|
|
use std::path::Path;
|
|
use std::sync::atomic::Ordering;
|
|
use std::sync::mpsc;
|
|
use std::thread;
|
|
use std::time::Duration;
|
|
|
|
use arena_tracker_core::{
|
|
Account, Error, Format, Match, SourceError, SyncProgress, SyncReport, Tracker,
|
|
};
|
|
use common::{
|
|
FakeHistory, SELF_PUUID, payload, played_by, recorded_account, recorded_matches, with_game_mode,
|
|
};
|
|
use serde_json::Value;
|
|
|
|
const RIOT_ID: &str = "Joueur#EUW";
|
|
|
|
fn open(db: &Path, history: FakeHistory) -> Tracker {
|
|
Tracker::open(db, Box::new(history)).unwrap()
|
|
}
|
|
|
|
fn sync(tracker: &Tracker) -> SyncReport {
|
|
tracker.sync(RIOT_ID, &mut |_| {}).unwrap()
|
|
}
|
|
|
|
/// The expectation for a recorded payload, read from the payload itself.
|
|
fn expected(raw: &str) -> Match {
|
|
let v: Value = serde_json::from_str(raw).unwrap();
|
|
let me = v["info"]["participants"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.find(|p| p["puuid"] == SELF_PUUID)
|
|
.unwrap();
|
|
let format = match v["info"]["queueId"].as_u64().unwrap() {
|
|
1700 => Format::Arena16,
|
|
1740 => Format::BraveryArena,
|
|
1750 => Format::Arena3x6,
|
|
queue => panic!("unexpected queue {queue}"),
|
|
};
|
|
Match {
|
|
match_id: v["metadata"]["matchId"].as_str().unwrap().into(),
|
|
format,
|
|
champion_id: me["championId"].as_u64().unwrap() as u32,
|
|
champion_name: me["championName"].as_str().unwrap().into(),
|
|
placement: me["placement"].as_u64().unwrap() as u8,
|
|
win: me["win"].as_bool().unwrap(),
|
|
started_at_ms: v["info"]["gameStartTimestamp"].as_i64().unwrap(),
|
|
}
|
|
}
|
|
|
|
/// Five Arena 3x6 Matches, one every 1000 s starting at `from_s`.
|
|
fn five_matches(from_s: i64) -> Vec<String> {
|
|
five_matches_every(from_s, 1000)
|
|
}
|
|
|
|
/// Five Arena 3x6 Matches, one every `step_s` seconds starting at `from_s`.
|
|
fn five_matches_every(from_s: i64, step_s: i64) -> Vec<String> {
|
|
(0..5)
|
|
.map(|i| {
|
|
payload(
|
|
&format!("EUW1_{i}"),
|
|
1750,
|
|
10 + i as u32,
|
|
"Champion",
|
|
(i % 8 + 1) as u8,
|
|
i % 2 == 0,
|
|
(from_s + i * step_s) * 1000,
|
|
)
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn started_at(matches: &[Match]) -> Vec<i64> {
|
|
matches.iter().map(|m| m.started_at_ms).collect()
|
|
}
|
|
|
|
fn started_ms(payload: &str) -> i64 {
|
|
let v: Value = serde_json::from_str(payload).unwrap();
|
|
v["info"]["gameStartTimestamp"].as_i64().unwrap()
|
|
}
|
|
|
|
const LEGACY_SCHEMA: &str = "
|
|
CREATE TABLE accounts (
|
|
puuid TEXT PRIMARY KEY, game_name TEXT NOT NULL, tag_line TEXT NOT NULL,
|
|
full_import_done INTEGER NOT NULL DEFAULT 0
|
|
);
|
|
CREATE TABLE matches (
|
|
puuid TEXT NOT NULL, match_id TEXT NOT NULL, queue_id INTEGER NOT NULL,
|
|
champion_id INTEGER NOT NULL, champion_name TEXT NOT NULL, placement INTEGER NOT NULL,
|
|
win INTEGER NOT NULL, started_at_ms INTEGER NOT NULL, raw TEXT NOT NULL,
|
|
PRIMARY KEY (puuid, match_id)
|
|
);
|
|
INSERT INTO accounts VALUES ('fixture-puuid-self', 'Joueur', 'EUW', 1);
|
|
INSERT INTO matches VALUES ('fixture-puuid-self', 'EUW1_1', 1750, 1, 'A', 4, 0, 1000000000, '{}');";
|
|
|
|
#[path = "import/accounts.rs"]
|
|
mod accounts;
|
|
#[path = "import/compatibility.rs"]
|
|
mod compatibility;
|
|
#[path = "import/concurrency.rs"]
|
|
mod concurrency;
|
|
#[path = "import/sync.rs"]
|
|
mod sync;
|