format
This commit is contained in:
parent
c4ad18d6fb
commit
7eee95ff39
5 changed files with 35 additions and 13 deletions
|
@ -6,8 +6,8 @@ use std::collections::HashMap;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use crate::data_source::{DataSource, Stat};
|
use crate::data_source::{DataSource, Stat};
|
||||||
use crate::Champion;
|
|
||||||
use crate::ChampInfo;
|
use crate::ChampInfo;
|
||||||
|
use crate::Champion;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct BuildResponse {
|
struct BuildResponse {
|
||||||
|
@ -104,7 +104,11 @@ impl DataSource for CGGDataSource {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_champs_with_positions(&self, client: &ureq::Agent, _champion: &Champion) -> IndexMap<u32, Vec<String>> {
|
fn get_champs_with_positions(
|
||||||
|
&self,
|
||||||
|
client: &ureq::Agent,
|
||||||
|
_champion: &Champion,
|
||||||
|
) -> 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();
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,11 @@ pub trait DataSource {
|
||||||
|
|
||||||
fn get_timeout(&self) -> u64;
|
fn get_timeout(&self) -> u64;
|
||||||
|
|
||||||
fn get_champs_with_positions(&self, client: &ureq::Agent, champion: &Champion) -> IndexMap<u32, Vec<String>>;
|
fn get_champs_with_positions(
|
||||||
|
&self,
|
||||||
|
client: &ureq::Agent,
|
||||||
|
champion: &Champion,
|
||||||
|
) -> IndexMap<u32, Vec<String>>;
|
||||||
|
|
||||||
fn get_champ_data_with_win_pourcentage(
|
fn get_champ_data_with_win_pourcentage(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::data_source::{Build, DataSource, Item, Stat};
|
use crate::data_source::{Build, DataSource, Item, Stat};
|
||||||
use crate::Champion as ChampionLoL;
|
|
||||||
use crate::ChampInfo;
|
use crate::ChampInfo;
|
||||||
|
use crate::Champion as ChampionLoL;
|
||||||
use crate::USER_AGENT_VALUE;
|
use crate::USER_AGENT_VALUE;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
@ -115,7 +115,9 @@ fn get_auth_token() -> Option<String> {
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
bundle = (&bundle[(q_position + 1)..]).to_string();
|
bundle = (&bundle[(q_position + 1)..]).to_string();
|
||||||
bundle.find('"').map(|position| (&bundle[..position]).to_string())
|
bundle
|
||||||
|
.find('"')
|
||||||
|
.map(|position| (&bundle[..position]).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KBDataSource {
|
impl KBDataSource {
|
||||||
|
@ -294,7 +296,11 @@ impl DataSource for KBDataSource {
|
||||||
300
|
300
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_champs_with_positions(&self, client: &ureq::Agent, _champion: &ChampionLoL) -> IndexMap<u32, Vec<String>> {
|
fn get_champs_with_positions(
|
||||||
|
&self,
|
||||||
|
client: &ureq::Agent,
|
||||||
|
_champion: &ChampionLoL,
|
||||||
|
) -> IndexMap<u32, Vec<String>> {
|
||||||
let mut champions = IndexMap::new();
|
let mut champions = IndexMap::new();
|
||||||
let data: ChampionResponse = match self.get_champion_response(client) {
|
let data: ChampionResponse = match self.get_champion_response(client) {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
|
@ -375,7 +381,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
let datasource = KBDataSource::new();
|
let datasource = KBDataSource::new();
|
||||||
let champion = ChampionLoL {
|
let champion = ChampionLoL {
|
||||||
data: IndexMap::new()
|
data: IndexMap::new(),
|
||||||
};
|
};
|
||||||
let champs_with_positions = datasource.get_champs_with_positions(&client, &champion);
|
let champs_with_positions = datasource.get_champs_with_positions(&client, &champion);
|
||||||
assert!(champs_with_positions.len() > 0);
|
assert!(champs_with_positions.len() > 0);
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -21,14 +21,14 @@ use winreg::RegKey;
|
||||||
mod cgg_data_source;
|
mod cgg_data_source;
|
||||||
mod data_source;
|
mod data_source;
|
||||||
mod kb_data_source;
|
mod kb_data_source;
|
||||||
mod pb_data_source;
|
|
||||||
mod ms_data_source;
|
mod ms_data_source;
|
||||||
|
mod pb_data_source;
|
||||||
|
|
||||||
use cgg_data_source::CGGDataSource;
|
use cgg_data_source::CGGDataSource;
|
||||||
use data_source::DataSource;
|
use data_source::DataSource;
|
||||||
use kb_data_source::KBDataSource;
|
use kb_data_source::KBDataSource;
|
||||||
use pb_data_source::PBDataSource;
|
|
||||||
use ms_data_source::MSDataSource;
|
use ms_data_source::MSDataSource;
|
||||||
|
use pb_data_source::PBDataSource;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Realm {
|
struct Realm {
|
||||||
|
@ -101,8 +101,12 @@ 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); 4] =
|
let data_sources: [&'static (dyn DataSource + Sync + Send); 4] = [
|
||||||
[&PBDataSource, &CGGDataSource, KBDataSource::new(), &MSDataSource];
|
&PBDataSource,
|
||||||
|
&CGGDataSource,
|
||||||
|
KBDataSource::new(),
|
||||||
|
&MSDataSource,
|
||||||
|
];
|
||||||
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);
|
||||||
|
|
|
@ -3,8 +3,8 @@ use serde_derive::Deserialize;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
use crate::data_source::{DataSource, Stat};
|
use crate::data_source::{DataSource, Stat};
|
||||||
use crate::Champion as ChampionLoL;
|
|
||||||
use crate::ChampInfo;
|
use crate::ChampInfo;
|
||||||
|
use crate::Champion as ChampionLoL;
|
||||||
|
|
||||||
pub struct PBDataSource;
|
pub struct PBDataSource;
|
||||||
|
|
||||||
|
@ -27,7 +27,11 @@ impl DataSource for PBDataSource {
|
||||||
300
|
300
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_champs_with_positions(&self, client: &ureq::Agent, _champion: &ChampionLoL) -> IndexMap<u32, Vec<String>> {
|
fn get_champs_with_positions(
|
||||||
|
&self,
|
||||||
|
client: &ureq::Agent,
|
||||||
|
_champion: &ChampionLoL,
|
||||||
|
) -> IndexMap<u32, Vec<String>> {
|
||||||
let mut champs = IndexMap::new();
|
let mut champs = IndexMap::new();
|
||||||
|
|
||||||
let page = client
|
let page = client
|
||||||
|
|
Loading…
Add table
Reference in a new issue