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
}
fn get_champs_with_positions_and_patch(
fn get_champs_with_positions(
&self,
client: &ureq::Agent,
) -> (IndexMap<u32, Vec<String>>, String) {
) -> IndexMap<u32, Vec<String>> {
let req = client.get("https://champion.gg").call().unwrap();
let page = &req.into_string().unwrap();
@ -124,7 +124,6 @@ impl DataSource for CGGDataSource {
.unwrap()
.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();
for champ in &datas.lol.champions_report {
@ -142,7 +141,7 @@ impl DataSource for CGGDataSource {
CHAMPIONS_REPORT.lock().unwrap().push(report);
}
(champions, patch)
champions
}
fn get_champ_data_with_win_pourcentage(
@ -208,6 +207,7 @@ impl DataSource for CGGDataSource {
win_rate: stat.win_rate.unwrap(),
games: stat.games.unwrap(),
kda: stat.kda.unwrap(),
patch: champ.patch.to_owned()
},
));
}

View file

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

View file

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

View file

@ -135,9 +135,8 @@ fn execute_data_source(
) {
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!(
"{} numbers of champs: {}",
data_source.get_alias(),
@ -151,7 +150,6 @@ fn execute_data_source(
client,
champion,
lol_champs_dir,
&patch,
*id,
positions,
);
@ -163,7 +161,6 @@ fn execute_data_source(
client,
champion,
lol_champs_dir,
&patch,
*id,
positions,
);
@ -177,7 +174,6 @@ fn get_and_write_item_set(
client: &ureq::Agent,
champion: &Champion,
lol_champs_dir: &PathBuf,
patch: &str,
id: u32,
positions: &[String],
) {
@ -188,7 +184,7 @@ fn get_and_write_item_set(
} else {
let path = lol_champs_dir.join(&champ_id).join("Recommended");
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 {
error!("{} not found in LoL champs", &champ_id);

View file

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