fix: stat items incorrect date range

This commit is contained in:
cwilvx
2024-10-14 13:44:52 +03:00
parent ee67e87532
commit de0db0a4b2
+13 -12
View File
@@ -295,44 +295,45 @@ def get_stats():
""" """
Get the stats for the user. Get the stats for the user.
""" """
now = int(datetime.now().timestamp()) # now = int(datetime.now().timestamp())
one_week_ago = now - get_duration_in_seconds("week") # one_week_ago = now - get_duration_in_seconds("week")
start_time, end_time = get_date_range("year")
total_tracks = StatItem( total_tracks = StatItem(
"trackcount", "trackcount",
"Total tracks", "Total tracks",
len(TrackStore.get_flat_list()), len(TrackStore.get_flat_list()),
) )
last_7_tracks, last_7_days_playcount, last_7_days_playduration = ( tracks, playcount, playduration = (
get_tracks_in_period(one_week_ago, now) get_tracks_in_period(start_time, end_time)
) )
last_7_days_playcount = StatItem( playcount = StatItem(
"streams", "streams",
"Track plays last week", "Track plays last week",
last_7_days_playcount, playcount,
) )
last_7_days_playduration = StatItem( playduration = StatItem(
"playtime", "playtime",
"Playtime last week", "Playtime last week",
seconds_to_time_string(last_7_days_playduration), seconds_to_time_string(playduration),
) )
last_7_tracks = sorted(last_7_tracks, key=lambda t: t.playduration, reverse=True) tracks = sorted(tracks, key=lambda t: t.playduration, reverse=True)
# Find the top track from the last 7 days # Find the top track from the last 7 days
top_track = StatItem( top_track = StatItem(
"toptrack", "toptrack",
"Top track last week", "Top track last week",
last_7_tracks[0].title if len(last_7_tracks) > 0 else "-", tracks[0].title if len(tracks) > 0 else "-",
) )
return { return {
"stats": [ "stats": [
top_track, top_track,
last_7_days_playcount, playcount,
last_7_days_playduration, playduration,
total_tracks, total_tracks,
] ]
} }