Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
58352ea6
Commit
58352ea6
authored
Aug 29, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/Stats: use std::chrono::duration for the total duration
Use milliseconds precision to reduce rounding errors.
parent
de64b353
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
6 deletions
+11
-6
Stats.cxx
src/Stats.cxx
+5
-2
Helpers.cxx
src/db/Helpers.cxx
+1
-1
Stats.hxx
src/db/Stats.hxx
+4
-2
ProxyDatabasePlugin.cxx
src/db/plugins/ProxyDatabasePlugin.cxx
+1
-1
No files found.
src/Stats.cxx
View file @
58352ea6
...
@@ -99,15 +99,18 @@ db_stats_print(Client &client, const Database &db)
...
@@ -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: %
l
u
\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
)
...
...
src/db/Helpers.cxx
View file @
58352ea6
...
@@ -41,7 +41,7 @@ StatsVisitTag(DatabaseStats &stats, StringSet &artists, StringSet &albums,
...
@@ -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
)
{
...
...
src/db/Stats.hxx
View file @
58352ea6
...
@@ -20,6 +20,8 @@
...
@@ -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 {
...
@@ -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 {
...
@@ -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
;
}
}
};
};
...
...
src/db/plugins/ProxyDatabasePlugin.cxx
View file @
58352ea6
...
@@ -807,7 +807,7 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection,
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment