From 8b774c23bc72fcd2234f00652ba250b787597ed5 Mon Sep 17 00:00:00 2001 From: Krateng Date: Thu, 4 Apr 2019 20:01:28 +0200 Subject: [PATCH] Display of chart performance in charts view --- htmlmodules.py | 53 ++++++++++++++++++++++++++++++++++++++++++ website/css/maloja.css | 11 +++++++++ 2 files changed, 64 insertions(+) diff --git a/htmlmodules.py b/htmlmodules.py index 3c8a0ce..e0685b6 100644 --- a/htmlmodules.py +++ b/htmlmodules.py @@ -98,6 +98,20 @@ def module_trackcharts(max_=None,**kwargs): tracks = database.get_charts_tracks(**kwargs_filter,**kwargs_time) + # last time range (to compare) + if "within" in kwargs_time: + from malojatime import _get_next + trackslast = database.get_charts_tracks(**kwargs_filter,within=_get_next(kwargs_time["within"],step=-1)) + # create rank association + lastrank = {} + for tl in trackslast: + lastrank[(*tl["track"]["artists"],tl["track"]["title"])] = tl["rank"] + for t in tracks: + try: + t["delta"] = lastrank[(*t["track"]["artists"],t["track"]["title"])] - t["rank"] + except: + t["delta"] = None + if tracks != []: maxbar = tracks[0]["scrobbles"] representative = tracks[0]["track"] @@ -112,12 +126,25 @@ def module_trackcharts(max_=None,**kwargs): if max_ is not None and i>max_: break html += "" + # rank if i == 1 or e["scrobbles"] < prev["scrobbles"]: html += "#" + str(i) + "" else: html += "" + # rank change + if "within" not in kwargs_time: pass + elif e["delta"] is None: + html += "🆕" + elif e["delta"] > 0: + html += "↗" + elif e["delta"] < 0: + html += "↘" + else: + html += "➡" + # track html += "" + artistLinks(e["track"]["artists"]) + "" html += "" + trackLink(e["track"]) + "" + # scrobbles html += "" + scrobblesTrackLink(e["track"],kwargs_time,amount=e["scrobbles"]) + "" html += "" + scrobblesTrackLink(e["track"],kwargs_time,percent=e["scrobbles"]*100/maxbar) + "" html += "" @@ -134,6 +161,19 @@ def module_artistcharts(max_=None,**kwargs): artists = database.get_charts_artists(**kwargs_filter,**kwargs_time) + # last time range (to compare) + if "within" in kwargs_time: + from malojatime import _get_next + artistslast = database.get_charts_artists(**kwargs_filter,within=_get_next(kwargs_time["within"],step=-1)) + # create rank association + lastrank = {} + for al in artistslast: + lastrank[al["artist"]] = al["rank"] + for a in artists: + try: + a["delta"] = lastrank[a["artist"]] - a["rank"] + except: + a["delta"] = None if artists != []: maxbar = artists[0]["scrobbles"] @@ -148,14 +188,27 @@ def module_artistcharts(max_=None,**kwargs): if max_ is not None and i>max_: break html += "" + # rank if i == 1 or e["scrobbles"] < prev["scrobbles"]: html += "#" + str(i) + "" else: html += "" + # rank change + if "within" not in kwargs_time: pass + elif e["delta"] is None: + html += "🆕" + elif e["delta"] > 0: + html += "↗" + elif e["delta"] < 0: + html += "↘" + else: + html += "➡" + # artist html += "" + artistLink(e["artist"]) if (e["counting"] != []): html += " incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "" html += "" + # scrobbles html += "" + scrobblesArtistLink(e["artist"],kwargs_time,amount=e["scrobbles"],associated=True) + "" html += "" + scrobblesArtistLink(e["artist"],kwargs_time,percent=e["scrobbles"]*100/maxbar,associated=True) + "" html += "" diff --git a/website/css/maloja.css b/website/css/maloja.css index 0ed9d56..648b156 100644 --- a/website/css/maloja.css +++ b/website/css/maloja.css @@ -239,6 +239,17 @@ p.desc a { font-size:80%; } + +.rankup { + color:green; +} +.rankdown { + color:red; +} +.ranksame { + color:grey; +} + a { cursor:pointer; }