add empty datasource
This commit is contained in:
parent
176982b750
commit
77b6b62300
4 changed files with 51 additions and 9 deletions
|
@ -70,7 +70,7 @@ impl DataSource for CGGDataSource {
|
||||||
(champions, patch)
|
(champions, patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option<Value> {
|
fn get_champ_data(&self, id: &str, position: &str, client: &reqwest::Client) -> Option<Value> {
|
||||||
let mut req = client
|
let mut req = client
|
||||||
.get(&format!(
|
.get(&format!(
|
||||||
"https://champion.gg/champion/{}/{}?league=",
|
"https://champion.gg/champion/{}/{}?league=",
|
||||||
|
|
|
@ -43,16 +43,22 @@ pub trait DataSource {
|
||||||
&self,
|
&self,
|
||||||
client: &reqwest::Client,
|
client: &reqwest::Client,
|
||||||
) -> (IndexMap<String, Vec<String>>, String);
|
) -> (IndexMap<String, Vec<String>>, String);
|
||||||
fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option<Value>;
|
fn get_champ_data(&self, id: &str, position: &str, client: &reqwest::Client) -> Option<Value>;
|
||||||
|
|
||||||
fn make_item_set(data: &Value, label: &str) -> Value {
|
fn make_item_set(&self, data: &Value, label: &str) -> Value {
|
||||||
json!({
|
json!({
|
||||||
"items": data["items"].as_array().unwrap().iter().map(|x| json!({"id": x["id"].as_str(), "count": 1})).collect::<Vec<Value>>(),
|
"items": data["items"].as_array().unwrap().iter().map(|x| json!({"id": x["id"].as_str(), "count": 1})).collect::<Vec<Value>>(),
|
||||||
"type": format!("{} ({:.2}% - {} games)", label, data["winPercent"].as_f64().unwrap() * 100., data["games"].as_u64().unwrap())
|
"type": format!("{} ({:.2}% - {} games)", label, data["winPercent"].as_f64().unwrap() * 100., data["games"].as_u64().unwrap())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_item_set_from_list(list: &Vec<u32>, label: &str, key: &str, data: &Value) -> Value {
|
fn make_item_set_from_list(
|
||||||
|
&self,
|
||||||
|
list: &Vec<u32>,
|
||||||
|
label: &str,
|
||||||
|
key: &str,
|
||||||
|
data: &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_none() {
|
||||||
key_order = data["skills"][key]["order"]
|
key_order = data["skills"][key]["order"]
|
||||||
|
@ -83,7 +89,7 @@ pub trait DataSource {
|
||||||
client: &reqwest::Client,
|
client: &reqwest::Client,
|
||||||
) {
|
) {
|
||||||
info!("Retrieving data for {} at {}", name, pos);
|
info!("Retrieving data for {} at {}", name, pos);
|
||||||
let data = Self::get_champ_data(id, pos, client);
|
let data = self.get_champ_data(id, pos, client);
|
||||||
|
|
||||||
match data {
|
match data {
|
||||||
Some(data) => {
|
Some(data) => {
|
||||||
|
@ -106,17 +112,17 @@ pub trait DataSource {
|
||||||
if !data[&path[0]].get(&path[1]).is_none() {
|
if !data[&path[0]].get(&path[1]).is_none() {
|
||||||
item_set
|
item_set
|
||||||
.blocks
|
.blocks
|
||||||
.push(Self::make_item_set(&data[&path[0]][&path[1]], label));
|
.push(self.make_item_set(&data[&path[0]][&path[1]], label));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item_set.blocks.push(Self::make_item_set_from_list(
|
item_set.blocks.push(self.make_item_set_from_list(
|
||||||
&CONSUMABLES.to_vec(),
|
&CONSUMABLES.to_vec(),
|
||||||
"Consumables | Frequent:",
|
"Consumables | Frequent:",
|
||||||
"mostGames",
|
"mostGames",
|
||||||
&data,
|
&data,
|
||||||
));
|
));
|
||||||
item_set.blocks.push(Self::make_item_set_from_list(
|
item_set.blocks.push(self.make_item_set_from_list(
|
||||||
&TRINKETS.to_vec(),
|
&TRINKETS.to_vec(),
|
||||||
"Trinkets | Wins:",
|
"Trinkets | Wins:",
|
||||||
"highestWinPercent",
|
"highestWinPercent",
|
||||||
|
|
|
@ -16,10 +16,12 @@ extern crate winreg;
|
||||||
|
|
||||||
mod cgg_data_source;
|
mod cgg_data_source;
|
||||||
mod data_source;
|
mod data_source;
|
||||||
|
mod pb_data_source;
|
||||||
|
|
||||||
use cgg_data_source::CGGDataSource;
|
use cgg_data_source::CGGDataSource;
|
||||||
use data_source::DataSource;
|
use data_source::DataSource;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
use pb_data_source::PBDataSource;
|
||||||
use reqwest::header::{Headers, UserAgent};
|
use reqwest::header::{Headers, UserAgent};
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -85,7 +87,7 @@ fn main() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
info!("LoL numbers of champs: {}", champion.data.len());
|
info!("LoL numbers of champs: {}", champion.data.len());
|
||||||
|
|
||||||
let data_sources = [CGGDataSource];
|
let data_sources: [Box<DataSource>; 2] = [Box::new(PBDataSource), Box::new(CGGDataSource)];
|
||||||
|
|
||||||
for data_source in data_sources.iter() {
|
for data_source in data_sources.iter() {
|
||||||
let (champs, patch) = data_source.get_champs_with_positions_and_patch(&client);
|
let (champs, patch) = data_source.get_champs_with_positions_and_patch(&client);
|
||||||
|
|
34
src/pb_data_source.rs
Normal file
34
src/pb_data_source.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
extern crate indexmap;
|
||||||
|
extern crate lazy_static;
|
||||||
|
extern crate log;
|
||||||
|
extern crate regex;
|
||||||
|
extern crate reqwest;
|
||||||
|
extern crate select;
|
||||||
|
extern crate serde;
|
||||||
|
extern crate serde_json;
|
||||||
|
extern crate simple_logger;
|
||||||
|
extern crate winreg;
|
||||||
|
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use data_source::DataSource;
|
||||||
|
|
||||||
|
pub struct PBDataSource;
|
||||||
|
impl DataSource for PBDataSource {
|
||||||
|
fn get_champs_with_positions_and_patch(
|
||||||
|
&self,
|
||||||
|
_client: &reqwest::Client,
|
||||||
|
) -> (IndexMap<String, Vec<String>>, String) {
|
||||||
|
(IndexMap::new(), String::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_champ_data(
|
||||||
|
&self,
|
||||||
|
_id: &str,
|
||||||
|
_position: &str,
|
||||||
|
_client: &reqwest::Client,
|
||||||
|
) -> Option<Value> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue