improve CGG datasource

This commit is contained in:
nyyu 2021-03-14 09:49:18 +01:00
parent 0c83809911
commit d238c9a4b9
6 changed files with 38 additions and 28 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
target/ target/
*.json

View file

@ -30,7 +30,13 @@ struct ChampionReport {
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct Stats { struct Stats {
starting_items: Build, 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)] #[derive(Deserialize, Debug)]
@ -47,37 +53,21 @@ pub struct CGGDataSource;
impl CGGDataSource { impl CGGDataSource {
fn make_item_set(&self, build: &Build, label: &str) -> Value { fn make_item_set(&self, build: &Build, label: &str) -> Value {
json!({ json!({
"items": build.build.iter().map(|x| json!({"id": x, "count": 1})).collect::<Vec<Value>>(), "items": build.build.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
"type": format!("{} ({:.2}% - {} games)", label, build.win_rate * 100., build.games) "type": format!("{} ({:.2}% - {} games)", label, build.win_rate * 100., build.games)
}) })
} }
fn make_item_set_from_list( fn make_item_set_from_list(
&self, &self, build: &Build, label: &str, skills: &Build,
list: &[u32],
label: &str,
key: &str,
data: &Value,
) -> Value { ) -> Value {
let mut key_order = String::new(); let key_order = skills.build
if data["skills"].get("skillInfo").is_some() {
key_order = data["skills"][key]["order"]
.as_array()
.unwrap()
.iter() .iter()
.map(|x| { .map(|x| { x.to_string() })
data["skills"]["skillInfo"].as_array().unwrap() .collect::<Vec<String>>()
[x.as_str().unwrap().parse::<usize>().unwrap() - 1]["key"] .join("");
.as_str()
.unwrap() self.make_item_set(build, [label, &key_order.as_str()].join(" ").as_str())
})
.collect::<Vec<&str>>()
.join(".");
}
json!({
"items": list.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
"type": format!("{} {}", label, key_order)
})
} }
} }
@ -86,6 +76,10 @@ impl DataSource for CGGDataSource {
"CGG" "CGG"
} }
fn get_timeout(&self) -> u64 {
0
}
fn get_champs_with_positions_and_patch( fn get_champs_with_positions_and_patch(
&self, &self,
client: &ureq::Agent, client: &ureq::Agent,
@ -146,8 +140,13 @@ impl DataSource for CGGDataSource {
if let Some(champ) = some_champ { if let Some(champ) = some_champ {
let mut blocks = vec![]; 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.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)); return Some((blocks, 42.0));
} }

View file

@ -34,6 +34,8 @@ pub struct Item {
pub trait DataSource { pub trait DataSource {
fn get_alias(&self) -> &str; fn get_alias(&self) -> &str;
fn get_timeout(&self) -> u64;
fn get_champs_with_positions_and_patch( fn get_champs_with_positions_and_patch(
&self, &self,
client: &ureq::Agent, client: &ureq::Agent,

View file

@ -181,6 +181,10 @@ impl DataSource for KBDataSource {
"KB" "KB"
} }
fn get_timeout(&self) -> u64 {
300
}
fn get_champs_with_positions_and_patch( fn get_champs_with_positions_and_patch(
&self, &self,
client: &ureq::Agent, client: &ureq::Agent,

View file

@ -117,7 +117,7 @@ fn main() {
&path, &path,
&client, &client,
); );
thread::sleep(Duration::from_millis(300)); thread::sleep(Duration::from_millis(data_source.get_timeout()));
} }
} else { } else {
error!("{} not found in LoL champs", &id); error!("{} not found in LoL champs", &id);

View file

@ -10,6 +10,10 @@ impl DataSource for PBDataSource {
"PB" "PB"
} }
fn get_timeout(&self) -> u64 {
0
}
fn get_champs_with_positions_and_patch( fn get_champs_with_positions_and_patch(
&self, &self,
_client: &ureq::Agent, _client: &ureq::Agent,