From: Andre Noll Date: Sun, 1 Dec 2013 00:14:37 +0000 (+0100) Subject: Merge branch 't/mood_cleanups' X-Git-Tag: v0.5.1~6 X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;h=3055dabe9c91c9dfaa517ebbb65a9aae5946d018;hp=a29e6451e79365af6dce8d14f3056fc107b059fb;p=paraslash.git Merge branch 't/mood_cleanups' Cooking since 2011-10-13, seems to be fine. 6bcd10 mood: Deduplicate score formula. f24778 mood: Combine compute_num_played_score() and compute_last_played_score(). 62a968 mood: Don't open-code compute_dynamic_score(). 2c85cd mood: Don't add files without valid information to the score table. 5e9ded mood: Simplify compute_dynamic_score(). ab9f71 mood.c: Remove unused int_log2(). --- diff --git a/NEWS b/NEWS index fc6ccffb..980f613a 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ NEWS - audiod improvements and fixes. - buffer tree robustness improvements. + - cleanup of the mood subsystem. ---------------------------------------- 0.5.0 (2013-08-23) "invertible validity" diff --git a/mood.c b/mood.c index e5e84953..d15e011f 100644 --- a/mood.c +++ b/mood.c @@ -455,19 +455,6 @@ void mood_check_callback(int fd, __a_unused const struct osl_object *query) free(pb.buf); } -#if 0 -static unsigned int_log2(uint64_t x) -{ - unsigned res = 0; - - while (x) { - x /= 2; - res++; - } - return res; -} -#endif - static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd) { if (!n || !qd) @@ -475,31 +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_num_played_score(struct afs_info *afsi) +static long compute_score(struct afs_info *afsi, long mood_score) { - return -normalized_value(afsi->num_played, statistics.num, + mood_score -= normalized_value(afsi->num_played, statistics.num, statistics.num_played_sum, statistics.num_played_qd); -} - -static long compute_last_played_score(struct afs_info *afsi) -{ - return -normalized_value(afsi->last_played, statistics.num, + mood_score -= normalized_value(afsi->last_played, statistics.num, statistics.last_played_sum, statistics.last_played_qd); -} - -static long compute_dynamic_score(const struct osl_row *aft_row) -{ - struct afs_info afsi; - int64_t score, nscore = 0, lscore = 0; - int ret; - - ret = get_afsi_of_row(aft_row, &afsi); - if (ret < 0) - return -100; - nscore = compute_num_played_score(&afsi); - lscore = compute_last_played_score(&afsi); - score = nscore + lscore; - return score; + return mood_score / 3; } static int add_afs_statistics(const struct osl_row *row) @@ -691,7 +660,13 @@ static int update_afs_statistics(struct afs_info *old_afsi, struct afs_info *new static int add_to_score_table(const struct osl_row *aft_row, long mood_score) { - long score = (compute_dynamic_score(aft_row) + mood_score) / 3; + long score; + struct afs_info afsi; + int ret = get_afsi_of_row(aft_row, &afsi); + + if (ret < 0) + return ret; + score = compute_score(&afsi, mood_score); return score_add(aft_row, score); } @@ -772,9 +747,7 @@ static int mood_update_audio_file(const struct osl_row *aft_row, if (ret < 0) return ret; } - score += compute_num_played_score(&afsi); - score += compute_last_played_score(&afsi); - score /= 3; + score = compute_score(&afsi, score); PARA_DEBUG_LOG("score: %li\n", score); percent = (score + 100) / 3; if (percent > 100)