mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Remove buggy playlist weighting
This commit is contained in:
parent
324339e00b
commit
3adcc0f10e
1 changed files with 5 additions and 67 deletions
|
|
@ -10,13 +10,7 @@ use adw::{
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use diesel::{
|
use diesel::{dsl::exists, prelude::*, QueryDsl, SqliteConnection};
|
||||||
dsl::{exists, sql},
|
|
||||||
prelude::*,
|
|
||||||
sql_query,
|
|
||||||
sql_types::BigInt,
|
|
||||||
QueryDsl, SqliteConnection,
|
|
||||||
};
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
|
@ -432,59 +426,9 @@ impl MusicusLibrary {
|
||||||
query = query.filter(album_recordings::album_id.eq(album_id));
|
query = query.filter(album_recordings::album_id.eq(album_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if program.prefer_recently_added() > 0.0 {
|
// TODO: Implement weighting.
|
||||||
let oldest_timestamp = sql_query(
|
// if program.prefer_recently_added() > 0.0 {}
|
||||||
"SELECT CAST(STRFTIME('%s', MIN(created_at)) AS INTEGER) AS value FROM recordings",
|
// if program.prefer_least_recently_played() > 0.0 {}
|
||||||
)
|
|
||||||
.get_result::<IntegerValue>(connection)?
|
|
||||||
.value;
|
|
||||||
|
|
||||||
let newest_timestamp = sql_query(
|
|
||||||
"SELECT CAST(STRFTIME('%s', MAX(created_at)) AS INTEGER) AS value FROM recordings",
|
|
||||||
)
|
|
||||||
.get_result::<IntegerValue>(connection)?
|
|
||||||
.value;
|
|
||||||
|
|
||||||
let range = newest_timestamp - oldest_timestamp;
|
|
||||||
|
|
||||||
if range >= 60 {
|
|
||||||
let proportion = program.prefer_recently_added().max(1.0) * 0.9;
|
|
||||||
let cutoff_timestamp =
|
|
||||||
oldest_timestamp + (proportion * range as f64).floor() as i64;
|
|
||||||
|
|
||||||
query = query.filter(
|
|
||||||
sql::<BigInt>("CAST(STRFTIME('%s', recordings.created_at) AS INTEGER)")
|
|
||||||
.ge(cutoff_timestamp)
|
|
||||||
.or(recordings::last_played_at.is_null()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if program.prefer_least_recently_played() > 0.0 {
|
|
||||||
let oldest_timestamp =
|
|
||||||
sql_query("SELECT CAST(STRFTIME('%s', MIN(last_played_at)) AS INTEGER) AS value FROM recordings")
|
|
||||||
.get_result::<IntegerValue>(connection)?
|
|
||||||
.value;
|
|
||||||
|
|
||||||
let newest_timestamp =
|
|
||||||
sql_query("SELECT CAST(STRFTIME('%s', MAX(last_played_at)) AS INTEGER) AS value FROM recordings")
|
|
||||||
.get_result::<IntegerValue>(connection)?
|
|
||||||
.value;
|
|
||||||
|
|
||||||
let range = newest_timestamp - oldest_timestamp;
|
|
||||||
|
|
||||||
if range >= 60 {
|
|
||||||
let proportion = 1.0 - program.prefer_least_recently_played().max(1.0) * 0.9;
|
|
||||||
let cutoff_timestamp =
|
|
||||||
oldest_timestamp + (proportion * range as f64).floor() as i64;
|
|
||||||
|
|
||||||
query = query.filter(
|
|
||||||
sql::<BigInt>("CAST(STRFTIME('%s', recordings.last_played_at) AS INTEGER)")
|
|
||||||
.le(cutoff_timestamp)
|
|
||||||
.or(recordings::last_played_at.is_null()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let row = query
|
let row = query
|
||||||
.order(random())
|
.order(random())
|
||||||
|
|
@ -1315,10 +1259,4 @@ impl LibraryResults {
|
||||||
&& self.recordings.is_empty()
|
&& self.recordings.is_empty()
|
||||||
&& self.albums.is_empty()
|
&& self.albums.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(QueryableByName)]
|
|
||||||
pub struct IntegerValue {
|
|
||||||
#[diesel(sql_type = diesel::sql_types::BigInt)]
|
|
||||||
pub value: i64,
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue