Add games and kda to title item set
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nyyu 2021-03-14 14:25:37 +01:00
parent d02a3c6a1d
commit 3212938a2a
4 changed files with 33 additions and 14 deletions

View file

@ -6,7 +6,7 @@ use serde_json::{json, Value};
use std::collections::HashMap;
use std::sync::Mutex;
use crate::data_source::DataSource;
use crate::data_source::{DataSource, Stat};
use crate::ChampInfo;
#[derive(Deserialize, Debug)]
@ -132,14 +132,13 @@ impl DataSource for CGGDataSource {
let mut champions: IndexMap<String, Vec<String>> = IndexMap::new();
for champ in &datas.lol.champions_report {
let id = champ.champion_id.to_string();
if champions.contains_key(&id) {
let mut roles = champions.get(&id).unwrap().clone();
roles.push(champ.role.clone());
champions.insert(id, roles);
} else {
champions.insert(id, [champ.role.clone()].to_vec());
}
champions.insert(id, vec![champ.role.clone()]);
}
}
for report in datas.lol.champions_report {
@ -154,7 +153,7 @@ impl DataSource for CGGDataSource {
champ: &ChampInfo,
position: &str,
_client: &ureq::Agent,
) -> Option<(Vec<Value>, f64)> {
) -> Option<(Vec<Value>, Stat)> {
let mut some_champ: Option<&ChampionReport> = None;
let reports = CHAMPIONS_REPORT.lock().unwrap();
for champion in reports.iter() {
@ -197,9 +196,16 @@ impl DataSource for CGGDataSource {
key = val.stats.as_ref().unwrap().id.clone();
}
}
let win_rate = champs_stats.get(&key).unwrap().win_rate;
return Some((blocks, win_rate.unwrap()));
let stat = champs_stats.get(&key).unwrap();
return Some((
blocks,
Stat {
win_rate: stat.win_rate.unwrap(),
games: stat.games.unwrap(),
kda: stat.kda.unwrap(),
},
));
}
None
}

View file

@ -31,6 +31,12 @@ pub struct Item {
pub count: u8,
}
pub struct Stat {
pub win_rate: f64,
pub games: u32,
pub kda: f64,
}
pub trait DataSource {
fn get_alias(&self) -> &str;
@ -46,7 +52,7 @@ pub trait DataSource {
champ: &ChampInfo,
position: &str,
client: &ureq::Agent,
) -> Option<(Vec<Value>, f64)>;
) -> Option<(Vec<Value>, Stat)>;
fn write_item_set(
&self,
@ -62,7 +68,7 @@ pub trait DataSource {
match data {
Some(data) => {
let item_set = ItemSet {
title: format!("{} {} {} - {:.2}%", self.get_alias(), pos, ver, data.1),
title: format!("{} {} {} - {:.2}% wins - {} games - {:.2} kda", self.get_alias(), pos, ver, data.1.win_rate, data.1.games, data.1.kda),
type_: "custom".to_string(),
map: "any".to_string(),
mode: "any".to_string(),

View file

@ -1,4 +1,4 @@
use crate::data_source::{Build, DataSource, Item};
use crate::data_source::{Build, DataSource, Item, Stat};
#[cfg(test)]
use crate::time::Duration;
use crate::ChampInfo;
@ -211,7 +211,7 @@ impl DataSource for KBDataSource {
champ: &ChampInfo,
position: &str,
client: &ureq::Agent,
) -> Option<(Vec<Value>, f64)> {
) -> Option<(Vec<Value>, Stat)> {
let token = match self.token.clone() {
Some(t) => t,
None => return None,
@ -338,7 +338,14 @@ impl DataSource for KBDataSource {
items: final_items
}));
}
Some((blocks, winrate))
Some((
blocks,
Stat {
win_rate: winrate,
games: data.builds2[0].games as u32,
kda: 0.0,
},
))
}
}

View file

@ -1,7 +1,7 @@
use indexmap::IndexMap;
use serde_json::Value;
use crate::data_source::DataSource;
use crate::data_source::{DataSource, Stat};
use crate::ChampInfo;
pub struct PBDataSource;
@ -26,7 +26,7 @@ impl DataSource for PBDataSource {
_champ: &ChampInfo,
_position: &str,
_client: &ureq::Agent,
) -> Option<(Vec<Value>, f64)> {
) -> Option<(Vec<Value>, Stat)> {
None
}
}