Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions crates/openlogs-analysis/src/run_result.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! The result of a Mythic+ run decided with the game's dungeon data. Without that data the
//! index's result stands.

use std::collections::HashSet;
//! The result of a run. A Mythic+ run's is decided with the game's dungeon data; without
//! that data, and for a dungeon visit, the index's result stands.

use openlogs_gamedata::{DungeonTable, KeyTimer};
use openlogs_index::{FightSummary, Outcome};
Expand All @@ -21,9 +19,11 @@ pub struct RunResult {
pub bosses: Option<BossProgress>,
/// Only for a run completed by the boss list with a logged time.
pub timer: Option<KeyTimer>,
/// Bosses with a killed boss pull in the run, each counted once.
pub killed_bosses: u32,
}

/// The result of `run` (an entry with `challenge`) among the index's `fights`.
/// The result of `run` (a run entry) among the index's `fights`.
///
/// With a boss list for the key: completed exactly when every boss of the dungeon has a
/// killed boss pull in the run and the logged time is not 0; otherwise not completed with
Expand All @@ -35,12 +35,14 @@ pub fn run_result(
fights: &[FightSummary],
dungeons: Option<&DungeonTable>,
) -> RunResult {
let kills = run.killed_encounters(fights);
let index_result = RunResult {
outcome: run.outcome,
bosses: None,
timer: None,
killed_bosses: kills.len() as u32,
};
let Some(challenge) = &run.challenge else {
let Some(challenge) = run.keystone() else {
return index_result;
};
let Some(dungeon) = dungeons.and_then(|table| table.dungeon(challenge.challenge_mode_id))
Expand All @@ -50,11 +52,6 @@ pub fn run_result(
let Some(bosses) = &dungeon.bosses else {
return index_result;
};
let kills: HashSet<u32> = fights
.iter()
.filter(|fight| fight.run_index == Some(run.index) && fight.outcome == Outcome::Kill)
.map(|fight| fight.encounter_id)
.collect();
let killed = bosses
.iter()
.filter(|boss| kills.contains(&boss.encounter_id))
Expand All @@ -75,5 +72,6 @@ pub fn run_result(
outcome,
bosses: Some(BossProgress { killed, total }),
timer,
..index_result
}
}
30 changes: 30 additions & 0 deletions crates/openlogs-analysis/tests/run_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn a_key_ended_after_a_mid_dungeon_kill_is_not_completed() {
outcome: Outcome::Wipe,
bosses: bosses(2),
timer: None,
killed_bosses: 2,
}
);
}
Expand All @@ -98,6 +99,7 @@ fn a_key_with_every_boss_killed_is_completed_with_its_timer() {
outcome: Outcome::Kill,
bosses: bosses(3),
timer: Some(timer),
killed_bosses: 3,
},
"{total_ms} ms"
);
Expand All @@ -116,6 +118,7 @@ fn a_logged_time_of_zero_is_not_completed_even_with_every_boss_killed() {
outcome: Outcome::Wipe,
bosses: bosses(3),
timer: None,
killed_bosses: 3,
}
);
}
Expand All @@ -127,6 +130,7 @@ fn without_a_boss_list_the_index_result_stays() {
outcome: Outcome::Kill,
bosses: None,
timer: None,
killed_bosses: 2,
};
let index = log_with(|_| {});
assert_eq!(result(&index, None), unchanged, "no dungeon data");
Expand All @@ -139,3 +143,29 @@ fn without_a_boss_list_the_index_result_stays() {
assert_eq!(result(&index, Some(&table)), unchanged, "key {key}");
}
}

#[test]
fn a_run_counts_each_killed_boss_once() {
let log = [
"11/17/2026 20:00:00.0000 ZONE_CHANGE,230,\"Blackrock Depths\",1",
"11/17/2026 20:00:10.0000 ENCOUNTER_START,227,\"High Interrogator Gerstahn\",1,5,230",
"11/17/2026 20:00:20.0000 ENCOUNTER_END,227,\"High Interrogator Gerstahn\",1,5,1,10000",
"11/17/2026 20:01:10.0000 ENCOUNTER_START,227,\"High Interrogator Gerstahn\",1,5,230",
"11/17/2026 20:01:20.0000 ENCOUNTER_END,227,\"High Interrogator Gerstahn\",1,5,1,10000",
"11/17/2026 20:02:10.0000 ENCOUNTER_START,228,\"Lord Roccor\",1,5,230",
"11/17/2026 20:02:20.0000 ENCOUNTER_END,228,\"Lord Roccor\",1,5,0,10000",
"11/17/2026 20:03:00.0000 ZONE_CHANGE,0,\"Searing Gorge\",0",
]
.map(|line| format!("{line}\n"))
.concat();
let index = index_bytes(log.as_bytes());
assert_eq!(
result(&index, Some(&table())),
RunResult {
outcome: Outcome::Ended,
bosses: None,
timer: None,
killed_bosses: 1,
}
);
}
74 changes: 58 additions & 16 deletions crates/openlogs-cli/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use std::fmt::Write;
use std::path::Path;
use std::time::Duration;

use openlogs_index::{
CacheStatus, ChallengeMode, FightSummary, GameFlavor, LogIndex, Outcome, difficulty_label,
};
use openlogs_index::{CacheStatus, FightSummary, GameFlavor, LogIndex, Outcome, difficulty_label};

/// Human-readable fight table for `openlogs-cli dump-fights`.
pub fn report(
Expand Down Expand Up @@ -67,11 +65,12 @@ pub fn report(
let runs: Vec<String> = index
.fights
.iter()
.filter_map(|fight| Some(run_line(fight, fight.challenge.as_ref()?, &index.fights)))
.filter(|fight| fight.is_run())
.map(|run| run_line(run, &index.fights))
.collect();
if !runs.is_empty() {
let _ = writeln!(out);
let _ = writeln!(out, "Mythic+ runs");
let _ = writeln!(out, "Runs");
for line in runs {
let _ = writeln!(out, "{line}");
}
Expand All @@ -80,23 +79,22 @@ pub fn report(
}

fn fight_row(fight: &FightSummary) -> String {
let (difficulty, result) = match &fight.challenge {
let (difficulty, result) = match fight.keystone() {
Some(challenge) => (
format!("+{}", challenge.keystone_level),
run_result(fight.outcome),
),
None if fight.is_combat() => ("Combat".to_string(), pull_result(fight.outcome)),
None => (
difficulty_label(fight.difficulty)
.map_or_else(|| fight.difficulty.to_string(), str::to_string),
difficulty_name(fight.difficulty),
pull_result(fight.outcome),
),
};
let enemies = match &fight.combat {
Some(combat) if combat.enemy_count > 1 => format!(" +{}", combat.enemy_count - 1),
_ => String::new(),
};
// Pulls of a Mythic+ run sit indented under their run.
// Pulls of a run sit indented under their run.
let name = match fight.run_index {
Some(_) => format!(" {}{enemies}", fight.name),
None => format!("{}{enemies}", fight.name),
Expand Down Expand Up @@ -126,7 +124,11 @@ fn pull_result(outcome: Outcome) -> &'static str {
}
}

/// A run's result as the index reads it from the log (see `FightSummary::outcome`).
fn difficulty_name(difficulty: u32) -> String {
difficulty_label(difficulty).map_or_else(|| difficulty.to_string(), str::to_string)
}

/// A key's result as the index reads it from the log (see `FightSummary::outcome`).
fn run_result(outcome: Outcome) -> &'static str {
match outcome {
Outcome::Kill => "Completed",
Expand All @@ -136,26 +138,38 @@ fn run_result(outcome: Outcome) -> &'static str {
}

/// E.g. ` #1 Priory of the Sacred Flame +12: Completed in 10:00.0 (logged 10:00.0),
/// affixes 10, 147, 9, boss pulls 2, 3, 4`.
fn run_line(run: &FightSummary, challenge: &ChallengeMode, fights: &[FightSummary]) -> String {
/// affixes 10, 147, 9, boss pulls 2, 3, 4`, or ` #1 Blackrock Depths Normal: Ended in
/// 70:00.0, bosses killed 3, boss pulls 3, 5, 7`.
fn run_line(run: &FightSummary, fights: &[FightSummary]) -> String {
let list = |items: Vec<String>| {
if items.is_empty() {
"none".to_string()
} else {
items.join(", ")
}
};
let logged = challenge
.total_time_ms
.map_or_else(String::new, |ms| format!(" (logged {})", duration(ms)));
let affixes = list(challenge.affix_ids.iter().map(u32::to_string).collect());
let pulls = list(
fights
.iter()
.filter(|fight| fight.run_index == Some(run.index) && !fight.is_combat())
.map(|fight| fight.index.to_string())
.collect(),
);
let Some(challenge) = run.keystone() else {
return format!(
" #{} {} {}: {} in {}, bosses killed {}, boss pulls {pulls}",
run.index,
run.name,
difficulty_name(run.difficulty),
pull_result(run.outcome),
duration(run.duration_ms),
run.killed_encounters(fights).len()
);
};
let logged = challenge
.total_time_ms
.map_or_else(String::new, |ms| format!(" (logged {})", duration(ms)));
let affixes = list(challenge.affix_ids.iter().map(u32::to_string).collect());
format!(
" #{} {} +{}: {} in {}{logged}, affixes {affixes}, boss pulls {pulls}",
run.index,
Expand Down Expand Up @@ -259,6 +273,34 @@ mod tests {
);
}

#[test]
fn report_lists_dungeon_runs_with_their_killed_bosses() {
let log = [
"11/17/2026 20:00:00.0000 ZONE_CHANGE,230,\"Blackrock Depths\",1",
"11/17/2026 20:00:10.0000 ENCOUNTER_START,227,\"High Interrogator Gerstahn\",1,5,230",
"11/17/2026 20:00:20.0000 ENCOUNTER_END,227,\"High Interrogator Gerstahn\",1,5,1,10000",
"11/17/2026 20:01:10.0000 ENCOUNTER_START,228,\"Lord Roccor\",1,5,230",
"11/17/2026 20:01:20.0000 ENCOUNTER_END,228,\"Lord Roccor\",1,5,0,10000",
"11/17/2026 20:02:00.0000 ZONE_CHANGE,0,\"Searing Gorge\",0",
]
.map(|line| format!("{line}\n"))
.concat();
let index = index_bytes(log.as_bytes());
let text = report(
Path::new("Logs/brd.txt"),
8192,
&index,
Duration::from_millis(3),
None,
);
assert!(
text.contains(
"#1 Blackrock Depths Normal: Ended in 1:20.0, bosses killed 1, boss pulls 2, 3"
),
"{text}"
);
}

#[test]
fn report_marks_combat_pulls() {
let index = index_bytes(
Expand Down
2 changes: 1 addition & 1 deletion crates/openlogs-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Cli {

#[derive(Subcommand)]
enum Command {
/// List the fights (boss pulls and Mythic+ runs) in a combat log.
/// List the fights (pulls and runs) in a combat log.
DumpFights {
/// Path to a WoWCombatLog-*.txt file.
file: PathBuf,
Expand Down
Loading
Loading