diff --git a/src/cgg_data_source.rs b/src/cgg_data_source.rs index 48fe98a..6e7623b 100644 --- a/src/cgg_data_source.rs +++ b/src/cgg_data_source.rs @@ -3,7 +3,6 @@ use lazy_static::lazy_static; use log::error; use serde_derive::Deserialize; use serde_json::{json, Value}; -use std::collections::HashMap; use std::sync::Mutex; use crate::data_source::{DataSource, Stat}; @@ -39,6 +38,11 @@ struct Stats { most_common_core_builds: Build, most_common_big_item_builds: Build, most_common_skills: Build, + games: u32, + kills: u32, + deaths: u32, + wins: u32, + assists: u32 } #[derive(Deserialize, Debug)] @@ -48,25 +52,8 @@ struct Build { games: u32, } -#[derive(Deserialize, Debug, Clone)] -struct ChampStat { - champion_id: Option, - stats: Option, - matchups: Option>, - #[serde(rename = "winRate")] - win_rate: Option, - games: Option, - kda: Option, -} - -#[derive(Deserialize, Debug, Clone)] -struct Info { - id: String, -} - lazy_static! { static ref CHAMPIONS_REPORT: Mutex> = Mutex::new(Vec::new()); - static ref CHAMPIONS_STATS: Mutex> = Mutex::new(HashMap::new()); } pub struct CGGDataSource; @@ -120,17 +107,6 @@ impl DataSource for CGGDataSource { serde_json::from_str(&extract_json("window.__PRELOADED_STATE__ = ", page)) .unwrap(); - let champs_stats: HashMap = serde_json::from_str(&extract_json( - "window.__FLASH_CMS_APOLLO_STATE__ = ", - page, - )) - .unwrap(); - for entry in champs_stats.iter() { - CHAMPIONS_STATS - .lock() - .unwrap() - .insert(entry.0.to_owned(), entry.1.to_owned()); - } for champ in &datas.lol.champions_report { let id = champ.champion_id; if champions.contains_key(&id) { @@ -191,26 +167,16 @@ impl DataSource for CGGDataSource { ), ]; - let mut key: String = String::new(); - let champs_stats = CHAMPIONS_STATS.lock().unwrap(); - for val in champs_stats.values() { - if val.champion_id.is_some() && val.champion_id.unwrap() == champ.champion_id { - key = val.stats.as_ref().unwrap().id.to_owned(); - } - } - - if let Some(stat) = champs_stats.get(&key) { - data.push(( - position.to_owned(), - blocks, - Stat { - win_rate: stat.win_rate.unwrap(), - games: stat.games.unwrap(), - kda: stat.kda.unwrap(), - patch: champ.patch.to_owned(), - }, - )); - } + data.push(( + position.to_owned(), + blocks, + Stat { + win_rate: (champ.stats.wins as f64 / champ.stats.games as f64) * 100f64, + games: champ.stats.games, + kda: (champ.stats.kills + champ.stats.assists) as f64 / champ.stats.deaths as f64, + patch: champ.patch.to_owned(), + }, + )); } } data