1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Implemented top tracks in jinja

This commit is contained in:
Krateng 2020-08-27 22:26:51 +02:00
parent 7fc879f778
commit 0abf2aae39
4 changed files with 101 additions and 3 deletions

View File

@ -34,9 +34,6 @@ def datadir(*args):
from doreah import config
config(
pyhp={
"version": 2
},
settings={
"files":[
datadir("settings/default.ini"),

View File

@ -2,3 +2,40 @@ def fixlength(real,target):
t = real[:target]
while len(t)<target: t.append(None)
return t
def find_representative(sequence,attribute_id,attribute_count):
try:
newsequence = [e for e in sequence if e is not None and e[attribute_id] is not None]
for element in newsequence:
element["_j_appears"] = [e[attribute_id] for e in newsequence].count(element[attribute_id])
newsequence = [e for e in newsequence if e["_j_appears"] == max(el["_j_appears"] for el in newsequence)]
newsequence = [e for e in newsequence if e[attribute_count] == max(el[attribute_count] for el in newsequence)]
return newsequence[0]
except:
return None
finally:
for e in newsequence:
del e["_j_appears"]
# groups = []
# for element in sequence:
# for grouprep,groupentries in groups:
# if grouprep == element[attribute_id]:
# groupentries.append(element)
# break
# else:
# groups.append((element[attribute_id],[element]))
#
# groups.sort(key=lambda x:len(x[1]),reverse=True)
#
# # now group this grouping by number of appearances
#
# import itertools
# byappearances = itertools.groupby(groups,key=lambda x:len(x[1]))
# mostappearances = list(next(byappearances)[1])
#
# return mostappearances
# # among those, pick the one with the highest count in one of their appearances

View File

@ -0,0 +1,32 @@
{% macro top_tracks(filterkeys,limitkeys,delimitkeys,amountkeys) %}
{% set ranges = dbp.get_top_tracks(filterkeys,limitkeys,delimitkeys) %}
{% set maxbar = ranges|map(attribute="scrobbles")|max|default(1) %}
{% if maxbar < 1 %}{% set maxbar = 1 %}{% endif %}
<table class="list">
{% for e in ranges %}
{% set thisrange = e.range %}
{% set track = e.track %}
<tr>
<td>{{ thisrange.desc() }}</td>
{% if e.track is none %}
<td><div></div></td>
<td class='stats'>n/a</td>
<td class='amount'>0</td>
<td class='bar'></td>
{% else %}
{{ htmlgenerators.entity_column(track,image=utilities.getTrackImage(track.artists,track.title,fast=True)) }}
<td class='amount'>{{ htmlgenerators.scrobblesTrackLink(track,thisrange.urikeys(),amount=e.scrobbles) }}</td>
<td class='bar'> {{ htmlgenerators.scrobblesTrackLink(track,thisrange.urikeys(),percent=e.scrobbles*100/maxbar) }}</td>
{% endif %}
</tr>
{% endfor %}
</table>
{%- endmacro %}

View File

@ -0,0 +1,32 @@
{% extends "abstracts/base.jinja" %}
{% block title %}Maloja - #1 Tracks{% endblock %}
<!-- find representative -->
{% set entries = dbp.get_top_tracks(filterkeys,limitkeys,delimitkeys) %}
{% set repr = entries | find_representative('track','scrobbles') %}
{% set img = "/favicon.png" if repr is none else utilities.getTrackImage(repr.track.artists,repr.track.title) %}
{% block content %}
<table class="top_info">
<tr>
<td class="image">
<div style="background-image:url('{{ img }}')"></div>
</td>
<td class="text">
<h1>#1 Tracks</h1><br/>
<span>{{ limitkeys.timerange.desc(prefix=True) }}</span>
<br/><br/>
{{ htmlmodules.module_filterselection(_urikeys,delimit=True) }}
</td>
</tr>
</table>
{% import 'partials/top_tracks.jinja' as top_tracks %}
{{ top_tracks.top_tracks(filterkeys,limitkeys,delimitkeys,amountkeys) }}
{% endblock %}