X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=mood.c;h=2cb7bc699f3688985565142af40762a73ea82311;hb=f24778705c853647f48b89c8d27ba1ded27a6f29;hp=e06382e85cf2831ce638b27d0e5b057f759faac2;hpb=1775d4d4147730e79e48aa941aee88580b8beb08;p=paraslash.git diff --git a/mood.c b/mood.c index e06382e8..2cb7bc69 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,12 @@ 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_dynamic_score(struct afs_info *afsi) { return -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, - 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; + statistics.num_played_sum, statistics.num_played_qd) + - normalized_value(afsi->last_played, statistics.num, + statistics.last_played_sum, statistics.last_played_qd); } static int add_afs_statistics(const struct osl_row *row) @@ -691,7 +659,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_dynamic_score(&afsi) + mood_score) / 3; return score_add(aft_row, score); } @@ -772,8 +746,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 += compute_dynamic_score(&afsi); score /= 3; PARA_DEBUG_LOG("score: %li\n", score); percent = (score + 100) / 3; @@ -918,6 +891,8 @@ static int reload_current_mood(void) * This function performs actions required due to the occurrence of the given * event. Possible actions include reload of the current mood and update of the * score of an audio file. + * + * \return Standard. */ int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb, void *data)