Add check if there is a tie in scrobble count

This commit is contained in:
mitteneer 2025-07-02 16:10:55 -04:00
parent 5739f89e0d
commit 9fa90ff129
2 changed files with 15 additions and 8 deletions

View file

@ -17,7 +17,11 @@
<div style="display:flex;flex-direction:row;justify-content:space-evenly"> <div style="display:flex;flex-direction:row;justify-content:space-evenly">
<div style="display:flex;flex-direction:column;align-self:left"> <div style="display:flex;flex-direction:column;align-self:left">
@if ($.song.is_tie)
<div>{{.song.scrobbles}} scrobbles ({{.song.rank}} place, tied)</div>
@else
<div>{{.song.scrobbles}} scrobbles ({{.song.rank}} place)</div> <div>{{.song.scrobbles}} scrobbles ({{.song.rank}} place)</div>
@end
@partial partials/firstlast_listens(firstlast: .firstlast) @partial partials/firstlast_listens(firstlast: .firstlast)
<h3>Yearly Performance</h3> <h3>Yearly Performance</h3>
@partial partials/timescale(range: .yearly) @partial partials/timescale(range: .yearly)

View file

@ -346,14 +346,17 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
.entity_info => switch (entity) { .entity_info => switch (entity) {
.scrobble => unreachable, .scrobble => unreachable,
.song => .song =>
\\SELECT * FROM \\WITH ranked AS (
\\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM99999th') AS rank FROM \\SELECT songs.name AS song_name, COUNT(songs.id) AS scrobbles, RANK() OVER ( ORDER BY COUNT(songs.id) DESC) AS rank, songs.id AS song_id
\\(SELECT songs.name AS song_name, songs.id AS song_id, COUNT(scrobbles) AS scrobbles \\FROM scrobbles
\\FROM albumsongs \\INNER JOIN albumsongs ON albumsongs.id = scrobbles.albumsong
\\INNER JOIN songs ON albumsongs.song_id = songs.id \\INNER JOIN songs ON songs.id = albumsongs.song_id
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id \\GROUP BY songs.id)
\\GROUP BY songs.id)) \\SELECT * FROM (SELECT song_name, scrobbles, TO_CHAR(rank,'FM9999th') AS rank, song_id,
\\WHERE song_id = $1 \\( rank = lag(rank, 1, -1::bigint) OVER (ORDER BY rank)
\\OR rank = lead(rank, 1, -1::bigint) OVER (ORDER BY rank)
\\)AS is_tie
\\FROM ranked) WHERE song_id = $1;
, ,
.album => .album =>
\\SELECT album_name, t.album_id, artists.name AS artist_name, artists.id AS artist_id, song_num, scrobbles, rank FROM \\SELECT album_name, t.album_id, artists.name AS artist_name, artists.id AS artist_id, song_num, scrobbles, rank FROM