From bad5fe7ce12e9c280791cf309761a75e777b82f0 Mon Sep 17 00:00:00 2001 From: krateng Date: Sat, 28 Oct 2023 21:39:54 +0200 Subject: [PATCH] Added UI distinction for associated scrobbles --- maloja/database/__init__.py | 4 ++-- maloja/database/sqldb.py | 13 ++++++++----- maloja/web/jinja/partials/charts_artists.jinja | 7 ++++++- maloja/web/jinja/partials/top_artists.jinja | 7 ++++++- maloja/web/static/css/maloja.css | 14 ++++++++++++++ 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 297048b..d3b56ef 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -564,9 +564,9 @@ def get_top_artists(dbconn=None,**keys): for rng in rngs: try: res = get_charts_artists(timerange=rng,separate=separate,dbconn=dbconn)[0] - results.append({"range":rng,"artist":res["artist"],"scrobbles":res["scrobbles"],"associated_artists":sqldb.get_associated_artists(res["artist"])}) + results.append({"range":rng,"artist":res["artist"],"scrobbles":res["scrobbles"],"real_scrobbles":res["real_scrobbles"],"associated_artists":sqldb.get_associated_artists(res["artist"])}) except Exception: - results.append({"range":rng,"artist":None,"scrobbles":0}) + results.append({"range":rng,"artist":None,"scrobbles":0,"real_scrobbles":0}) return results diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index d33dd4b..3e6f52a 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -1063,11 +1063,14 @@ def count_scrobbles_by_artist(since,to,associated=True,resolve_ids=True,dbconn=N # only count distinct scrobbles - because of artist replacement, we could end up # with two artists of the same scrobble counting it twice for the same artist # e.g. Irene and Seulgi adding two scrobbles to Red Velvet for one real scrobble - artistselect.label('artist_id') + artistselect.label('artist_id'), # use the replaced artist as artist to count if it exists, otherwise original one + sql.func.sum( + sql.case((DB['trackartists'].c.artist_id == artistselect, 1), else_=0) + ).label('really_by_this_artist') + # also select the original artist in any case as a separate column ).select_from(jointable2).where( - DB['scrobbles'].c.timestamp<=to, - DB['scrobbles'].c.timestamp>=since + DB['scrobbles'].c.timestamp.between(since,to) ).group_by( artistselect ).order_by(sql.desc('count')) @@ -1075,9 +1078,9 @@ def count_scrobbles_by_artist(since,to,associated=True,resolve_ids=True,dbconn=N if resolve_ids: artists = get_artists_map([row.artist_id for row in result],dbconn=dbconn) - result = [{'scrobbles':row.count,'artist':artists[row.artist_id],'artist_id':row.artist_id} for row in result] + result = [{'scrobbles':row.count,'real_scrobbles':row.really_by_this_artist,'artist':artists[row.artist_id],'artist_id':row.artist_id} for row in result] else: - result = [{'scrobbles':row.count,'artist_id':row.artist_id} for row in result] + result = [{'scrobbles':row.count,'real_scrobbles':row.really_by_this_artist,'artist_id':row.artist_id} for row in result] result = rank(result,key='scrobbles') return result diff --git a/maloja/web/jinja/partials/charts_artists.jinja b/maloja/web/jinja/partials/charts_artists.jinja index 4cd0063..221dae5 100644 --- a/maloja/web/jinja/partials/charts_artists.jinja +++ b/maloja/web/jinja/partials/charts_artists.jinja @@ -53,7 +53,12 @@ {{ links.link_scrobbles([{'artist':e['artist'],'associated':(not specialkeys.separate),'timerange':limitkeys.timerange}],amount=e['scrobbles']) }} - {{ links.link_scrobbles([{'artist':e['artist'],'associated':(not specialkeys.separate),'timerange':limitkeys.timerange}],percent=e['scrobbles']*100/maxbar) }} + + {{ links.link_scrobbles([{'artist':e['artist'],'associated':False,'timerange':limitkeys.timerange}],percent=e['real_scrobbles']*100/maxbar) }} + {%- if e['real_scrobbles'] != e['scrobbles'] -%} + {{ links.link_scrobbles([{'artist':e['artist'],'associated':True,'timerange':limitkeys.timerange}],percent=(e['scrobbles']-e['real_scrobbles'])*100/maxbar) }} + {%- endif %} + {% endif %} {% endfor %} diff --git a/maloja/web/jinja/partials/top_artists.jinja b/maloja/web/jinja/partials/top_artists.jinja index dae0f10..5063f1d 100644 --- a/maloja/web/jinja/partials/top_artists.jinja +++ b/maloja/web/jinja/partials/top_artists.jinja @@ -22,7 +22,12 @@ {% else %} {{ entityrow.row(artist,counting=([] if specialkeys.separate else e.associated_artists)) }} {{ links.link_scrobbles([{'artist':artist,'associated':(not specialkeys.separate),'timerange':thisrange}],amount=e.scrobbles) }} - {{ links.link_scrobbles([{'artist':artist,'associated':(not specialkeys.separate),'timerange':thisrange}],percent=e.scrobbles*100/maxbar) }} + + {{ links.link_scrobbles([{'artist':e['artist'],'associated':False,'timerange':e.range}],percent=e['real_scrobbles']*100/maxbar) }} + {%- if e['real_scrobbles'] != e['scrobbles'] -%} + {{ links.link_scrobbles([{'artist':e['artist'],'associated':True,'timerange':e.range}],percent=(e['scrobbles']-e['real_scrobbles'])*100/maxbar) }} + {%- endif %} + {% endif %} diff --git a/maloja/web/static/css/maloja.css b/maloja/web/static/css/maloja.css index 396091a..0d6378f 100644 --- a/maloja/web/static/css/maloja.css +++ b/maloja/web/static/css/maloja.css @@ -905,6 +905,20 @@ table.list tr:hover td.bar div { cursor:pointer; } +/* extra bar for associated */ +table.list td.bar a:nth-child(2) div { + opacity: 0.7; +} +table.list td.bar:hover a:nth-child(2) div { + /* when we start hovering over the bar, but not the associated part, go back to normal bg color */ + background-color: var(--text-color); +} +table.list td.bar:hover a:nth-child(2) div:hover { + /* restore full color when hovering the associated part */ + background-color: var(--text-color-focus); +} + + table.list td.chart { width:400px; /* background-color: var(--base-color); */