X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mood.c;h=897c22b9997d21d25f3644cd866706a7152182d9;hp=5d2d38b46637322ad93e802fce150b368cdae2e5;hb=e8ca7526ddebc98f3023736f77fa13b65034767b;hpb=c5e38315901ea63efd169af5d4ba3f3c66db7de9 diff --git a/mood.c b/mood.c index 5d2d38b4..897c22b9 100644 --- a/mood.c +++ b/mood.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2013 Andre Noll + * Copyright (C) 2007-2014 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -18,6 +18,7 @@ #include "ipc.h" #include "mm.h" #include "sideband.h" +#include "mood.h" /** * Contains statistical data of the currently admissible audio files. @@ -386,7 +387,7 @@ static int load_mood(const struct osl_row *mood_row, struct mood **m) if (!*mood_name) return -E_DUMMY_ROW; mlpd.m = alloc_new_mood(mood_name); - ret = for_each_line_ro(mood_def.data, mood_def.size, + ret = for_each_line(FELF_READ_ONLY, mood_def.data, mood_def.size, parse_mood_line, &mlpd); osl_close_disk_object(&mood_def); if (ret < 0) { @@ -418,7 +419,7 @@ static int check_mood(struct osl_row *mood_row, void *data) ret = para_printf(pb, "checking mood %s...\n", mood_name); if (ret < 0) goto out; - ret = for_each_line_ro(mood_def.data, mood_def.size, + ret = for_each_line(FELF_READ_ONLY, mood_def.data, mood_def.size, parse_mood_line, &mlpd); if (ret < 0) para_printf(pb, "%s line %u: %s\n", mood_name, mlpd.line_num, @@ -455,19 +456,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 +463,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 +661,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 +748,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) @@ -865,7 +839,7 @@ int change_current_mood(char *mood_name) if (ret < 0) return ret; log_statistics(); - PARA_INFO_LOG("%d admissible files \n", statistics.num); + PARA_INFO_LOG("%d admissible files\n", statistics.num); for (i = 0; i < statistics.num; i++) { struct admissible_file_info *a = aa.array + i; ret = add_to_score_table(a->aft_row, a->score); @@ -918,6 +892,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)