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 += " "
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;
}