Skip to content

Commit 8fa743f

Browse files
committed
update for new Boot Types
1 parent 81fb205 commit 8fa743f

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

src/constants.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub const BOOT_IDS: [(f32, &str); 8] = [
2-
(1001., "Boots"),
2+
(1001., "Boots"), // Placeholder for no T2 boots, also result for Cassiopeia
33
(3006., "Berserker's Greaves"),
44
(3009., "Boots of Swiftness"),
55
(3020., "Sorcerer's Shoes"),
@@ -8,4 +8,8 @@ pub const BOOT_IDS: [(f32, &str); 8] = [
88
(3117., "Mobility Boots"),
99
(3158., "Ionian Boots of Lucidity"),
1010
];
11-
pub const MAPPING_FILE: &str = "snowflake_puuid.txt";
11+
pub const MAPPING_FILE: &str = "snowflake_puuid.txt";
12+
13+
pub const REPLACEMENTS: [(f32, f32); 1] = [
14+
(3172., 3006.), // Treat every Zephyr as Berserker's Greaves
15+
];

src/prediction.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use self::data::get_current_match_data;
1212
pub mod data;
1313

1414
const MODEL_FILE_NAME: &str = "model.bin";
15-
const GOETHE: &str = "qan7meW9JWz1XI1nmZ8yD000EXpxLGkSbirRVPaRjCwcr9WeIcg32KQOTtJV71OEyov3LwCnRq5o5Q";
15+
const GOETHE: &str = "C07uW6f7a9Gkj5nMkqsT-idkHGwc76DaX-fLAryZZOksdXob2bY5NDtG3j6SD7YsS3-N8x6X25z2JQ";
1616

1717
fn predict_one(model: &DecisionTree<f32, String>, data: &Array1<f32>) -> String {
1818
let data_boxed: Array2<f32> = data.clone().into_shape((1, 13)).unwrap();
@@ -41,7 +41,16 @@ fn create_dataset(data: &Array2<f32>) -> DatasetBase<ArrayBase<OwnedRepr<f32>, D
4141

4242
// create actual dataset (maps ids to String representation)
4343
let dataset = Dataset::new(features, labels)
44-
.map_targets(|x| crate::constants::BOOT_IDS.iter().filter(|b| &b.0 == x).nth(0).map(|x| x.1).unwrap_or("No Boots").to_string())
44+
.map_targets(
45+
|x|
46+
crate::constants::BOOT_IDS
47+
.iter()
48+
.filter(|b| &b.0 == x)
49+
.nth(0)
50+
.map(|x| x.1)
51+
.unwrap_or("No Boots")
52+
.to_string()
53+
)
4554
.with_feature_names(feature_names);
4655

4756
dataset
@@ -92,7 +101,7 @@ pub fn recreate_model(game_count: usize) {
92101
.expect("Could not fetch the Riot token");
93102
let base_path = env::var("CONFIG_PATH").unwrap_or(String::new());
94103
let snowflake_map = create_snowflake_puuid_map(&format!("{}{}", base_path, crate::constants::MAPPING_FILE));
95-
let test_puuid = snowflake_map.values().filter(|id| id.starts_with("f7Xz")).nth(0).unwrap().clone();
104+
let test_puuid = snowflake_map.values().filter(|id| id.starts_with("UtnLP")).nth(0).unwrap().clone();
96105

97106
// Train a new model
98107
let start_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();

src/prediction/data.rs

+33-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io::Write;
66
use std::time::Duration;
77
use std::thread::sleep;
88

9-
use crate::constants::BOOT_IDS;
9+
use crate::constants::{BOOT_IDS, REPLACEMENTS};
1010

1111
const PAST_GAMES: u32 = 20;
1212
const DEFAULT_RETRY_TIME: u64 = 40;
@@ -259,10 +259,22 @@ fn prepare_training_data(games: Vec<Value>) -> Array2<f32> {
259259
// Add one data row for each participant
260260
for i in 0..participants.len() {
261261
let player: &Value = &participants[i];
262-
let enemies: Vec<&Value> = participants.iter().filter(|p| p.get("teamId").unwrap() != player.get("teamId").unwrap()).collect();
262+
let enemies: Vec<&Value> = participants
263+
.iter()
264+
.filter(
265+
|p|
266+
p.get("teamId").unwrap() != player.get("teamId").unwrap()
267+
)
268+
.collect();
263269

264-
let enemy_champs: Vec<f32> = enemies.iter()
265-
.map(|e| from_value::<f32>(e.get("championId").unwrap().clone()).unwrap()).collect();
270+
let enemy_champs: Vec<f32> = enemies
271+
.iter()
272+
.map(
273+
|e| from_value::<f32>(
274+
e.get("championId").unwrap().clone()
275+
).unwrap()
276+
)
277+
.collect();
266278

267279

268280
let enemy_trees: Vec<f32> = enemies.iter()
@@ -278,7 +290,13 @@ fn prepare_training_data(games: Vec<Value>) -> Array2<f32> {
278290
player_items.push(from_value::<f32>(player.get(format!("item{}", i)).unwrap().clone()).unwrap());
279291
}
280292
let boot_ids: Vec<f32> = BOOT_IDS.iter().map(|i| i.0).collect();
281-
let player_boots: f32 = player_items.iter().filter(|item| boot_ids.contains(item)).nth(0).unwrap_or(&1001.).clone();
293+
let player_boots: f32 = player_items
294+
.iter()
295+
.map(preprocess)
296+
.filter(|item| boot_ids.contains(item))
297+
.nth(0)
298+
.unwrap_or(&1001.)
299+
.clone();
282300

283301
let mut entry: Vec<f32> = vec![
284302
player_champ,
@@ -373,3 +391,13 @@ fn print_loading_bar(progress: usize, total: usize, duplicates: usize) {
373391
// Flush the output to make the progress visible without newline
374392
let _ = std::io::stdout().flush();
375393
}
394+
395+
fn preprocess(item: &f32) -> &f32 {
396+
// Currently only one step: replace any specified items
397+
let replacements: Vec<&(f32, f32)> = REPLACEMENTS.iter().collect();
398+
replacements
399+
.iter()
400+
.find(|r| &r.0 == item)
401+
.map(|r| &r.1)
402+
.unwrap_or(item)
403+
}

0 commit comments

Comments
 (0)