diff --git a/.gitignore b/.gitignore index 9f97022..39d6990 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -target/ \ No newline at end of file +target/ +*.json \ No newline at end of file diff --git a/src/cgg_data_source.rs b/src/cgg_data_source.rs index 563bc45..24f5ffe 100644 --- a/src/cgg_data_source.rs +++ b/src/cgg_data_source.rs @@ -30,7 +30,13 @@ struct ChampionReport { #[derive(Deserialize, Debug)] struct Stats { starting_items: Build, - core_builds: Build + core_builds: Build, + big_item_builds: Build, + skills: Build, + most_common_starting_items: Build, + most_common_core_builds: Build, + most_common_big_item_builds: Build, + most_common_skills: Build } #[derive(Deserialize, Debug)] @@ -47,37 +53,21 @@ pub struct CGGDataSource; impl CGGDataSource { fn make_item_set(&self, build: &Build, label: &str) -> Value { json!({ - "items": build.build.iter().map(|x| json!({"id": x, "count": 1})).collect::>(), + "items": build.build.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::>(), "type": format!("{} ({:.2}% - {} games)", label, build.win_rate * 100., build.games) }) } fn make_item_set_from_list( - &self, - list: &[u32], - label: &str, - key: &str, - data: &Value, + &self, build: &Build, label: &str, skills: &Build, ) -> Value { - let mut key_order = String::new(); - if data["skills"].get("skillInfo").is_some() { - key_order = data["skills"][key]["order"] - .as_array() - .unwrap() + let key_order = skills.build .iter() - .map(|x| { - data["skills"]["skillInfo"].as_array().unwrap() - [x.as_str().unwrap().parse::().unwrap() - 1]["key"] - .as_str() - .unwrap() - }) - .collect::>() - .join("."); - } - json!({ - "items": list.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::>(), - "type": format!("{} {}", label, key_order) - }) + .map(|x| { x.to_string() }) + .collect::>() + .join(""); + + self.make_item_set(build, [label, &key_order.as_str()].join(" ").as_str()) } } @@ -86,6 +76,10 @@ impl DataSource for CGGDataSource { "CGG" } + fn get_timeout(&self) -> u64 { + 0 + } + fn get_champs_with_positions_and_patch( &self, client: &ureq::Agent, @@ -146,8 +140,13 @@ impl DataSource for CGGDataSource { if let Some(champ) = some_champ { let mut blocks = vec![]; - blocks.push(self.make_item_set(&champ.stats.starting_items, "Highest % Win Starting Items")); + blocks.push(self.make_item_set_from_list(&champ.stats.starting_items, "Highest % Win Starting Items | Skills: ", &champ.stats.skills)); blocks.push(self.make_item_set(&champ.stats.core_builds, "Highest % Win Core Build Path:")); + blocks.push(self.make_item_set(&champ.stats.big_item_builds, "Highest % Win Big Items:")); + + blocks.push(self.make_item_set_from_list(&champ.stats.most_common_starting_items, "Most Frequent Starting Items | Skills: ", &champ.stats.most_common_skills)); + blocks.push(self.make_item_set(&champ.stats.most_common_core_builds, "Most Frequent Build Path")); + blocks.push(self.make_item_set(&champ.stats.most_common_big_item_builds, "Most Frequent Big Items:")); return Some((blocks, 42.0)); } diff --git a/src/data_source.rs b/src/data_source.rs index 4a0fcff..754f050 100644 --- a/src/data_source.rs +++ b/src/data_source.rs @@ -34,6 +34,8 @@ pub struct Item { pub trait DataSource { fn get_alias(&self) -> &str; + fn get_timeout(&self) -> u64; + fn get_champs_with_positions_and_patch( &self, client: &ureq::Agent, diff --git a/src/kb_data_source.rs b/src/kb_data_source.rs index 6bc2c20..acf0a4f 100644 --- a/src/kb_data_source.rs +++ b/src/kb_data_source.rs @@ -181,6 +181,10 @@ impl DataSource for KBDataSource { "KB" } + fn get_timeout(&self) -> u64 { + 300 + } + fn get_champs_with_positions_and_patch( &self, client: &ureq::Agent, diff --git a/src/main.rs b/src/main.rs index 09292d1..b82c784 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,7 +117,7 @@ fn main() { &path, &client, ); - thread::sleep(Duration::from_millis(300)); + thread::sleep(Duration::from_millis(data_source.get_timeout())); } } else { error!("{} not found in LoL champs", &id); diff --git a/src/pb_data_source.rs b/src/pb_data_source.rs index d24632e..0de9e56 100644 --- a/src/pb_data_source.rs +++ b/src/pb_data_source.rs @@ -10,6 +10,10 @@ impl DataSource for PBDataSource { "PB" } + fn get_timeout(&self) -> u64 { + 0 + } + fn get_champs_with_positions_and_patch( &self, _client: &ureq::Agent,