Add total scrobble count to stats

This commit is contained in:
Claudio Ortolina
2025-09-02 08:17:42 +03:00
parent b932ad0ef4
commit a4670412df
6 changed files with 28 additions and 3 deletions
+4
View File
@@ -107,6 +107,10 @@ defmodule MusicLibrary.ScrobbleActivity do
defp main_artist_name([]), do: nil
defp main_artist_name([artist | _rest]), do: artist.name
def scrobble_count do
Repo.aggregate(Track, :count, :scrobbled_at_uts)
end
def from_recent_tracks(recent_tracks, timezone) do
all_artist_pairs = Artists.get_all_artist_pairs()
recent_release_ids = recent_release_ids(recent_tracks)
@@ -48,7 +48,7 @@ defmodule MusicLibraryWeb.StatsComponents do
attr :title, :string, required: true
attr :count, :integer, required: true
attr :path, :string, required: true
attr :path, :string, required: false, default: nil
def counter(assigns) do
~H"""
@@ -60,11 +60,18 @@ defmodule MusicLibraryWeb.StatsComponents do
</dt>
<dd class="mt-1">
<.link
:if={@path}
navigate={@path}
class="block text-2xl sm:text-3xl font-semibold text-center text-zinc-900 hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200"
>
{@count}
</.link>
<p
:if={!@path}
class="block text-2xl sm:text-3xl font-semibold text-center text-zinc-900 dark:text-zinc-300"
>
{@count}
</p>
</dd>
</div>
"""
@@ -135,6 +135,8 @@ defmodule MusicLibraryWeb.StatsLive.Index do
artist_ids: artist_ids
} = ScrobbleActivity.from_recent_tracks(recent_tracks, socket.assigns.timezone)
scrobble_count = ScrobbleActivity.scrobble_count()
last_updated_uts =
if track = List.first(localized_recent_tracks) do
track.scrobbled_at_uts
@@ -142,6 +144,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
socket
|> assign(:last_updated_uts, last_updated_uts)
|> assign(:scrobble_count, scrobble_count)
|> stream(:recent_tracks, localized_recent_tracks, reset: true)
|> stream(:recent_albums, recent_albums, reset: true)
|> assign(
@@ -3,11 +3,11 @@
{gettext("Records")}
</h1>
<%!-- TODO: replace with OSS version --%>
<dl class="mt-5 grid grid-cols-2 gap-5 sm:grid-cols-5">
<dl class="mt-5 grid grid-cols-3 gap-5 sm:grid-cols-5">
<.album_preview
record={@latest_record}
title={gettext("Latest purchase")}
class="col-span-2 sm:col-span-3"
class="col-span-3 sm:col-span-2"
/>
<.counter
title={gettext("Total collection")}
@@ -15,6 +15,7 @@
path={~p"/collection"}
/>
<.counter title={gettext("Total wishlist")} count={@wishlist_count} path={~p"/wishlist"} />
<.counter title={gettext("Total scrobbles")} count={@scrobble_count} />
</dl>
</div>