Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the map stats #142

Merged
merged 1 commit into from
Aug 3, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.env
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coh3-stats-desktop-app",
"private": true,
"version": "1.5.0",
"version": "1.5.1",
"type": "module",
"repository": {
"url": "https://github.com/cohstats/coh3-stats-desktop-app"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coh3-stats-desktop-app"
version = "1.5.0"
version = "1.5.1"
description = "COH3 Stats Desktop App"
authors = ["coh3stats team"]
license = ""
Expand Down
42 changes: 19 additions & 23 deletions src-tauri/src/parse_log_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ pub fn parse_log_file_reverse(path: String) -> LogFileData {
let right_team = get_team_data(right);

info!(
"Log file parsed: Found {} players",
left_team.players.len() + right_team.players.len()
"Log file parsed: Found {} players. Left team {:?}, right team {:?}.",
left_team.players.len() + right_team.players.len(), left_team.side, right_team.side
);

LogFileData {
Expand Down Expand Up @@ -310,33 +310,29 @@ fn get_ai_count(team: &TeamData) -> usize {
}

fn get_team_data(players: Vec<PlayerData>) -> TeamData {
let mut mixed = false;
let mut last = TeamSide::Mixed;
let mut team_side = TeamSide::Mixed;
let mut is_axis = false;
let mut is_allies = false;

for player in &players {
// For some reason the logs now produce faction as germans instead of german
if player.faction == "germans" || player.faction == "german" || player.faction == "west_german" {
if last == TeamSide::Allies {
mixed = true;
break;
}
last = TeamSide::Axis;
} else {
if last == TeamSide::Axis {
mixed = true;
break;
}
last = TeamSide::Allies;
if player.faction == "germans" || player.faction == "afrika_korps" {
is_axis = true;
} else if player.faction == "americans" || player.faction == "british_africa" {
is_allies = true;
}
}
if mixed {
return TeamData {
players,
side: TeamSide::Mixed,
};

if is_axis && is_allies {
team_side = TeamSide::Mixed;
} else if is_axis {
team_side = TeamSide::Axis;
} else if is_allies {
team_side = TeamSide::Allies;
}

TeamData {
players,
side: last,
side: team_side,
}
}

Expand Down
41 changes: 37 additions & 4 deletions src-tauri/src/parse_log_file/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::parse_log_file::{parse_log_file_reverse, GameState};
use crate::parse_log_file::{parse_log_file_reverse, GameState, TeamSide};


// TODO: Add more assertions and tests for parsing the log files
Expand All @@ -15,9 +15,15 @@ fn test_parse_log_file_reverse_file_1() {
assert_eq!(result.map, "winter_line_8p_mkii");
assert_eq!(result.win_condition, "VictoryPoint");

assert_eq!(result.left.side, TeamSide::Axis);
assert_eq!(result.right.side, TeamSide::Allies);

assert_eq!(result.player_name, "Wolfsindis");
assert_eq!(result.language_code, "en");

// assert some results
// assert_eq!(result.len(), 3);
// print!("{:#?}", result);
// print!("{:#?}", result);
}

#[test]
Expand All @@ -26,7 +32,13 @@ fn test_parse_log_file_reverse_file_2() {
let result = parse_log_file_reverse("./test_assets/warnings-2.log".to_string());
assert_eq!(result.game_state, GameState::Closed);

// TODO: add more assertions
assert_eq!(result.map, "rural_town_2p_mkii");

assert_eq!(result.left.side, TeamSide::Axis);
assert_eq!(result.right.side, TeamSide::Allies);

assert_eq!(result.player_name, "UMirinBrah?");
assert_eq!(result.language_code, "fr");

// print!("{:#?}", result);
}
Expand All @@ -38,8 +50,29 @@ fn test_parse_log_file_reverse_file_3() {
assert_eq!(result.game_state, GameState::Closed);

assert_eq!(result.map, "desert_village_2p_mkiii");
// TODO: add more assertions

assert_eq!(result.left.side, TeamSide::Allies);
assert_eq!(result.right.side, TeamSide::Axis);

assert_eq!(result.player_name, "UMirinBrah?");
assert_eq!(result.language_code, "fr");

// print!("{:#?}", result);
}

#[test]
fn test_team_composition() {
println!("{}", file!());
let result = parse_log_file_reverse("./test_assets/warnings-4v4-allfactions.log".to_string());
assert_eq!(result.game_state, GameState::Closed);

assert_eq!(result.map, "winter_line_8p_mkii");


assert_eq!(result.left.side, TeamSide::Allies);
assert_eq!(result.right.side, TeamSide::Axis);

assert_eq!(result.player_name, "pagep");
assert_eq!(result.language_code, "en");
print!("{:#?}", result);
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "Coh3 Stats Desktop App",
"version": "1.5.0"
"version": "1.5.1"
},
"tauri": {
"allowlist": {
Expand Down
Loading