Better logic for representative image of #1 list

This commit is contained in:
Krateng 2019-04-02 15:27:22 +02:00
parent 6d76d323f0
commit 632aa2a8d7
2 changed files with 26 additions and 5 deletions

View File

@ -176,7 +176,18 @@ def module_toptracks(pictures=True,**kwargs):
if tracks != []:
maxbar = max(t["scrobbles"] for t in tracks)
representative = [t["track"] for t in tracks if t["scrobbles"] == maxbar][0]
# track with most #1 positions
max_appear = 0
representatives = list(t["track"] for t in tracks if t["track"] is not None)
for t in representatives:
max_appear = max(max_appear,representatives.count(t))
#representatives.sort(key=lambda reftrack:len([t for t in tracks if t["track"] == reftrack["track"] and t["track"] is not None]))
representatives = [t for t in tracks if representatives.count(t["track"]) == max_appear]
# of these, track with highest scrobbles in its #1 range
representatives.sort(key=lambda t: t["scrobbles"])
representative = representatives[-1]["track"]
else:
representative = None
@ -221,7 +232,17 @@ def module_topartists(pictures=True,**kwargs):
if artists != []:
maxbar = max(a["scrobbles"] for a in artists)
representative = [a["artist"] for a in artists if a["scrobbles"] == maxbar][0]
# artists with most #1 positions
max_appear = 0
representatives = list(a["artist"] for a in artists if a["artist"] is not None)
for a in representatives:
max_appear = max(max_appear,representatives.count(a))
representatives = [a for a in artists if representatives.count(a["artist"]) == max_appear]
# of these, artist with highest scrobbles in their #1 range
representatives.sort(key=lambda a: a["scrobbles"])
representative = representatives[-1]["artist"]
else:
representative = None

View File

@ -1,3 +1,3 @@
*.tsv
*.csv
*.tsv.rulestate
*
!dummy
!.gitignore