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))
|
if (!stats_update(db))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
unsigned total_duration_s =
|
||||||
|
std::chrono::duration_cast<std::chrono::seconds>(stats.total_duration).count();
|
||||||
|
|
||||||
client_printf(client,
|
client_printf(client,
|
||||||
"artists: %u\n"
|
"artists: %u\n"
|
||||||
"albums: %u\n"
|
"albums: %u\n"
|
||||||
"songs: %u\n"
|
"songs: %u\n"
|
||||||
"db_playtime: %lu\n",
|
"db_playtime: %u\n",
|
||||||
stats.artist_count,
|
stats.artist_count,
|
||||||
stats.album_count,
|
stats.album_count,
|
||||||
stats.song_count,
|
stats.song_count,
|
||||||
stats.total_duration);
|
total_duration_s);
|
||||||
|
|
||||||
const time_t update_stamp = db.GetUpdateStamp();
|
const time_t update_stamp = db.GetUpdateStamp();
|
||||||
if (update_stamp > 0)
|
if (update_stamp > 0)
|
||||||
|
@ -41,7 +41,7 @@ StatsVisitTag(DatabaseStats &stats, StringSet &artists, StringSet &albums,
|
|||||||
const Tag &tag)
|
const Tag &tag)
|
||||||
{
|
{
|
||||||
if (!tag.duration.IsNegative())
|
if (!tag.duration.IsNegative())
|
||||||
stats.total_duration += tag.duration.ToS();
|
stats.total_duration += tag.duration;
|
||||||
|
|
||||||
for (const auto &item : tag) {
|
for (const auto &item : tag) {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
#ifndef MPD_DATABASE_STATS_HXX
|
#ifndef MPD_DATABASE_STATS_HXX
|
||||||
#define MPD_DATABASE_STATS_HXX
|
#define MPD_DATABASE_STATS_HXX
|
||||||
|
|
||||||
|
#include "Chrono.hxx"
|
||||||
|
|
||||||
struct DatabaseStats {
|
struct DatabaseStats {
|
||||||
/**
|
/**
|
||||||
* Number of songs.
|
* Number of songs.
|
||||||
@ -29,7 +31,7 @@ struct DatabaseStats {
|
|||||||
/**
|
/**
|
||||||
* Total duration of all songs (in seconds).
|
* 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.
|
* Number of distinct artist names.
|
||||||
@ -43,7 +45,7 @@ struct DatabaseStats {
|
|||||||
|
|
||||||
void Clear() {
|
void Clear() {
|
||||||
song_count = 0;
|
song_count = 0;
|
||||||
total_duration = 0;
|
total_duration = total_duration.zero();
|
||||||
artist_count = album_count = 0;
|
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);
|
update_stamp = (time_t)mpd_stats_get_db_update_time(stats2);
|
||||||
|
|
||||||
stats.song_count = mpd_stats_get_number_of_songs(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.artist_count = mpd_stats_get_number_of_artists(stats2);
|
||||||
stats.album_count = mpd_stats_get_number_of_albums(stats2);
|
stats.album_count = mpd_stats_get_number_of_albums(stats2);
|
||||||
mpd_stats_free(stats2);
|
mpd_stats_free(stats2);
|
||||||
|
Loading…
Reference in New Issue
Block a user