Fix artist aggregation so it works
This commit is contained in:
@ -94,7 +94,7 @@ def top_artists(filter: str = "today", limit: int = 15) -> List["Artist"]:
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
Artist.objects.annotate(
|
Artist.objects.annotate(
|
||||||
num_scrobbles=Sum("track__scrobble", distinct=True)
|
num_scrobbles=Count("track__scrobble", distinct=True)
|
||||||
)
|
)
|
||||||
.filter(time_filter)
|
.filter(time_filter)
|
||||||
.order_by("-num_scrobbles")[:limit]
|
.order_by("-num_scrobbles")[:limit]
|
||||||
|
|||||||
@ -13,7 +13,7 @@ class ScrobbleAdmin(admin.ModelAdmin):
|
|||||||
"playback_position",
|
"playback_position",
|
||||||
"in_progress",
|
"in_progress",
|
||||||
)
|
)
|
||||||
list_filter = ("in_progress", "source")
|
list_filter = ("in_progress", "source", "track__artist")
|
||||||
ordering = ("-timestamp",)
|
ordering = ("-timestamp",)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ from scrobbles.utils import convert_to_seconds
|
|||||||
from videos.models import Video
|
from videos.models import Video
|
||||||
from vrobbler.apps.music.aggregators import (
|
from vrobbler.apps.music.aggregators import (
|
||||||
scrobble_counts,
|
scrobble_counts,
|
||||||
|
top_artists,
|
||||||
top_tracks,
|
top_tracks,
|
||||||
week_of_scrobbles,
|
week_of_scrobbles,
|
||||||
)
|
)
|
||||||
@ -62,6 +63,11 @@ class RecentScrobbleList(ListView):
|
|||||||
data['top_daily_tracks'] = top_tracks()
|
data['top_daily_tracks'] = top_tracks()
|
||||||
data['top_weekly_tracks'] = top_tracks(filter='week')
|
data['top_weekly_tracks'] = top_tracks(filter='week')
|
||||||
data['top_monthly_tracks'] = top_tracks(filter='month')
|
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["weekly_data"] = week_of_scrobbles()
|
||||||
data['counts'] = scrobble_counts()
|
data['counts'] = scrobble_counts()
|
||||||
return data
|
return data
|
||||||
|
|||||||
@ -280,35 +280,35 @@
|
|||||||
var myChart = new Chart(ctx, {
|
var myChart = new Chart(ctx, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels: [
|
labels: [
|
||||||
{% for day in weekly_data.keys %}
|
{% for day in weekly_data.keys %}
|
||||||
"{{day}}"{% if not forloop.last %},{% endif %}
|
"{{day}}"{% if not forloop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
],
|
],
|
||||||
datasets: [{
|
datasets: [{
|
||||||
data: [
|
data: [
|
||||||
{% for count in weekly_data.values %}
|
{% for count in weekly_data.values %}
|
||||||
{{count}}{% if not forloop.last %},{% endif %}
|
{{count}}{% if not forloop.last %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
],
|
],
|
||||||
lineTension: 0,
|
lineTension: 0,
|
||||||
backgroundColor: 'transparent',
|
backgroundColor: 'transparent',
|
||||||
borderColor: '#007bff',
|
borderColor: '#007bf0',
|
||||||
borderWidth: 4,
|
borderWidth: 4,
|
||||||
pointBackgroundColor: '#007bff'
|
pointBackgroundColor: '#007bff'
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
scales: {
|
scales: {
|
||||||
yAxes: [{
|
yAxes: [{
|
||||||
ticks: {
|
ticks: {
|
||||||
beginAtZero: false
|
beginAtZero: false
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
legend: {
|
legend: {
|
||||||
display: false
|
display: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
|
|||||||
@ -20,80 +20,109 @@
|
|||||||
|
|
||||||
<canvas class="my-4 w-100" id="myChart" width="900" height="380"></canvas>
|
<canvas class="my-4 w-100" id="myChart" width="900" height="380"></canvas>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
<h2>Top this week</h2>
|
<div class="row">
|
||||||
<div class="table-responsive">
|
<div class="col-md">
|
||||||
<table class="table table-striped table-sm">
|
<h2>Top artists this week</h2>
|
||||||
<thead>
|
<div class="table-responsive">
|
||||||
<tr>
|
<table class="table table-striped table-sm">
|
||||||
<th scope="col">#</th>
|
<thead>
|
||||||
<th scope="col">Track</th>
|
<tr>
|
||||||
<th scope="col">Artist</th>
|
<th scope="col">#</th>
|
||||||
<th scope="col">Album</th>
|
<th scope="col">Artist</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for track in top_weekly_tracks %}
|
{% for artist in top_weekly_artists %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{track.num_scrobbles}}</td>
|
<td>{{artist.num_scrobbles}}</td>
|
||||||
<td>{{track.title}}</td>
|
<td>{{artist.name}}</td>
|
||||||
<td>{{track.artist.name}}</td>
|
</tr>
|
||||||
<td>{{track.album.name}}</td>
|
{% endfor %}
|
||||||
</tr>
|
</tbody>
|
||||||
{% endfor %}
|
</table>
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
</div>
|
||||||
|
<div class="col-lg">
|
||||||
|
<h2>Top tracks this week</h2>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Track</th>
|
||||||
|
<th scope="col">Artist</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for track in top_weekly_tracks %}
|
||||||
|
<tr>
|
||||||
|
<td>{{track.num_scrobbles}}</td>
|
||||||
|
<td>{{track.title}}</td>
|
||||||
|
<td>{{track.artist.name}}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg">
|
||||||
|
<h2>Latest listened</h2>
|
||||||
|
<p>Today <b>{{counts.today}}</b> | This Week <b>{{counts.week}}</b> | This Month <b>{{counts.month}}</b> | This Year <b>{{counts.year}}</b> | All Time <b>{{counts.alltime}}</b></p>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Time</th>
|
||||||
|
<th scope="col">Track</th>
|
||||||
|
<th scope="col">Artist</th>
|
||||||
|
<th scope="col">Source</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for scrobble in object_list %}
|
||||||
|
<tr>
|
||||||
|
<td>{{scrobble.timestamp|naturaltime}}</td>
|
||||||
|
<td>{{scrobble.track.title}}</td>
|
||||||
|
<td>{{scrobble.track.artist.name}}</td>
|
||||||
|
<td>{{scrobble.source}}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h2>Latest scrobbles</h2>
|
<div class="col-lg">
|
||||||
<p>Today <b>{{counts.today}}</b> | This Week <b>{{counts.week}}</b> | This Month <b>{{counts.month}}</b> | This Year <b>{{counts.year}}</b> | All Time <b>{{counts.alltime}}</b></p>
|
<h2>Latest watched</h2>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped table-sm">
|
<table class="table table-striped table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Time</th>
|
<th scope="col">Time</th>
|
||||||
<th scope="col">Track</th>
|
<th scope="col">Title</th>
|
||||||
<th scope="col">Artist</th>
|
<th scope="col">Series</th>
|
||||||
<th scope="col">Source</th>
|
<th scope="col">Source</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for scrobble in object_list %}
|
{% for scrobble in video_scrobble_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{scrobble.timestamp|naturaltime}}</td>
|
<td>{{scrobble.timestamp|naturaltime}}</td>
|
||||||
<td>{{scrobble.track.title}}</td>
|
<td>{% if scrobble.video.tv_series %}E{{scrobble.video.season_number}}S{{scrobble.video.season_number}} -{% endif %} {{scrobble.video.title}}</td>
|
||||||
<td>{{scrobble.track.artist.name}}</td>
|
<td>{% if scrobble.video.tv_series %}{{scrobble.video.tv_series}}{% endif %}</td>
|
||||||
<td>{{scrobble.source}}</td>
|
<td>{{scrobble.source}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<h2>Latest watched</h2>
|
</div>
|
||||||
<div class="table-responsive">
|
|
||||||
<table class="table table-striped table-sm">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">Time</th>
|
|
||||||
<th scope="col">Title</th>
|
|
||||||
<th scope="col">Series</th>
|
|
||||||
<th scope="col">Season & Episode</th>
|
|
||||||
<th scope="col">Source</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for scrobble in video_scrobble_list %}
|
|
||||||
<tr>
|
|
||||||
<td>{{scrobble.timestamp|naturaltime}}</td>
|
|
||||||
<td>{{scrobble.video.title}}</td>
|
|
||||||
<td>{% if scrobble.video.tv_series %}{{scrobble.video.tv_series}}{% endif %}</td>
|
|
||||||
<td>{% if scrobble.video.tv_series %}{{scrobble.video.season_number}}, {{scrobble.video.episode_number}}{% endif %}</td>
|
|
||||||
<td>{{scrobble.source}}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user