Fix format
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nyyu 2021-03-17 09:13:19 +01:00
parent 9d7eb9f875
commit c2cb38b703
4 changed files with 8 additions and 21 deletions

View file

@ -103,10 +103,7 @@ impl DataSource for CGGDataSource {
0 0
} }
fn get_champs_with_positions( fn get_champs_with_positions(&self, client: &ureq::Agent) -> IndexMap<u32, Vec<String>> {
&self,
client: &ureq::Agent,
) -> IndexMap<u32, Vec<String>> {
let req = client.get("https://champion.gg").call().unwrap(); let req = client.get("https://champion.gg").call().unwrap();
let page = &req.into_string().unwrap(); let page = &req.into_string().unwrap();
@ -153,9 +150,7 @@ impl DataSource for CGGDataSource {
let mut some_champ: Option<&ChampionReport> = None; let mut some_champ: Option<&ChampionReport> = None;
let reports = CHAMPIONS_REPORT.lock().unwrap(); let reports = CHAMPIONS_REPORT.lock().unwrap();
for champion in reports.iter() { for champion in reports.iter() {
if champion.champion_id.to_string() == champ.key if champion.champion_id.to_string() == champ.key && champion.role == *position {
&& champion.role == *position
{
some_champ = Some(champion); some_champ = Some(champion);
break; break;
} }
@ -205,7 +200,7 @@ impl DataSource for CGGDataSource {
win_rate: stat.win_rate.unwrap(), win_rate: stat.win_rate.unwrap(),
games: stat.games.unwrap(), games: stat.games.unwrap(),
kda: stat.kda.unwrap(), kda: stat.kda.unwrap(),
patch: champ.patch.to_owned() patch: champ.patch.to_owned(),
}, },
)); ));
} }

View file

@ -35,7 +35,7 @@ pub struct Stat {
pub win_rate: f64, pub win_rate: f64,
pub games: u32, pub games: u32,
pub kda: f64, pub kda: f64,
pub patch: String pub patch: String,
} }
pub trait DataSource { pub trait DataSource {
@ -43,10 +43,7 @@ pub trait DataSource {
fn get_timeout(&self) -> u64; fn get_timeout(&self) -> u64;
fn get_champs_with_positions( fn get_champs_with_positions(&self, client: &ureq::Agent) -> IndexMap<u32, Vec<String>>;
&self,
client: &ureq::Agent,
) -> IndexMap<u32, Vec<String>>;
fn get_champ_data_with_win_pourcentage( fn get_champ_data_with_win_pourcentage(
&self, &self,

View file

@ -1,11 +1,11 @@
use crate::data_source::{Build, DataSource, Item, Stat}; use crate::data_source::{Build, DataSource, Item, Stat};
use crate::ChampInfo; use crate::ChampInfo;
use crate::USER_AGENT_VALUE;
use indexmap::IndexMap; use indexmap::IndexMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde_derive::Deserialize; use serde_derive::Deserialize;
use serde_json::{json, Value}; use serde_json::{json, Value};
use std::time::Duration; use std::time::Duration;
use crate::USER_AGENT_VALUE;
pub struct KBDataSource { pub struct KBDataSource {
token: Option<String>, token: Option<String>,

View file

@ -90,7 +90,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.call()? .call()?
.into_json()?; .into_json()?;
info!("LoL version: {}", realm.v); info!("LoL version: {}", realm.v);
let champion: Champion = client let champion: Champion = client
.get(&format!( .get(&format!(
"https://ddragon.leagueoflegends.com/cdn/{}/data/en_US/champion.json", "https://ddragon.leagueoflegends.com/cdn/{}/data/en_US/champion.json",
@ -100,13 +99,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.into_json()?; .into_json()?;
info!("LoL numbers of champs: {}", champion.data.len()); info!("LoL numbers of champs: {}", champion.data.len());
let data_sources: [&'static (dyn DataSource + Sync + Send); 3] = [ let data_sources: [&'static (dyn DataSource + Sync + Send); 3] =
&PBDataSource, [&PBDataSource, &CGGDataSource, KBDataSource::new()];
&CGGDataSource,
KBDataSource::new(),
];
data_sources.par_iter().for_each(|data_source| { data_sources.par_iter().for_each(|data_source| {
let init = Instant::now(); let init = Instant::now();
execute_data_source(*data_source, &client, &champion, &lol_champs_dir); execute_data_source(*data_source, &client, &champion, &lol_champs_dir);
info!( info!(