Now correctly showing same rank for equally-ranked entries

This commit is contained in:
Krateng 2019-03-03 21:55:35 +01:00
parent 143fe8ef88
commit ca90adc842
3 changed files with 43 additions and 15 deletions

View File

@ -163,7 +163,7 @@ def module_artistcharts_tiles(**kwargs) :
bigpart = [0,1,2,6,15]
smallpart = [0,1,2,4,6,9,12,15]
rnk = (0,0) #temporary store so entries with the same scrobble amount get the same rank
html = """<table class="tiles_top"><tr>"""
@ -177,9 +177,18 @@ def module_artistcharts_tiles(**kwargs) :
if i in smallpart:
html += "<tr>"
rank = "#" + str(i) if e is not None else ""
image = "/image?artist=" + urllib.parse.quote(e["artist"]) if e is not None else ""
link = artistLink(e["artist"]) if e is not None else ""
if e is not None:
rank = i if e["scrobbles"] != rnk[1] else rnk[0]
rnk = (rank,e["scrobbles"])
rank = "#" + str(rank)
image = "/image?artist=" + urllib.parse.quote(e["artist"])
link = artistLink(e["artist"])
else:
rank = ""
image = ""
link = ""
html += """<td style="background-image:url('""" + image + """')"><span class="stats">""" + rank + "</span> <span>" + link + "</span></td>"
@ -208,6 +217,7 @@ def module_trackcharts_tiles(**kwargs) :
bigpart = [0,1,2,6,15]
smallpart = [0,1,2,4,6,9,12,15]
rnk = (0,0) #temporary store so entries with the same scrobble amount get the same rank
html = """<table class="tiles_top"><tr>"""
@ -222,9 +232,17 @@ def module_trackcharts_tiles(**kwargs) :
if i in smallpart:
html += "<tr>"
rank = "#" + str(i) if e is not None else ""
image = "/image?title=" + urllib.parse.quote(e["track"]["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in e["track"]["artists"]]) if e is not None else ""
link = trackLink(e["track"]) if e is not None else ""
if e is not None:
rank = i if e["scrobbles"] != rnk[1] else rnk[0]
rnk = (rank,e["scrobbles"])
rank = "#" + str(rank)
image = "/image?title=" + urllib.parse.quote(e["track"]["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in e["track"]["artists"]])
link = trackLink(e["track"])
else:
rank = ""
image = ""
link = ""
html += """<td style="background-image:url('""" + image + """')"><span class="stats">""" + rank + "</span> <span>" + link + "</span></td>"

View File

@ -3,6 +3,7 @@ import os
import hashlib
from threading import Thread
import pickle
import urllib
### TSV files
@ -257,7 +258,7 @@ def loadCache():
finally:
fl.close()
def getTrackInfo(artists,title):
def getTrackInfo(artists,title,fast=False):
obj = (frozenset(artists),title)
filename = "-".join([re.sub("[^a-zA-Z0-9]","",artist) for artist in artists]) + "_" + re.sub("[^a-zA-Z0-9]","",title)
@ -279,6 +280,10 @@ def getTrackInfo(artists,title):
return {"image":cachedTracks[(frozenset(artists),title)]}
except:
pass
# fast request only retuns cached and local results, generates redirect link for rest
if fast:
return "/image?title=" + urllib.parse.quote(title) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in artists])
result = apirequest(artists=artists,title=title)
if result.get("image") is not None:
@ -289,7 +294,7 @@ def getTrackInfo(artists,title):
#cachedTracks[(frozenset(artists),title)] = result["image"]
return result
def getArtistInfo(artist):
def getArtistInfo(artist,fast=False):
obj = artist
filename = re.sub("[^a-zA-Z0-9]","",artist)
@ -314,6 +319,11 @@ def getArtistInfo(artist):
except:
pass
# fast request only retuns cached and local results, generates redirect link for rest
if fast:
return "/image?artist=" + urllib.parse.quote(artist)
result = apirequest(artist=artist)
if result.get("image") is not None:
cachedArtists[artist] = result["image"]
@ -321,12 +331,12 @@ def getArtistInfo(artist):
else:
return {"image":""}
def getTracksInfo(trackobjectlist):
def getTracksInfo(trackobjectlist,fast=False):
threads = []
for track in trackobjectlist:
t = Thread(target=getTrackInfo,args=(track["artists"],track["title"],))
t = Thread(target=getTrackInfo,args=(track["artists"],track["title"],),kwargs={"fast":fast})
t.start()
threads.append(t)
@ -336,12 +346,12 @@ def getTracksInfo(trackobjectlist):
return [getTrackInfo(t["artists"],t["title"]) for t in trackobjectlist]
def getArtistsInfo(artistlist):
def getArtistsInfo(artistlist,fast=False):
threads = []
for artist in artistlist:
t = Thread(target=getArtistInfo,args=(artist,))
t = Thread(target=getArtistInfo,args=(artist,),kwargs={"fast":fast})
t.start()
threads.append(t)

View File

@ -9,8 +9,8 @@ def instructions(keys):
from utilities import getArtistsInfo, getTracksInfo
from htmlgenerators import artistLink, trackLink
max_show = 14
posrange = ["#" + str(i) for i in range(1,max_show+1)]
# max_show = 14
# posrange = ["#" + str(i) for i in range(1,max_show+1)]
# get chart data