feat: enhancement
All checks were successful
ci/woodpecker/push/linux Pipeline was successful
ci/woodpecker/push/mingw Pipeline was successful

This commit is contained in:
Slany 2023-01-03 11:13:33 +01:00 committed by Gitea
parent 605bead83f
commit ace57d30fc
6 changed files with 31 additions and 40 deletions

View file

@ -1,5 +1,4 @@
use indexmap::IndexMap;
use lazy_static::lazy_static;
use log::error;
use serde_derive::Deserialize;
use serde_json::{json, Value};
@ -52,13 +51,17 @@ struct Build {
games: u32,
}
lazy_static! {
static ref CHAMPIONS_REPORT: Mutex<Vec<ChampionReport>> = Mutex::new(Vec::new());
pub struct CGGDataSource {
champions_report: Mutex<Vec<ChampionReport>>,
}
pub struct CGGDataSource;
impl CGGDataSource {
pub fn new() -> CGGDataSource {
Self {
champions_report: Mutex::new(Vec::new()),
}
}
fn make_item_set(&self, build: &Build, label: &str) -> Value {
json!({
"items": build.build.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
@ -119,7 +122,7 @@ impl DataSource for CGGDataSource {
}
for report in datas.lol.champions_report {
CHAMPIONS_REPORT.lock().unwrap().push(report);
self.champions_report.lock().unwrap().push(report);
}
}
Err(e) => error!("Error retrieving data: {}", e),
@ -136,7 +139,7 @@ impl DataSource for CGGDataSource {
let mut data = vec![];
for position in positions {
let mut some_champ: Option<&ChampionReport> = None;
let reports = CHAMPIONS_REPORT.lock().unwrap();
let reports = self.champions_report.lock().unwrap();
for champion in reports.iter() {
if champion.champion_id.to_string() == champ.key && champion.role == *position {
some_champ = Some(champion);

View file

@ -3,7 +3,6 @@ use crate::ChampInfo;
use crate::Champion as ChampionLoL;
use crate::USER_AGENT_VALUE;
use indexmap::IndexMap;
use lazy_static::lazy_static;
use serde_derive::Deserialize;
use serde_json::{json, Value};
use std::time::Duration;
@ -110,25 +109,22 @@ fn get_auth_token() -> Option<String> {
Some(position) => position,
None => return None,
};
bundle = (&bundle[(auth_position + 13)..]).to_string();
bundle = bundle[(auth_position + 13)..].to_string();
let q_position = match bundle.find('"') {
Some(position) => position,
None => return None,
};
bundle = (&bundle[(q_position + 1)..]).to_string();
bundle = bundle[(q_position + 1)..].to_string();
bundle
.find('"')
.map(|position| (&bundle[..position]).to_string())
.map(|position| bundle[..position].to_string())
}
impl KBDataSource {
pub fn new() -> &'static KBDataSource {
lazy_static! {
static ref DATASOURCE: KBDataSource = KBDataSource {
token: get_auth_token(),
};
pub fn new() -> KBDataSource {
Self {
token: get_auth_token(),
}
&DATASOURCE
}
fn get_champion_response(&self, client: &ureq::Agent) -> Option<ChampionResponse> {

View file

@ -11,6 +11,7 @@ use std::io;
use std::io::Error;
#[cfg(target_os = "windows")]
use std::io::ErrorKind;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::time::Instant;
use std::{fs, thread, time};
@ -101,15 +102,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.into_json()?;
info!("LoL numbers of champs: {}", champion.data.len());
let data_sources: [&'static (dyn DataSource + Sync + Send); 4] = [
&PBDataSource,
&CGGDataSource,
KBDataSource::new(),
&MSDataSource,
let data_sources: Vec<Box<dyn DataSource + Sync + Send>> = vec![
Box::new(PBDataSource),
Box::new(CGGDataSource::new()),
Box::new(KBDataSource::new()),
Box::new(MSDataSource),
];
data_sources.par_iter().for_each(|data_source| {
let init = Instant::now();
execute_data_source(*data_source, &client, &champion, &lol_champs_dir);
execute_data_source(data_source.deref(), &client, &champion, &lol_champs_dir);
info!(
"{}: done in {}s",
data_source.get_alias(),

View file

@ -40,7 +40,7 @@ impl DataSource for MSDataSource {
let k = p + page[p..].find("data-search-terms-like=").unwrap() + 23;
let pipe = k + page[k..].find('|').unwrap() + 1;
let key = &page[pipe..pipe + page[pipe..].find(' ').unwrap()].replace("\"", "");
let key = &page[pipe..pipe + page[pipe..].find(' ').unwrap()].replace('\"', "");
let id = champion.data.get(key).unwrap().key.parse::<u32>().unwrap();
@ -82,10 +82,10 @@ impl DataSource for MSDataSource {
let patch = &page[pos + 6..pos + 11];
pos = page.find("Win Rate:").unwrap();
let win_rate: f32 = (&page[pos + 26..pos + 31]).parse().unwrap();
let win_rate: f32 = page[pos + 26..pos + 31].parse().unwrap();
pos = page.find("KDA:").unwrap();
let kda: f32 = (&page[pos + 21..pos + 25]).parse().unwrap();
let kda: f32 = page[pos + 21..pos + 25].parse().unwrap();
let mut items = vec![];