From 439d12d87f010bddb84d1df1ca4a8bb007536c7f Mon Sep 17 00:00:00 2001 From: Krateng Date: Sun, 23 Aug 2020 00:30:55 +0200 Subject: [PATCH] Implemented chart trend indicators --- maloja/web/jinja/charts_artists.jinja | 2 +- maloja/web/jinja/charts_tracks.jinja | 2 +- .../web/jinja/partials/charts_artists.jinja | 24 ++++++++++++++++--- maloja/web/jinja/partials/charts_tracks.jinja | 21 ++++++++-------- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/maloja/web/jinja/charts_artists.jinja b/maloja/web/jinja/charts_artists.jinja index bb14dff..8f65da2 100644 --- a/maloja/web/jinja/charts_artists.jinja +++ b/maloja/web/jinja/charts_artists.jinja @@ -36,7 +36,7 @@ {% import 'partials/charts_artists.jinja' as charts_artists %} -{{ charts_artists.charts_artists(limitkeys,amountkeys,compare=False) }} +{{ charts_artists.charts_artists(limitkeys,amountkeys,compare=true) }} {% import 'snippets/pagination.jinja' as pagination %} diff --git a/maloja/web/jinja/charts_tracks.jinja b/maloja/web/jinja/charts_tracks.jinja index e38752b..d8ba310 100644 --- a/maloja/web/jinja/charts_tracks.jinja +++ b/maloja/web/jinja/charts_tracks.jinja @@ -36,7 +36,7 @@ {% import 'partials/charts_tracks.jinja' as charts_tracks %} -{{ charts_tracks.charts_tracks(filterkeys,limitkeys,amountkeys,charts=charts,compare=false) }} +{{ charts_tracks.charts_tracks(filterkeys,limitkeys,amountkeys,charts=charts,compare=true) }} {% import 'snippets/pagination.jinja' as pagination %} diff --git a/maloja/web/jinja/partials/charts_artists.jinja b/maloja/web/jinja/partials/charts_artists.jinja index 3049384..56fb6d2 100644 --- a/maloja/web/jinja/partials/charts_artists.jinja +++ b/maloja/web/jinja/partials/charts_artists.jinja @@ -5,6 +5,21 @@ {% endif %} {% if compare %} + {% if compare is true %} + {% set compare = limitkeys.timerange.next(step=-1) %} + {% endif %} + {% set prevartists = dbp.get_charts_artists(filterkeys,{'timerange':compare}) %} + + {% set lastranks = {} %} + {% for a in prevartists %} + {% if lastranks.update({a.artist:a.rank}) %}{% endif %} + {% endfor %} + + {% for a in charts %} + {% if a.artist in lastranks %} + {% if a.update({'last_rank':lastranks[a.artist]}) %}{% endif %} + {% endif %} + {% endfor %} {% endif %} {% set firstindex = amountkeys.page * amountkeys.perpage %} @@ -20,9 +35,12 @@ {%if loop.changed(e.scrobbles) %}#{{ e.rank }}{% endif %} - {% if false %} - {% if e not in prevcharts %}🆕{% endif %} - + {% if compare %} + {% if e.last_rank is undefined %}🆕 + {% elif e.last_rank < e.rank %}↘ + {% elif e.last_rank > e.rank %}↗ + {% elif e.last_rank == e.rank %}➡ + {% endif %} {% endif %} diff --git a/maloja/web/jinja/partials/charts_tracks.jinja b/maloja/web/jinja/partials/charts_tracks.jinja index 9bfee8e..2351111 100644 --- a/maloja/web/jinja/partials/charts_tracks.jinja +++ b/maloja/web/jinja/partials/charts_tracks.jinja @@ -9,14 +9,14 @@ {% endif %} {% set prevtracks = dbp.get_charts_tracks(filterkeys,{'timerange':compare}) %} - {% set lastrank = {} %} - {% for t in charts %} - {% if lastrank.update({(t.track.artists,t.track.title):t.rank}) %}{% endif %} + {% set lastranks = {} %} + {% for t in prevtracks %} + {% if lastranks.update({"|".join(t.track.artists)+"||"+t.track.title:t.rank}) %}{% endif %} {% endfor %} {% for t in charts %} - {% if (t.track.artists,t.track.title) in lastrank %} - {% if t.update({'lastrank':lastrank[(t.track.artists,t.track.title)]}) %}{% endif %} + {% if "|".join(t.track.artists)+"||"+t.track.title in lastranks %} + {% if t.update({'last_rank':lastranks["|".join(t.track.artists)+"||"+t.track.title]}) %}{% endif %} {% endif %} {% endfor %} {% endif %} @@ -24,9 +24,7 @@ {% set firstindex = amountkeys.page * amountkeys.perpage %} {% set lastindex = firstindex + amountkeys.perpage %} - {% set maxbar = charts[0]['scrobbles'] if charts != [] else 0 %} - {% for e in charts %} {% if loop.index0 >= firstindex and loop.index0 < lastindex %} @@ -34,9 +32,12 @@ - {% if false %} - {% if e not in prevtracks %}{% endif %} - + {% if compare %} + {% if e.last_rank is undefined %} + {% elif e.last_rank < e.rank %} + {% elif e.last_rank > e.rank %} + {% elif e.last_rank == e.rank %} + {% endif %} {% endif %}
{%if loop.changed(e.scrobbles) %}#{{ e.rank }}{% endif %} 🆕🆕↘↗➡