]> git.tue.mpg.de Git - paraslash.git/commitdiff
mood: Deduplicate score formula.
authorAndre Noll <maan@systemlinux.org>
Wed, 4 Sep 2013 20:14:12 +0000 (20:14 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 13 Oct 2013 13:25:06 +0000 (15:25 +0200)
mood.c computes the score of an audio file from its subscores (mood,
last_played, num_played) at two locations, both of which use the same
formula (a + b + c) / 3.

Get rid of this duplication by doing the calculation only once in
compute_dynamic_score(). Rename this function to compute_score() as
it now includes the (static) mood score as well.

mood.c

diff --git a/mood.c b/mood.c
index 2cb7bc699f3688985565142af40762a73ea82311..d15e011f04c720cef376b73752d9fcba51c61f00 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -462,12 +462,13 @@ static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd)
        return 100 * (n * x - sum) / (int64_t)int_sqrt(n * qd);
 }
 
-static long compute_dynamic_score(struct afs_info *afsi)
+static long compute_score(struct afs_info *afsi, long mood_score)
 {
-       return -normalized_value(afsi->num_played, statistics.num,
-                       statistics.num_played_sum, statistics.num_played_qd)
-               - normalized_value(afsi->last_played, statistics.num,
-                       statistics.last_played_sum, statistics.last_played_qd);
+       mood_score -= normalized_value(afsi->num_played, statistics.num,
+               statistics.num_played_sum, statistics.num_played_qd);
+       mood_score -= normalized_value(afsi->last_played, statistics.num,
+               statistics.last_played_sum, statistics.last_played_qd);
+       return mood_score / 3;
 }
 
 static int add_afs_statistics(const struct osl_row *row)
@@ -665,7 +666,7 @@ static int add_to_score_table(const struct osl_row *aft_row, long mood_score)
 
        if (ret < 0)
                return ret;
-       score = (compute_dynamic_score(&afsi) + mood_score) / 3;
+       score = compute_score(&afsi, mood_score);
        return score_add(aft_row, score);
 }
 
@@ -746,8 +747,7 @@ static int mood_update_audio_file(const struct osl_row *aft_row,
                if (ret < 0)
                        return ret;
        }
-       score += compute_dynamic_score(&afsi);
-       score /= 3;
+       score = compute_score(&afsi, score);
        PARA_DEBUG_LOG("score: %li\n", score);
        percent = (score + 100) / 3;
        if (percent > 100)