chiark / gitweb /
Bias up recently added tracks. See new_bias and new_bias_age in
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 May 2008 22:44:36 +0000 (23:44 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 May 2008 22:44:36 +0000 (23:44 +0100)
disorder_config(5) for details.  Fixes defect #11.

CHANGES
doc/disorder_config.5.in
lib/configuration.c
lib/configuration.h
server/choose.c

diff --git a/CHANGES b/CHANGES
index 48c33a363822d120ad957d4c7cd03745dc460c54..2d6c87dcc9d3207e0b7c57df7f1e386fc4904d4e 100644 (file)
--- 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
index a774cc65a80a6a6f983e5ea39db22c9aa2a2242a..5feb325283a2900d8a7a8b9e73873de4ced462e0 100644 (file)
@@ -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.
index 670eed9b8c914f322064863c93c349564cbf358e..5c1d4cef429720f80472dc07bf944929fda9d9f0 100644 (file)
@@ -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);
index 4b22fdbdf1d002985a0af913e3d615c00f41a4e6..bf3a493b394922d0f96fa9299d344a0ee6dbceef 100644 (file)
@@ -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 */
index b725ea46330c64201470f3edc3e71fd003941491..dbb962c1ee8a80633d2554c341142438bfaff277 100644 (file)
@@ -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];