Skip to content

Commit

Permalink
Finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldoylecs committed Oct 6, 2019
1 parent 0511ba5 commit c5e185e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

15 changes: 5 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern crate serde_derive;

use boxcars::{ParseError, Replay, HeaderProp};

use std::env;
use std::error;
use std::fs;
use std::io::{stdin, Read, Error, ErrorKind};
Expand Down Expand Up @@ -146,20 +145,15 @@ fn get_player_stats_property(replay: &Replay) -> Result<HeaderProp, String> {
}

fn get_winning_team(replay: &Replay) -> Result<i32, String> {
let mut team_0_score: i32 = -1;
let mut team_1_score: i32 = -1;
let mut team_0_score: i32 = 0;
let mut team_1_score: i32 = 0;
for prop in &replay.properties {
match prop.0.as_ref() {
"Team0Score" => if let HeaderProp::Int(v) = prop.1 { team_0_score = v },
"Team1Score" => if let HeaderProp::Int(v) = prop.1 { team_1_score = v },
_ => (),
}
}

if team_0_score == -1 || team_1_score == -1 {
return Err("Team score failed to be found".to_string());
}

return if team_0_score < team_1_score { Ok(1) } else { Ok(0) }
}

Expand Down Expand Up @@ -205,8 +199,6 @@ fn write_csv(stats: Vec<PlayerStats>, output: PathBuf) -> Result<(), Box<dyn err
}

fn run() -> Result<(), Box<dyn error::Error>> {
let args: Vec<String> = env::args().collect();
println!("{:?}", args);
let input_path: PathBuf = read_path_input("What is the path to the replay file directory")?;
let mut output_path: PathBuf = read_path_input("What is the path to the output directory")?;

Expand All @@ -224,6 +216,9 @@ fn run() -> Result<(), Box<dyn error::Error>> {
for stat in stats.iter() {
all_stats.push(stat.clone());
}
for _ in 0..(6 - stats.len()) {
all_stats.push(PlayerStats::default());
}
println!(
"Done reading {}",
file_path.file_name()
Expand Down

0 comments on commit c5e185e

Please sign in to comment.