This commit is contained in:
parent
a9ea40f44a
commit
3fade08679
1 changed files with 15 additions and 49 deletions
|
@ -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<u32>,
|
||||
stats: Option<Info>,
|
||||
matchups: Option<Vec<Info>>,
|
||||
#[serde(rename = "winRate")]
|
||||
win_rate: Option<f64>,
|
||||
games: Option<u32>,
|
||||
kda: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
struct Info {
|
||||
id: String,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref CHAMPIONS_REPORT: Mutex<Vec<ChampionReport>> = Mutex::new(Vec::new());
|
||||
static ref CHAMPIONS_STATS: Mutex<HashMap<String, ChampStat>> = 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<String, ChampStat> = 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,28 +167,18 @@ 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(),
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue