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

This commit is contained in:
nyyu 2021-03-16 20:23:32 +01:00
parent d1061daf11
commit 245e9c8628

View file

@ -1,10 +1,23 @@
use indexmap::IndexMap;
use serde_json::Value;
use serde_derive::Deserialize;
use serde_json::{json, Value};
use crate::data_source::{DataSource, Stat};
use crate::ChampInfo;
pub struct PBDataSource;
#[derive(Deserialize, Debug)]
struct ChampionResponse {
champions: Vec<Champion>,
}
#[derive(Deserialize, Debug)]
struct Champion {
key: String,
name: String
}
impl DataSource for PBDataSource {
fn init(&self, _client: &ureq::Agent) {}
@ -13,22 +26,60 @@ impl DataSource for PBDataSource {
}
fn get_timeout(&self) -> u64 {
0
300
}
fn get_champs_with_positions(
&self,
_client: &ureq::Agent,
client: &ureq::Agent,
) -> IndexMap<u32, Vec<String>> {
IndexMap::new()
let mut champs = IndexMap::new();
let page = client
.get("https://www.probuilds.net/ajax/championListNew")
.set("Accept", "application/json")
.call().unwrap().into_string().unwrap();
let data: ChampionResponse =
serde_json::from_str(&page).unwrap();
for champ in data.champions {
champs.insert(champ.key.parse::<u32>().unwrap(), vec!["ANY".to_owned()]);
}
champs
}
fn get_champ_data_with_win_pourcentage(
&self,
_champ: &ChampInfo,
_positions: &[String],
_client: &ureq::Agent,
champ: &ChampInfo,
positions: &[String],
client: &ureq::Agent,
) -> Vec<(String, Vec<Value>, Stat)> {
vec![]
let mut builds = vec![];
let page = client
.get(format!("https://www.probuilds.net/ajax/games?limit=1&sort=gameDate-desc&championId={}&olderThan=0&lane=&region=", champ.key).as_str())
.set("Accept", "application/json")
.call().unwrap().into_string().unwrap();
let mut items = vec![];
let mut build = &page[page.find("'items'").unwrap()..];
while build.contains("items") {
let pos = build.find("data-id=").unwrap();
build = &build[pos+10..];
let end = build.find('\\').unwrap();
items.push(&build[..end]);
build = &build[pos+22..];
}
builds.push((positions[0].to_owned(), vec![json!({
"items": items.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
"type": "Set"
})], Stat{win_rate:0.0,games:1,kda:0.0,patch:"".to_string()}));
builds
}
}