core/tags/track: Find the average play count of tracks
This function returns the average count of tracks that have been played, and not the average count of all tracks. Implements #29: Efficiently calculate average play count of tracks Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
1973d15605
commit
4998b0867b
|
@ -205,6 +205,13 @@ unsigned int track_db_count_plays()
|
|||
return play_count;
|
||||
}
|
||||
|
||||
unsigned int track_db_average_plays()
|
||||
{
|
||||
if (unplayed_count == track_db.db_size)
|
||||
return 0;
|
||||
return play_count / (track_db.db_size - unplayed_count);
|
||||
}
|
||||
|
||||
struct track *track_add(struct library *library, const gchar *filepath)
|
||||
{
|
||||
unsigned int offset = strlen(library->li_path) + 1;
|
||||
|
|
|
@ -80,6 +80,9 @@ unsigned int track_db_count_unplayed();
|
|||
/* Called to find the total play count of all tracks in the database. */
|
||||
unsigned int track_db_count_plays();
|
||||
|
||||
/* Called to find the average play count of tracks in the database. */
|
||||
unsigned int track_db_average_plays();
|
||||
|
||||
/* Called to add a track tag to the database. */
|
||||
struct track *track_add(struct library *, const gchar *);
|
||||
|
||||
|
|
|
@ -232,6 +232,7 @@ static void test_track_db()
|
|||
|
||||
test_equal(track_db_count_unplayed(), 0);
|
||||
test_equal(track_db_count_plays(), 0);
|
||||
test_equal(track_db_average_plays(), 0);
|
||||
track = track_add(library, path);
|
||||
test_verify_track(track);
|
||||
test_equal(track_db_count_unplayed(), 1);
|
||||
|
@ -267,12 +268,15 @@ static void test_track_db()
|
|||
test_equal(track_db_count_unplayed(), 2);
|
||||
|
||||
test_equal(track_db_count_plays(), 0);
|
||||
test_equal(track_db_average_plays(), 0);
|
||||
track_played(track);
|
||||
test_equal(track_db_count_unplayed(), 1);
|
||||
test_equal(track_db_count_plays(), 1);
|
||||
test_equal(track_db_average_plays(), 1);
|
||||
track_played(track);
|
||||
test_equal(track_db_count_unplayed(), 1);
|
||||
test_equal(track_db_count_plays(), 2);
|
||||
test_equal(track_db_average_plays(), 2);
|
||||
|
||||
track = track_add(library, "tests/Music/invalid_track");
|
||||
test_equal((void *)track, NULL);
|
||||
|
@ -289,9 +293,11 @@ static void test_track_db()
|
|||
test_equal(track_db_get()->db_size, 2);
|
||||
test_equal(track_db_count_unplayed(), 1);
|
||||
test_equal(track_db_count_plays(), 2);
|
||||
test_equal(track_db_average_plays(), 2);
|
||||
|
||||
track_remove(track_get(2));
|
||||
test_equal(track_db_count_plays(), 0);
|
||||
test_equal(track_db_average_plays(), 0);
|
||||
|
||||
track_remove_all(library);
|
||||
test_equal(track_db_get()->db_size, 0);
|
||||
|
|
|
@ -70,6 +70,7 @@ static void test_treeview()
|
|||
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||
gui_settings_init();
|
||||
gui_view_init();
|
||||
while (idle_run_task()) {}
|
||||
|
||||
collection_add("tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task() == true) {}
|
||||
|
|
Loading…
Reference in New Issue