Added UI distinction for associated scrobbles

This commit is contained in:
krateng 2023-10-28 21:39:54 +02:00
parent 6182b1dbcc
commit bad5fe7ce1
5 changed files with 36 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -53,7 +53,12 @@
<!-- scrobbles -->
<td class="amount">{{ links.link_scrobbles([{'artist':e['artist'],'associated':(not specialkeys.separate),'timerange':limitkeys.timerange}],amount=e['scrobbles']) }}</td>
<td class="bar">{{ links.link_scrobbles([{'artist':e['artist'],'associated':(not specialkeys.separate),'timerange':limitkeys.timerange}],percent=e['scrobbles']*100/maxbar) }}</td>
<td class="bar">
{{ 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 %}
</td>
</tr>
{% endif %}
{% endfor %}

View File

@ -22,7 +22,12 @@
{% else %}
{{ entityrow.row(artist,counting=([] if specialkeys.separate else e.associated_artists)) }}
<td class='amount'>{{ links.link_scrobbles([{'artist':artist,'associated':(not specialkeys.separate),'timerange':thisrange}],amount=e.scrobbles) }}</td>
<td class='bar'> {{ links.link_scrobbles([{'artist':artist,'associated':(not specialkeys.separate),'timerange':thisrange}],percent=e.scrobbles*100/maxbar) }}</td>
<td class='bar'>
{{ 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 %}
</td>
{% endif %}
</tr>

View File

@ -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); */