@@ -59,7 +59,7 @@ pub struct Match {
5959}
6060
6161impl ImageCollection {
62- pub async fn new ( options : & ImageCollectionOptions ) -> Result < ImageCollection > {
62+ pub async fn new ( options : & ImageCollectionOptions , image_dir : & String ) -> Result < ImageCollection > {
6363 let db_opions = sqlx:: sqlite:: SqliteConnectOptions :: from_str ( & options. db_path ) ?
6464 . shared_cache ( false )
6565 . synchronous ( sqlx:: sqlite:: SqliteSynchronous :: Normal )
@@ -73,7 +73,7 @@ impl ImageCollection {
7373 . connect_with ( db_opions)
7474 . await ?;
7575 sqlx:: query_file!( "./schema.sql" ) . execute ( & db) . await ?;
76- check_db_integrity ( & db) . await ?;
76+ check_db_integrity ( & db, & image_dir ) . await ?;
7777 let candidates = std:: sync:: Arc :: new ( ArrayQueue :: < Duel > :: new ( options. candidate_buffer ) ) ;
7878 let new_duels = calculate_new_matches ( & db, candidates. capacity ( ) ) . await ?;
7979 for nd in new_duels. into_iter ( ) {
@@ -124,14 +124,6 @@ impl ImageCollection {
124124 for p in players. iter ( ) {
125125 println ! { "{},{},{}" , & p. name, & p. rating, & p. deviation} ;
126126 }
127- //let mut sqre: f32 = 0.;
128- //for i in 0..players.len() {
129- // sqre += (players[i].name.parse::<f32>().unwrap() - i as f32)
130- // * (players[i].name.parse::<f32>().unwrap() - i as f32);
131- //}
132- //sqre /= players.len() as f32;
133- //sqre = sqre.sqrt();
134- //println!("MSRE: {}", sqre);
135127
136128 Ok ( ( ) )
137129 }
@@ -248,8 +240,7 @@ impl ImageCollection {
248240 }
249241}
250242
251- async fn check_db_integrity ( db : & SqlitePool ) -> Result < ( ) > {
252- let path = "images" ;
243+ async fn check_db_integrity ( db : & SqlitePool , image_dir : & String ) -> Result < ( ) > {
253244 let db_files = sqlx:: query!( "SELECT name FROM players" )
254245 . fetch_all ( db)
255246 . await ?;
@@ -260,7 +251,7 @@ async fn check_db_integrity(db: &SqlitePool) -> Result<()> {
260251
261252 // check if all files in db exists in fs
262253 for file in & db_files {
263- let file_path = format ! ( "{}/{}" , path , file) ;
254+ let file_path = format ! ( "{}/{}" , image_dir , file) ;
264255 if !std:: path:: Path :: new ( & file_path) . is_file ( ) {
265256 info ! ( "Image path \" {}\" does not exists in " , file) ;
266257 sqlx:: query!( "DELETE FROM players WHERE name = ?" , file)
@@ -269,7 +260,7 @@ async fn check_db_integrity(db: &SqlitePool) -> Result<()> {
269260 }
270261 }
271262
272- for entry in std:: fs:: read_dir ( path ) ? {
263+ for entry in std:: fs:: read_dir ( image_dir ) ? {
273264 if let Some ( file) = entry?. file_name ( ) . to_str ( ) {
274265 if !db_files. contains ( file) {
275266 info ! ( "Add \" {}\" to database." , file) ;
0 commit comments