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

12
Cargo.lock generated
View file

@ -54,7 +54,6 @@ name = "cggitem_sets"
version = "1.0.0"
dependencies = [
"indexmap",
"lazy_static",
"log",
"rayon",
"serde",
@ -65,12 +64,6 @@ dependencies = [
"winreg",
]
[[package]]
name = "chunked_transfer"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cca491388666e04d7248af3f60f0c40cfb0991c72205595d7c396e3510207d1a"
[[package]]
name = "colored"
version = "2.0.0"
@ -511,12 +504,11 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "ureq"
version = "2.5.0"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97acb4c28a254fd7a4aeec976c46a7fa404eac4d7c134b30c75144846d7cb8f"
checksum = "733b5ad78377302af52c0dbcb2623d78fe50e4b3bf215948ff29e9ee031d8566"
dependencies = [
"base64",
"chunked_transfer",
"flate2",
"log",
"once_cell",

View file

@ -7,15 +7,14 @@ version = "1.0.0"
include = ["src/**/*"]
[dependencies]
indexmap = {version = "1.8", features = ["serde-1", "rayon"]}
lazy_static = "1.4"
indexmap = {version = "1.9", features = ["serde-1", "rayon"]}
log = "0.4"
rayon = "1.5"
rayon = "1.6"
serde = "1.0"
serde_derive = "1.0"
serde_json = {version = "1.0", features = ["preserve_order"]}
simple_logger = "4.0"
ureq = {version = "2.4", features = ["json"]}
ureq = {version = "2.6", features = ["json"]}
[target.'cfg(windows)'.dependencies]
winreg = "0.10"

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![];