From 05dcfac6f90b695d4e238f9f15fab1cb5d011967 Mon Sep 17 00:00:00 2001 Message-Id: <05dcfac6f90b695d4e238f9f15fab1cb5d011967.1715641494.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 18 May 2008 23:44:36 +0100 Subject: [PATCH] Bias up recently added tracks. See new_bias and new_bias_age in disorder_config(5) for details. Fixes defect #11. Organization: Straylight/Edgeware From: Richard Kettlewell --- CHANGES | 3 +++ doc/disorder_config.5.in | 9 +++++++++ lib/configuration.c | 4 ++++ lib/configuration.h | 7 +++++++ server/choose.c | 19 ++++++++++++++++--- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 48c33a3..2d6c87d 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,8 @@ This has been completely rewritten to support new features: - there is a new configuration item replay_min defining the minimum time before a played track can be picked at random. The default is 8 hours (which matches the earlier behaviour). + - recently added tracks are biased up; see new_bias and new_bias_age + in disorder_config(5). *** Web Interface @@ -46,6 +48,7 @@ play as well as the local default sound device. #2 Search results should link to directories #10 Non-uniform track selection +#11 Bias random selection to newly added tracks #16 Cookie expiry causes user to be silently logged out and not subsequently redirected to login page #20 Broken aliasing rules diff --git a/doc/disorder_config.5.in b/doc/disorder_config.5.in index a774cc6..5feb325 100644 --- a/doc/disorder_config.5.in +++ b/doc/disorder_config.5.in @@ -487,6 +487,15 @@ namepart artist "/([^/]+)/[^/]+/[^/]+$" $1 * namepart ext "(\\.[a-zA-Z0-9]+)$" $1 * .fi .TP +.B new_bias \fIWEIGHT\fR +The weight for new tracks. +The default is 900000, i.e. recently added tracks are a hundred times as likely +to be picked as normal. +.TP +.B new_bias_age \fISECONDS\fR +The maximum age of tracks that \fBnew_bias\fR applies to, in seconds. +The default is one week. +.TP .B new_max \fIMAX\fR The maximum number of tracks to list when reporting newly noticed tracks. The default is 100. diff --git a/lib/configuration.c b/lib/configuration.c index 670eed9..5c1d4ce 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -946,6 +946,8 @@ static const struct conf conf[] = { { C(multicast_loop), &type_boolean, validate_any }, { C(multicast_ttl), &type_integer, validate_non_negative }, { C(namepart), &type_namepart, validate_any }, + { C(new_bias), &type_integer, validate_positive }, + { C(new_bias_age), &type_integer, validate_positive }, { C(new_max), &type_integer, validate_positive }, { C2(nice, nice_rescan), &type_integer, validate_non_negative }, { C(nice_rescan), &type_integer, validate_non_negative }, @@ -1195,6 +1197,8 @@ static struct config *config_default(void) { c->smtp_server = xstrdup("127.0.0.1"); c->new_max = 100; c->reminder_interval = 600; /* 10m */ + c->new_bias_age = 7 * 86400; /* 1 week */ + c->new_bias = 9000000; /* 100 times the base weight */ /* Default stopwords */ if(config_set(&cs, (int)NDEFAULT_STOPWORDS, (char **)default_stopwords)) exit(1); diff --git a/lib/configuration.h b/lib/configuration.h index 4b22fdb..bf3a493 100644 --- a/lib/configuration.h +++ b/lib/configuration.h @@ -1,3 +1,4 @@ + /* * This file is part of DisOrder. * Copyright (C) 2004-2008 Richard Kettlewell @@ -285,6 +286,12 @@ struct config { /** @brief Whether to allow user management over TCP */ int remote_userman; + + /** @brief Maximum age of biased-up tracks */ + long new_bias_age; + + /** @brief Maximum bias */ + long new_bias; /* derived values: */ int nparts; /* number of distinct name parts */ diff --git a/server/choose.c b/server/choose.c index b725ea4..dbb962c 100644 --- a/server/choose.c +++ b/server/choose.c @@ -57,6 +57,8 @@ #include "queue.h" #include "server-queue.h" +#define BASE_WEIGHT 90000 + static DB_TXN *global_tid; static const struct option options[] = { @@ -121,7 +123,7 @@ static unsigned long compute_weight(const char *track, struct kvp *prefs) { const char *s; char **track_tags; - time_t last, now; + time_t last, now = time(0); /* Reject tracks not in any collection (race between edit config and * rescan) */ @@ -142,7 +144,6 @@ static unsigned long compute_weight(const char *track, /* Reject tracks played within the last 8 hours */ if((s = kvp_get(prefs, "played_time"))) { last = atoll(s); - now = time(0); if(now < last + config->replay_min) return 0; } @@ -172,8 +173,20 @@ static unsigned long compute_weight(const char *track, if((errno == 0 || errno == ERANGE) && n >= 0) return n; } + + /* Bias up tracks that were recently added */ + if((s = kvp_get(data, "_noticed"))) { + const time_t noticed = atoll(s); + + if(noticed + config->new_bias_age < now) + /* Currently we just step up the weight of tracks that are in range. A + * more sophisticated approach would be to linearly decay from new_bias + * down to BASE_WEIGHT over the course of the new_bias_age interval + * starting when the track is added. */ + return config->new_bias; + } - return 90000; + return BASE_WEIGHT; } static unsigned char random_buffer[4096]; -- [mdw]