mirror of
https://codeberg.org/icewind/log-normalizer.git
synced 2026-06-03 13:54:11 +02:00
filter double win events
This commit is contained in:
parent
7386dddfe4
commit
9354eea80e
2 changed files with 3927 additions and 5 deletions
|
|
@ -152,6 +152,7 @@ impl From<RawLog> for NormalizedLog {
|
||||||
};
|
};
|
||||||
|
|
||||||
normalize_stopwatch_events(&mut normalized);
|
normalize_stopwatch_events(&mut normalized);
|
||||||
|
filter_double_wins(&mut normalized);
|
||||||
normalize_event_times(&mut normalized);
|
normalize_event_times(&mut normalized);
|
||||||
normalize_stopwatch_score(&mut normalized);
|
normalize_stopwatch_score(&mut normalized);
|
||||||
|
|
||||||
|
|
@ -240,6 +241,20 @@ fn normalize_stopwatch_events(log: &mut NormalizedLog) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn filter_double_wins(log: &mut NormalizedLog) {
|
||||||
|
for round in log.rounds.iter_mut() {
|
||||||
|
if let Some(index) = round
|
||||||
|
.events
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_index, event)| matches!(event, Event::RoundWin { .. }))
|
||||||
|
.map(|(index, _event)| index)
|
||||||
|
{
|
||||||
|
round.events.truncate(index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_round_end_time(round: &Round) -> u32 {
|
fn get_round_end_time(round: &Round) -> u32 {
|
||||||
round
|
round
|
||||||
.events
|
.events
|
||||||
|
|
@ -338,11 +353,15 @@ mod tests {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use test_case::test_case;
|
use test_case::test_case;
|
||||||
|
|
||||||
|
fn parse(file: &str) -> NormalizedLog {
|
||||||
|
let content = fs::read_to_string(format!("tests/data/{}", file)).unwrap();
|
||||||
|
serde_json::from_str(&content).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[test_case("134389.json", 0, 1)]
|
#[test_case("134389.json", 0, 1)]
|
||||||
#[test_case("550237.json", 1, 0)]
|
#[test_case("550237.json", 1, 0)]
|
||||||
fn test_normalize_stopwatch_score(file: &str, blue: u8, red: u8) {
|
fn test_normalize_stopwatch_score(file: &str, blue: u32, red: u32) {
|
||||||
let content = fs::read_to_string(format!("tests/data/{}", file)).unwrap();
|
let parsed = parse(file);
|
||||||
let parsed: NormalizedLog = serde_json::from_str(&content).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(parsed.teams.blue.score, blue);
|
assert_eq!(parsed.teams.blue.score, blue);
|
||||||
assert_eq!(parsed.teams.red.score, red);
|
assert_eq!(parsed.teams.red.score, red);
|
||||||
|
|
@ -353,8 +372,7 @@ mod tests {
|
||||||
#[test_case("550237.json")]
|
#[test_case("550237.json")]
|
||||||
#[test_case("2522305.json")]
|
#[test_case("2522305.json")]
|
||||||
fn test_normalize_event_time(file: &str) {
|
fn test_normalize_event_time(file: &str) {
|
||||||
let content = fs::read_to_string(format!("tests/data/{}", file)).unwrap();
|
let parsed = parse(file);
|
||||||
let parsed: NormalizedLog = serde_json::from_str(&content).unwrap();
|
|
||||||
|
|
||||||
let mut last_event_time = 0;
|
let mut last_event_time = 0;
|
||||||
|
|
||||||
|
|
@ -363,4 +381,24 @@ mod tests {
|
||||||
last_event_time = event.time();
|
last_event_time = event.time();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case("1.json")]
|
||||||
|
#[test_case("114840.json")]
|
||||||
|
#[test_case("134389.json")]
|
||||||
|
#[test_case("550237.json")]
|
||||||
|
#[test_case("2522305.json")]
|
||||||
|
fn test_round_win(file: &str) {
|
||||||
|
let parsed = parse(file);
|
||||||
|
|
||||||
|
for round in parsed.rounds {
|
||||||
|
assert_eq!(
|
||||||
|
1,
|
||||||
|
round
|
||||||
|
.events
|
||||||
|
.into_iter()
|
||||||
|
.filter(|event| matches!(event, Event::RoundWin { .. }))
|
||||||
|
.count()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3884
tests/data/114840.json
Normal file
3884
tests/data/114840.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue