rusty_blitzcrank/analysis/
mod.rs1use std::collections::HashMap;
2
3use crate::types::*;
4
5#[derive(Clone)]
6pub struct ChampStats {
7 pub wins: i64,
8 pub losses: i64,
9 pub kills: i64,
10 pub deaths: i64,
11 pub assists: i64,
12}
13
14impl ChampStats {
15 pub fn empty() -> ChampStats {
16 return ChampStats {
17 wins: 0,
18 losses: 0,
19 kills: 0,
20 deaths: 0,
21 assists: 0,
22 };
23 }
24}
25
26pub fn get_player_stats_for_matches(matches: &Vec<Match>, summoner_name: &str) -> Vec<Participant> {
27 let mut stats: Vec<Participant> = Vec::with_capacity(matches.len());
28
29 for m in matches {
30 for p in &m.info.participants {
31 if p.summoner_name.eq(summoner_name) {
32 stats.push(p.clone());
33 break;
34 }
35 }
36 }
37
38 return stats;
39}
40
41pub fn get_champion_stats(player_stats: &Vec<Participant>) -> HashMap<String, ChampStats> {
42 let mut map = HashMap::new();
43
44 for stat in player_stats {
45 let champ = &stat.champion_name;
46 let mut stats = map.get(champ).unwrap_or(&ChampStats::empty()).clone();
47
48 if stat.win {
49 stats.wins += 1;
50 } else {
51 stats.losses += 1;
52 }
53
54 stats.kills += stat.kills;
55 stats.deaths += stat.deaths;
56 stats.assists += stat.assists;
57
58 map.insert(champ.to_owned(), stats);
59 }
60
61 return map;
62}