lint
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nyyu 2021-03-11 00:00:04 +01:00
parent 6b2ec73a7d
commit 456f2e9624
2 changed files with 126 additions and 128 deletions

View File

@ -9,7 +9,7 @@ use crate::data_source::DataSource;
const CONSUMABLES: [u32; 9] = [2003, 2004, 2055, 2031, 2032, 2033, 2138, 2140, 2139];
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"]),
(
"Highest Win % Starters",
@ -31,13 +31,13 @@ impl CGGDataSource {
fn make_item_set_from_list(
&self,
list: &Vec<u32>,
list: &[u32],
label: &str,
key: &str,
data: &Value,
) -> Value {
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"]
.as_array()
.unwrap()
@ -128,7 +128,7 @@ impl DataSource for CGGDataSource {
.call()
.unwrap();
let response_status = req.status();
if 300 > response_status && response_status >= 200 {
if (200..300).contains(&response_status) {
lazy_static! {
static ref RE: Regex =
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();
let mut blocks = vec![];
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));
}
}

View File

@ -125,13 +125,10 @@ impl KBDataSource {
fn get_classname_mapping(&self, client: &ureq::Agent) -> IndexMap<String, String> {
let mut mapping = IndexMap::new();
match self.get_champion_response(client) {
Some(data) => {
for champ in data.champions {
mapping.insert(champ.classname, champ.name);
}
if let Some(data) = self.get_champion_response(client) {
for champ in data.champions {
mapping.insert(champ.classname, champ.name);
}
None => { /* Nothing to do */ }
};
mapping
}
@ -139,7 +136,7 @@ impl KBDataSource {
fn get_champion_response(&self, client: &ureq::Agent) -> Option<ChampionResponse> {
let token = match self.token.clone() {
Some(t) => t,
None => return None,
None => String::new(),
};
match client
.get("https://api.koreanbuilds.net/champions?patchid=-1")
@ -148,34 +145,31 @@ impl KBDataSource {
.call()
{
Ok(resp) => match resp.into_json() {
Ok(val) => return val,
Err(_) => return None,
Ok(val) => val,
Err(_) => None,
},
Err(_) => return None,
};
Err(_) => None,
}
}
fn get_positions(position: Option<Position>) -> Vec<String> {
let mut positions = Vec::new();
match position {
Some(pos) => {
if pos.top > 0 {
positions.push("TOP".to_owned());
}
if pos.jungle > 0 {
positions.push("JUNGLE".to_owned());
}
if pos.mid > 0 {
positions.push("MID".to_owned());
}
if pos.bot > 0 {
positions.push("BOT".to_owned());
}
if pos.support > 0 {
positions.push("SUPPORT".to_owned());
}
if let Some(pos) = position {
if pos.top > 0 {
positions.push("TOP".to_owned());
}
if pos.jungle > 0 {
positions.push("JUNGLE".to_owned());
}
if pos.mid > 0 {
positions.push("MID".to_owned());
}
if pos.bot > 0 {
positions.push("BOT".to_owned());
}
if pos.support > 0 {
positions.push("SUPPORT".to_owned());
}
None => { /* Nothing to do */ }
}
positions
}
@ -241,101 +235,105 @@ impl DataSource for KBDataSource {
}
};
let mut blocks = vec![];
let winrate = (data.builds2[0].wins / data.builds2[0].games) * 100.;
let mut starting_items: Vec<Item> = vec![];
if data.builds2[0].start_item0.item_id != 0 {
starting_items.push(Item {
id: data.builds2[0].start_item0.item_id.to_string(),
count: 1,
})
let mut winrate = 0.0;
if data.builds2.len() > 0 {
winrate = (data.builds2[0].wins / data.builds2[0].games) * 100.;
let mut starting_items: Vec<Item> = vec![];
if data.builds2[0].start_item0.item_id != 0 {
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))
}
}