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

This commit is contained in:
nyyu 2021-03-14 18:10:51 +01:00
parent dd5faf3e96
commit 3f7de3abac
2 changed files with 12 additions and 14 deletions

View file

@ -91,8 +91,7 @@ impl CGGDataSource {
fn extract_json(pattern: &str, page: &str) -> String { fn extract_json(pattern: &str, page: &str) -> String {
let json = page[page.find(pattern).unwrap() + pattern.len()..].to_owned(); let json = page[page.find(pattern).unwrap() + pattern.len()..].to_owned();
json[..json.find("};").unwrap() + 1] json[..json.find("};").unwrap() + 1].replace("undefined", "null")
.replace("undefined", "null")
} }
impl DataSource for CGGDataSource { impl DataSource for CGGDataSource {

View file

@ -241,9 +241,7 @@ impl DataSource for KBDataSource {
} }
}; };
let mut blocks = vec![]; let mut blocks = vec![];
let mut winrate = 0.0;
if !data.builds2.is_empty() { if !data.builds2.is_empty() {
winrate = (data.builds2[0].wins / data.builds2[0].games) * 100.;
let mut starting_items: Vec<Item> = vec![]; let mut starting_items: Vec<Item> = vec![];
if data.builds2[0].start_item0.item_id != 0 { if data.builds2[0].start_item0.item_id != 0 {
starting_items.push(Item { starting_items.push(Item {
@ -338,15 +336,16 @@ impl DataSource for KBDataSource {
), ),
items: final_items items: final_items
})); }));
} return Some((
Some((
blocks, blocks,
Stat { Stat {
win_rate: winrate, win_rate: (data.builds2[0].wins / data.builds2[0].games) * 100.,
games: data.builds2[0].games as u32, games: data.builds2[0].games as u32,
kda: 0.0, kda: 0.0,
}, },
)) ));
}
None
} }
} }