db/Stats: use std::chrono::duration for the total duration
Use milliseconds precision to reduce rounding errors.
This commit is contained in:
parent
de64b35359
commit
58352ea69d
|
@ -99,15 +99,18 @@ db_stats_print(Client &client, const Database &db)
|
|||
if (!stats_update(db))
|
||||
return;
|
||||
|
||||
unsigned total_duration_s =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(stats.total_duration).count();
|
||||
|
||||
client_printf(client,
|
||||
"artists: %u\n"
|
||||
"albums: %u\n"
|
||||
"songs: %u\n"
|
||||
"db_playtime: %lu\n",
|
||||
"db_playtime: %u\n",
|
||||
stats.artist_count,
|
||||
stats.album_count,
|
||||
stats.song_count,
|
||||
stats.total_duration);
|
||||
total_duration_s);
|
||||
|
||||
const time_t update_stamp = db.GetUpdateStamp();
|
||||
if (update_stamp > 0)
|
||||
|
|
|
@ -41,7 +41,7 @@ StatsVisitTag(DatabaseStats &stats, StringSet &artists, StringSet &albums,
|
|||
const Tag &tag)
|
||||
{
|
||||
if (!tag.duration.IsNegative())
|
||||
stats.total_duration += tag.duration.ToS();
|
||||
stats.total_duration += tag.duration;
|
||||
|
||||
for (const auto &item : tag) {
|
||||
switch (item.type) {
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#ifndef MPD_DATABASE_STATS_HXX
|
||||
#define MPD_DATABASE_STATS_HXX
|
||||
|
||||
#include "Chrono.hxx"
|
||||
|
||||
struct DatabaseStats {
|
||||
/**
|
||||
* Number of songs.
|
||||
|
@ -29,7 +31,7 @@ struct DatabaseStats {
|
|||
/**
|
||||
* Total duration of all songs (in seconds).
|
||||
*/
|
||||
unsigned long total_duration;
|
||||
std::chrono::duration<std::uint64_t, SongTime::period> total_duration;
|
||||
|
||||
/**
|
||||
* Number of distinct artist names.
|
||||
|
@ -43,7 +45,7 @@ struct DatabaseStats {
|
|||
|
||||
void Clear() {
|
||||
song_count = 0;
|
||||
total_duration = 0;
|
||||
total_duration = total_duration.zero();
|
||||
artist_count = album_count = 0;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -807,7 +807,7 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection,
|
|||
update_stamp = (time_t)mpd_stats_get_db_update_time(stats2);
|
||||
|
||||
stats.song_count = mpd_stats_get_number_of_songs(stats2);
|
||||
stats.total_duration = mpd_stats_get_db_play_time(stats2);
|
||||
stats.total_duration = std::chrono::seconds(mpd_stats_get_db_play_time(stats2));
|
||||
stats.artist_count = mpd_stats_get_number_of_artists(stats2);
|
||||
stats.album_count = mpd_stats_get_number_of_albums(stats2);
|
||||
mpd_stats_free(stats2);
|
||||
|
|
Loading…
Reference in New Issue