@@ -6,7 +6,7 @@ use std::io::Write;
6
6
use std:: time:: Duration ;
7
7
use std:: thread:: sleep;
8
8
9
- use crate :: constants:: BOOT_IDS ;
9
+ use crate :: constants:: { BOOT_IDS , REPLACEMENTS } ;
10
10
11
11
const PAST_GAMES : u32 = 20 ;
12
12
const DEFAULT_RETRY_TIME : u64 = 40 ;
@@ -259,10 +259,22 @@ fn prepare_training_data(games: Vec<Value>) -> Array2<f32> {
259
259
// Add one data row for each participant
260
260
for i in 0 ..participants. len ( ) {
261
261
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 ( ) ;
263
269
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 ( ) ;
266
278
267
279
268
280
let enemy_trees: Vec < f32 > = enemies. iter ( )
@@ -278,7 +290,13 @@ fn prepare_training_data(games: Vec<Value>) -> Array2<f32> {
278
290
player_items. push ( from_value :: < f32 > ( player. get ( format ! ( "item{}" , i) ) . unwrap ( ) . clone ( ) ) . unwrap ( ) ) ;
279
291
}
280
292
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 ( ) ;
282
300
283
301
let mut entry: Vec < f32 > = vec ! [
284
302
player_champ,
@@ -373,3 +391,13 @@ fn print_loading_bar(progress: usize, total: usize, duplicates: usize) {
373
391
// Flush the output to make the progress visible without newline
374
392
let _ = std:: io:: stdout ( ) . flush ( ) ;
375
393
}
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