patch is by champ
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
nyyu 2021-03-16 11:13:54 +01:00
parent 3906d6cc42
commit 2d72bab0fe
5 changed files with 51 additions and 60 deletions

View file

@ -105,10 +105,10 @@ impl DataSource for CGGDataSource {
0 0
} }
fn get_champs_with_positions_and_patch( fn get_champs_with_positions(
&self, &self,
client: &ureq::Agent, client: &ureq::Agent,
) -> (IndexMap<u32, Vec<String>>, String) { ) -> 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();
@ -124,7 +124,6 @@ impl DataSource for CGGDataSource {
.unwrap() .unwrap()
.insert(entry.0.to_owned(), entry.1.to_owned()); .insert(entry.0.to_owned(), entry.1.to_owned());
} }
let patch = datas.lol.champions_report[0].patch.to_owned();
let mut champions: IndexMap<u32, Vec<String>> = IndexMap::new(); let mut champions: IndexMap<u32, Vec<String>> = IndexMap::new();
for champ in &datas.lol.champions_report { for champ in &datas.lol.champions_report {
@ -142,7 +141,7 @@ impl DataSource for CGGDataSource {
CHAMPIONS_REPORT.lock().unwrap().push(report); CHAMPIONS_REPORT.lock().unwrap().push(report);
} }
(champions, patch) champions
} }
fn get_champ_data_with_win_pourcentage( fn get_champ_data_with_win_pourcentage(
@ -208,6 +207,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()
}, },
)); ));
} }

View file

@ -35,6 +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 trait DataSource { pub trait DataSource {
@ -44,10 +45,10 @@ pub trait DataSource {
fn get_timeout(&self) -> u64; fn get_timeout(&self) -> u64;
fn get_champs_with_positions_and_patch( fn get_champs_with_positions(
&self, &self,
client: &ureq::Agent, client: &ureq::Agent,
) -> (IndexMap<u32, Vec<String>>, String); ) -> IndexMap<u32, Vec<String>>;
fn get_champ_data_with_win_pourcentage( fn get_champ_data_with_win_pourcentage(
&self, &self,
@ -60,7 +61,6 @@ pub trait DataSource {
&self, &self,
champ: &ChampInfo, champ: &ChampInfo,
positions: &[String], positions: &[String],
ver: &str,
path: &PathBuf, path: &PathBuf,
client: &ureq::Agent, client: &ureq::Agent,
) { ) {
@ -100,7 +100,7 @@ pub trait DataSource {
"{} {} {} - {:.2}% wins - {} games - {:.2} kda", "{} {} {} - {:.2}% wins - {} games - {:.2} kda",
self.get_alias(), self.get_alias(),
build.0, build.0,
ver, build.2.patch,
build.2.win_rate, build.2.win_rate,
build.2.games, build.2.games,
build.2.kda build.2.kda

View file

@ -73,8 +73,9 @@ struct KBBuild {
#[serde(rename = "skillOrder")] #[serde(rename = "skillOrder")]
skill_order: String, skill_order: String,
wins: f64, wins: f64,
games: f64, games: u32,
summoner: Summoner, summoner: Summoner,
patch: Patch,
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
@ -267,9 +268,10 @@ impl KBDataSource {
build.position.to_owned().to_uppercase(), build.position.to_owned().to_uppercase(),
blocks, blocks,
Stat { Stat {
win_rate: (build.wins / build.games) * 100., win_rate: (build.wins / build.games as f64) * 100.,
games: build.games as u32, games: build.games,
kda: 0.0, kda: 0.0,
patch: build.patch.patch_version.to_owned(),
}, },
) )
} }
@ -290,25 +292,18 @@ impl DataSource for KBDataSource {
300 300
} }
fn get_champs_with_positions_and_patch( fn get_champs_with_positions(&self, client: &ureq::Agent) -> IndexMap<u32, Vec<String>> {
&self,
client: &ureq::Agent,
) -> (IndexMap<u32, Vec<String>>, 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,
None => { None => {
return (champions, String::new()); return champions;
} }
}; };
let patch = match data.patches.get(0) {
Some(p) => p.patch_version.clone(),
None => return (champions, String::new()),
};
for champ in data.champions { for champ in data.champions {
champions.insert(champ.id, KBDataSource::get_positions(champ.builds)); champions.insert(champ.id, KBDataSource::get_positions(champ.builds));
} }
(champions, patch) champions
} }
fn get_champ_data_with_win_pourcentage( fn get_champ_data_with_win_pourcentage(
@ -319,40 +314,40 @@ impl DataSource for KBDataSource {
) -> Vec<(String, Vec<Value>, Stat)> { ) -> Vec<(String, Vec<Value>, Stat)> {
let mut champ_data = vec![]; let mut champ_data = vec![];
if let Some(token) = TOKEN.lock().unwrap().as_ref() { if let Some(token) = TOKEN.lock().unwrap().as_ref() {
let data: BuildResponse = match client let data: BuildResponse = match client
.get(&format!( .get(&format!(
"https://api.koreanbuilds.net/builds?chmpname={}&patchid=-2&position=COMPOSITE", "https://api.koreanbuilds.net/builds?chmpname={}&patchid=-2&position=COMPOSITE",
champ.id champ.id
)) ))
.set("Accept", "application/json") .set("Accept", "application/json")
.set("Authorization", token.as_str()) .set("Authorization", token.as_str())
.call() .call()
{ {
Ok(resp) => match resp.into_json() { Ok(resp) => match resp.into_json() {
Ok(val) => val, Ok(val) => val,
Err(_) => {
return vec![];
}
},
Err(_) => { Err(_) => {
return vec![]; return vec![];
} }
}; },
Err(_) => {
return vec![];
}
};
for pos in position { for pos in position {
let mut build: Option<&KBBuild> = None; let mut build: Option<&KBBuild> = None;
for b in &data.builds2 { for b in &data.builds2 {
if b.position.to_uppercase() == *pos { if b.position.to_uppercase() == *pos {
build = Some(b); build = Some(b);
break; break;
}
}
if let Some(b) = build {
champ_data.push(self.get_build(&b));
} }
} }
if let Some(b) = build {
champ_data.push(self.get_build(&b));
}
}
} }
champ_data champ_data
} }
@ -381,9 +376,9 @@ mod tests {
.build(); .build();
let datasource = KBDataSource; let datasource = KBDataSource;
datasource.init(&client); datasource.init(&client);
let champs_with_positions_and_patch = let champs_with_positions =
datasource.get_champs_with_positions_and_patch(&client); datasource.get_champs_with_positions(&client);
assert!(champs_with_positions_and_patch.0.len() > 0); assert!(champs_with_positions.len() > 0);
} }
#[test] #[test]

View file

@ -135,9 +135,8 @@ fn execute_data_source(
) { ) {
data_source.init(client); data_source.init(client);
let (champs, patch) = data_source.get_champs_with_positions_and_patch(&client); let champs = data_source.get_champs_with_positions(&client);
info!("{} version: {}", data_source.get_alias(), patch);
info!( info!(
"{} numbers of champs: {}", "{} numbers of champs: {}",
data_source.get_alias(), data_source.get_alias(),
@ -151,7 +150,6 @@ fn execute_data_source(
client, client,
champion, champion,
lol_champs_dir, lol_champs_dir,
&patch,
*id, *id,
positions, positions,
); );
@ -163,7 +161,6 @@ fn execute_data_source(
client, client,
champion, champion,
lol_champs_dir, lol_champs_dir,
&patch,
*id, *id,
positions, positions,
); );
@ -177,7 +174,6 @@ fn get_and_write_item_set(
client: &ureq::Agent, client: &ureq::Agent,
champion: &Champion, champion: &Champion,
lol_champs_dir: &PathBuf, lol_champs_dir: &PathBuf,
patch: &str,
id: u32, id: u32,
positions: &[String], positions: &[String],
) { ) {
@ -188,7 +184,7 @@ fn get_and_write_item_set(
} else { } else {
let path = lol_champs_dir.join(&champ_id).join("Recommended"); let path = lol_champs_dir.join(&champ_id).join("Recommended");
fs::create_dir_all(&path).unwrap(); fs::create_dir_all(&path).unwrap();
data_source.write_item_set(&champ, &positions, &patch, &path, &client); data_source.write_item_set(&champ, &positions, &path, &client);
} }
} else { } else {
error!("{} not found in LoL champs", &champ_id); error!("{} not found in LoL champs", &champ_id);

View file

@ -16,11 +16,11 @@ impl DataSource for PBDataSource {
0 0
} }
fn get_champs_with_positions_and_patch( fn get_champs_with_positions(
&self, &self,
_client: &ureq::Agent, _client: &ureq::Agent,
) -> (IndexMap<u32, Vec<String>>, String) { ) -> IndexMap<u32, Vec<String>> {
(IndexMap::new(), String::new()) IndexMap::new()
} }
fn get_champ_data_with_win_pourcentage( fn get_champ_data_with_win_pourcentage(