Fix artist aggregation so it works

This commit is contained in:
2023-01-10 16:13:52 -05:00
parent 8b61dab1bc
commit f8c9df3b9a
5 changed files with 136 additions and 101 deletions

View File

@ -94,7 +94,7 @@ def top_artists(filter: str = "today", limit: int = 15) -> List["Artist"]:
return (
Artist.objects.annotate(
num_scrobbles=Sum("track__scrobble", distinct=True)
num_scrobbles=Count("track__scrobble", distinct=True)
)
.filter(time_filter)
.order_by("-num_scrobbles")[:limit]

View File

@ -13,7 +13,7 @@ class ScrobbleAdmin(admin.ModelAdmin):
"playback_position",
"in_progress",
)
list_filter = ("in_progress", "source")
list_filter = ("in_progress", "source", "track__artist")
ordering = ("-timestamp",)

View File

@ -23,6 +23,7 @@ from scrobbles.utils import convert_to_seconds
from videos.models import Video
from vrobbler.apps.music.aggregators import (
scrobble_counts,
top_artists,
top_tracks,
week_of_scrobbles,
)
@ -62,6 +63,11 @@ class RecentScrobbleList(ListView):
data['top_daily_tracks'] = top_tracks()
data['top_weekly_tracks'] = top_tracks(filter='week')
data['top_monthly_tracks'] = top_tracks(filter='month')
data['top_daily_artists'] = top_artists()
data['top_weekly_artists'] = top_artists(filter='week')
data['top_monthly_artists'] = top_artists(filter='month')
data["weekly_data"] = week_of_scrobbles()
data['counts'] = scrobble_counts()
return data