This commit is contained in:
parent
6b2ec73a7d
commit
456f2e9624
2 changed files with 126 additions and 128 deletions
|
@ -9,7 +9,7 @@ use crate::data_source::DataSource;
|
||||||
|
|
||||||
const CONSUMABLES: [u32; 9] = [2003, 2004, 2055, 2031, 2032, 2033, 2138, 2140, 2139];
|
const CONSUMABLES: [u32; 9] = [2003, 2004, 2055, 2031, 2032, 2033, 2138, 2140, 2139];
|
||||||
const TRINKETS: [u32; 3] = [3340, 3364, 3363];
|
const TRINKETS: [u32; 3] = [3340, 3364, 3363];
|
||||||
const ITEM_TYPES: &'static [(&str, [&str; 2]); 4] = &[
|
const ITEM_TYPES: & [(&str, [&str; 2]); 4] = &[
|
||||||
("Most Frequent Starters", ["firstItems", "mostGames"]),
|
("Most Frequent Starters", ["firstItems", "mostGames"]),
|
||||||
(
|
(
|
||||||
"Highest Win % Starters",
|
"Highest Win % Starters",
|
||||||
|
@ -31,13 +31,13 @@ impl CGGDataSource {
|
||||||
|
|
||||||
fn make_item_set_from_list(
|
fn make_item_set_from_list(
|
||||||
&self,
|
&self,
|
||||||
list: &Vec<u32>,
|
list: &[u32],
|
||||||
label: &str,
|
label: &str,
|
||||||
key: &str,
|
key: &str,
|
||||||
data: &Value,
|
data: &Value,
|
||||||
) -> Value {
|
) -> Value {
|
||||||
let mut key_order = String::new();
|
let mut key_order = String::new();
|
||||||
if !data["skills"].get("skillInfo").is_none() {
|
if data["skills"].get("skillInfo").is_some() {
|
||||||
key_order = data["skills"][key]["order"]
|
key_order = data["skills"][key]["order"]
|
||||||
.as_array()
|
.as_array()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -128,7 +128,7 @@ impl DataSource for CGGDataSource {
|
||||||
.call()
|
.call()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let response_status = req.status();
|
let response_status = req.status();
|
||||||
if 300 > response_status && response_status >= 200 {
|
if (200..300).contains(&response_status) {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref RE: Regex =
|
static ref RE: Regex =
|
||||||
Regex::new(r"(?m)^\s+matchupData\.championData = (.*)$").unwrap();
|
Regex::new(r"(?m)^\s+matchupData\.championData = (.*)$").unwrap();
|
||||||
|
@ -137,7 +137,7 @@ impl DataSource for CGGDataSource {
|
||||||
serde_json::from_str(&RE.captures(&req.into_string().unwrap())?[1]).unwrap();
|
serde_json::from_str(&RE.captures(&req.into_string().unwrap())?[1]).unwrap();
|
||||||
let mut blocks = vec![];
|
let mut blocks = vec![];
|
||||||
for (label, path) in ITEM_TYPES.iter() {
|
for (label, path) in ITEM_TYPES.iter() {
|
||||||
if !data[&path[0]].get(&path[1]).is_none() {
|
if data[&path[0]].get(&path[1]).is_some() {
|
||||||
blocks.push(self.make_item_set(&data[&path[0]][&path[1]], label));
|
blocks.push(self.make_item_set(&data[&path[0]][&path[1]], label));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,13 +125,10 @@ impl KBDataSource {
|
||||||
|
|
||||||
fn get_classname_mapping(&self, client: &ureq::Agent) -> IndexMap<String, String> {
|
fn get_classname_mapping(&self, client: &ureq::Agent) -> IndexMap<String, String> {
|
||||||
let mut mapping = IndexMap::new();
|
let mut mapping = IndexMap::new();
|
||||||
match self.get_champion_response(client) {
|
if let Some(data) = self.get_champion_response(client) {
|
||||||
Some(data) => {
|
for champ in data.champions {
|
||||||
for champ in data.champions {
|
mapping.insert(champ.classname, champ.name);
|
||||||
mapping.insert(champ.classname, champ.name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => { /* Nothing to do */ }
|
|
||||||
};
|
};
|
||||||
mapping
|
mapping
|
||||||
}
|
}
|
||||||
|
@ -139,7 +136,7 @@ impl KBDataSource {
|
||||||
fn get_champion_response(&self, client: &ureq::Agent) -> Option<ChampionResponse> {
|
fn get_champion_response(&self, client: &ureq::Agent) -> Option<ChampionResponse> {
|
||||||
let token = match self.token.clone() {
|
let token = match self.token.clone() {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => return None,
|
None => String::new(),
|
||||||
};
|
};
|
||||||
match client
|
match client
|
||||||
.get("https://api.koreanbuilds.net/champions?patchid=-1")
|
.get("https://api.koreanbuilds.net/champions?patchid=-1")
|
||||||
|
@ -148,34 +145,31 @@ impl KBDataSource {
|
||||||
.call()
|
.call()
|
||||||
{
|
{
|
||||||
Ok(resp) => match resp.into_json() {
|
Ok(resp) => match resp.into_json() {
|
||||||
Ok(val) => return val,
|
Ok(val) => val,
|
||||||
Err(_) => return None,
|
Err(_) => None,
|
||||||
},
|
},
|
||||||
Err(_) => return None,
|
Err(_) => None,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_positions(position: Option<Position>) -> Vec<String> {
|
fn get_positions(position: Option<Position>) -> Vec<String> {
|
||||||
let mut positions = Vec::new();
|
let mut positions = Vec::new();
|
||||||
match position {
|
if let Some(pos) = position {
|
||||||
Some(pos) => {
|
if pos.top > 0 {
|
||||||
if pos.top > 0 {
|
positions.push("TOP".to_owned());
|
||||||
positions.push("TOP".to_owned());
|
}
|
||||||
}
|
if pos.jungle > 0 {
|
||||||
if pos.jungle > 0 {
|
positions.push("JUNGLE".to_owned());
|
||||||
positions.push("JUNGLE".to_owned());
|
}
|
||||||
}
|
if pos.mid > 0 {
|
||||||
if pos.mid > 0 {
|
positions.push("MID".to_owned());
|
||||||
positions.push("MID".to_owned());
|
}
|
||||||
}
|
if pos.bot > 0 {
|
||||||
if pos.bot > 0 {
|
positions.push("BOT".to_owned());
|
||||||
positions.push("BOT".to_owned());
|
}
|
||||||
}
|
if pos.support > 0 {
|
||||||
if pos.support > 0 {
|
positions.push("SUPPORT".to_owned());
|
||||||
positions.push("SUPPORT".to_owned());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => { /* Nothing to do */ }
|
|
||||||
}
|
}
|
||||||
positions
|
positions
|
||||||
}
|
}
|
||||||
|
@ -241,101 +235,105 @@ impl DataSource for KBDataSource {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut blocks = vec![];
|
let mut blocks = vec![];
|
||||||
let winrate = (data.builds2[0].wins / data.builds2[0].games) * 100.;
|
let mut winrate = 0.0;
|
||||||
let mut starting_items: Vec<Item> = vec![];
|
if data.builds2.len() > 0 {
|
||||||
if data.builds2[0].start_item0.item_id != 0 {
|
winrate = (data.builds2[0].wins / data.builds2[0].games) * 100.;
|
||||||
starting_items.push(Item {
|
let mut starting_items: Vec<Item> = vec![];
|
||||||
id: data.builds2[0].start_item0.item_id.to_string(),
|
if data.builds2[0].start_item0.item_id != 0 {
|
||||||
count: 1,
|
starting_items.push(Item {
|
||||||
})
|
id: data.builds2[0].start_item0.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].start_item1.item_id != 0 {
|
||||||
|
starting_items.push(Item {
|
||||||
|
id: data.builds2[0].start_item1.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].start_item2.item_id != 0 {
|
||||||
|
starting_items.push(Item {
|
||||||
|
id: data.builds2[0].start_item2.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].start_item3.item_id != 0 {
|
||||||
|
starting_items.push(Item {
|
||||||
|
id: data.builds2[0].start_item3.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].start_item4.item_id != 0 {
|
||||||
|
starting_items.push(Item {
|
||||||
|
id: data.builds2[0].start_item4.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].start_item5.item_id != 0 {
|
||||||
|
starting_items.push(Item {
|
||||||
|
id: data.builds2[0].start_item5.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
blocks.push(json!(Build {
|
||||||
|
type_: format!(
|
||||||
|
"Early game items | skillOrder : {}",
|
||||||
|
data.builds2[0].skill_order
|
||||||
|
),
|
||||||
|
items: starting_items
|
||||||
|
}));
|
||||||
|
let mut final_items: Vec<Item> = vec![];
|
||||||
|
if data.builds2[0].item0.item_id != 0 {
|
||||||
|
final_items.push(Item {
|
||||||
|
id: data.builds2[0].item0.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].item1.item_id != 0 {
|
||||||
|
final_items.push(Item {
|
||||||
|
id: data.builds2[0].item1.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].item2.item_id != 0 {
|
||||||
|
final_items.push(Item {
|
||||||
|
id: data.builds2[0].item2.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].item3.item_id != 0 {
|
||||||
|
final_items.push(Item {
|
||||||
|
id: data.builds2[0].item3.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].item4.item_id != 0 {
|
||||||
|
final_items.push(Item {
|
||||||
|
id: data.builds2[0].item4.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].item5.item_id != 0 {
|
||||||
|
final_items.push(Item {
|
||||||
|
id: data.builds2[0].item5.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if data.builds2[0].item6.item_id != 0 {
|
||||||
|
final_items.push(Item {
|
||||||
|
id: data.builds2[0].item6.item_id.to_string(),
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
blocks.push(json!(Build {
|
||||||
|
type_: format!(
|
||||||
|
"Item order by time finished | Summoner : {}",
|
||||||
|
data.builds2[0].summoner.name
|
||||||
|
),
|
||||||
|
items: final_items
|
||||||
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
if data.builds2[0].start_item1.item_id != 0 {
|
|
||||||
starting_items.push(Item {
|
|
||||||
id: data.builds2[0].start_item1.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].start_item2.item_id != 0 {
|
|
||||||
starting_items.push(Item {
|
|
||||||
id: data.builds2[0].start_item2.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].start_item3.item_id != 0 {
|
|
||||||
starting_items.push(Item {
|
|
||||||
id: data.builds2[0].start_item3.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].start_item4.item_id != 0 {
|
|
||||||
starting_items.push(Item {
|
|
||||||
id: data.builds2[0].start_item4.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].start_item5.item_id != 0 {
|
|
||||||
starting_items.push(Item {
|
|
||||||
id: data.builds2[0].start_item5.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
blocks.push(json!(Build {
|
|
||||||
type_: format!(
|
|
||||||
"Early game items | skillOrder : {}",
|
|
||||||
data.builds2[0].skill_order
|
|
||||||
),
|
|
||||||
items: starting_items
|
|
||||||
}));
|
|
||||||
let mut final_items: Vec<Item> = vec![];
|
|
||||||
if data.builds2[0].item0.item_id != 0 {
|
|
||||||
final_items.push(Item {
|
|
||||||
id: data.builds2[0].item0.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].item1.item_id != 0 {
|
|
||||||
final_items.push(Item {
|
|
||||||
id: data.builds2[0].item1.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].item2.item_id != 0 {
|
|
||||||
final_items.push(Item {
|
|
||||||
id: data.builds2[0].item2.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].item3.item_id != 0 {
|
|
||||||
final_items.push(Item {
|
|
||||||
id: data.builds2[0].item3.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].item4.item_id != 0 {
|
|
||||||
final_items.push(Item {
|
|
||||||
id: data.builds2[0].item4.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].item5.item_id != 0 {
|
|
||||||
final_items.push(Item {
|
|
||||||
id: data.builds2[0].item5.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if data.builds2[0].item6.item_id != 0 {
|
|
||||||
final_items.push(Item {
|
|
||||||
id: data.builds2[0].item6.item_id.to_string(),
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
blocks.push(json!(Build {
|
|
||||||
type_: format!(
|
|
||||||
"Item order by time finished | Summoner : {}",
|
|
||||||
data.builds2[0].summoner.name
|
|
||||||
),
|
|
||||||
items: final_items
|
|
||||||
}));
|
|
||||||
Some((blocks, winrate))
|
Some((blocks, winrate))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue