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

3
.gitignore vendored
View file

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

View file

@ -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::<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)
})
}
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::<usize>().unwrap() - 1]["key"]
.as_str()
.unwrap()
})
.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)
})
.map(|x| { x.to_string() })
.collect::<Vec<String>>()
.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));
}

View file

@ -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,

View file

@ -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,

View file

@ -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);

View file

@ -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,