Skip to content

Commit bdf67cf

Browse files
committed
fixes image path param not considered by db
1 parent bbc6599 commit bdf67cf

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

image_collection/src/lib.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct Match {
5959
}
6060

6161
impl 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);

server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async fn main() -> Result<()> {
8989
db_path: args.output,
9090
candidate_buffer: args.queue_buffer,
9191
};
92-
let img_col = ImageCollection::new(&options).await?;
92+
let img_col = ImageCollection::new(&options, &args.image_dir).await?;
9393

9494
let addr = format!("0.0.0.0:{}", args.port);
9595
let image_dir = args.image_dir;

0 commit comments

Comments
 (0)