Add total scrobble count to stats
This commit is contained in:
@@ -107,6 +107,10 @@ defmodule MusicLibrary.ScrobbleActivity do
|
|||||||
defp main_artist_name([]), do: nil
|
defp main_artist_name([]), do: nil
|
||||||
defp main_artist_name([artist | _rest]), do: artist.name
|
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
|
def from_recent_tracks(recent_tracks, timezone) do
|
||||||
all_artist_pairs = Artists.get_all_artist_pairs()
|
all_artist_pairs = Artists.get_all_artist_pairs()
|
||||||
recent_release_ids = recent_release_ids(recent_tracks)
|
recent_release_ids = recent_release_ids(recent_tracks)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ defmodule MusicLibraryWeb.StatsComponents do
|
|||||||
|
|
||||||
attr :title, :string, required: true
|
attr :title, :string, required: true
|
||||||
attr :count, :integer, required: true
|
attr :count, :integer, required: true
|
||||||
attr :path, :string, required: true
|
attr :path, :string, required: false, default: nil
|
||||||
|
|
||||||
def counter(assigns) do
|
def counter(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -60,11 +60,18 @@ defmodule MusicLibraryWeb.StatsComponents do
|
|||||||
</dt>
|
</dt>
|
||||||
<dd class="mt-1">
|
<dd class="mt-1">
|
||||||
<.link
|
<.link
|
||||||
|
:if={@path}
|
||||||
navigate={@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"
|
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}
|
{@count}
|
||||||
</.link>
|
</.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>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -135,6 +135,8 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
artist_ids: artist_ids
|
artist_ids: artist_ids
|
||||||
} = ScrobbleActivity.from_recent_tracks(recent_tracks, socket.assigns.timezone)
|
} = ScrobbleActivity.from_recent_tracks(recent_tracks, socket.assigns.timezone)
|
||||||
|
|
||||||
|
scrobble_count = ScrobbleActivity.scrobble_count()
|
||||||
|
|
||||||
last_updated_uts =
|
last_updated_uts =
|
||||||
if track = List.first(localized_recent_tracks) do
|
if track = List.first(localized_recent_tracks) do
|
||||||
track.scrobbled_at_uts
|
track.scrobbled_at_uts
|
||||||
@@ -142,6 +144,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
|
|
||||||
socket
|
socket
|
||||||
|> assign(:last_updated_uts, last_updated_uts)
|
|> assign(:last_updated_uts, last_updated_uts)
|
||||||
|
|> assign(:scrobble_count, scrobble_count)
|
||||||
|> stream(:recent_tracks, localized_recent_tracks, reset: true)
|
|> stream(:recent_tracks, localized_recent_tracks, reset: true)
|
||||||
|> stream(:recent_albums, recent_albums, reset: true)
|
|> stream(:recent_albums, recent_albums, reset: true)
|
||||||
|> assign(
|
|> assign(
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
{gettext("Records")}
|
{gettext("Records")}
|
||||||
</h1>
|
</h1>
|
||||||
<%!-- TODO: replace with OSS version --%>
|
<%!-- 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
|
<.album_preview
|
||||||
record={@latest_record}
|
record={@latest_record}
|
||||||
title={gettext("Latest purchase")}
|
title={gettext("Latest purchase")}
|
||||||
class="col-span-2 sm:col-span-3"
|
class="col-span-3 sm:col-span-2"
|
||||||
/>
|
/>
|
||||||
<.counter
|
<.counter
|
||||||
title={gettext("Total collection")}
|
title={gettext("Total collection")}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
path={~p"/collection"}
|
path={~p"/collection"}
|
||||||
/>
|
/>
|
||||||
<.counter title={gettext("Total wishlist")} count={@wishlist_count} path={~p"/wishlist"} />
|
<.counter title={gettext("Total wishlist")} count={@wishlist_count} path={~p"/wishlist"} />
|
||||||
|
<.counter title={gettext("Total scrobbles")} count={@scrobble_count} />
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1308,3 +1308,8 @@ msgstr[1] ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Search (Cmd/Ctrl+K)"
|
msgid "Search (Cmd/Ctrl+K)"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/stats_live/index.html.heex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Total scrobbles"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
@@ -1308,3 +1308,8 @@ msgstr[1] ""
|
|||||||
#, elixir-autogen, elixir-format, fuzzy
|
#, elixir-autogen, elixir-format, fuzzy
|
||||||
msgid "Search (Cmd/Ctrl+K)"
|
msgid "Search (Cmd/Ctrl+K)"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/live/stats_live/index.html.heex
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Total scrobbles"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user