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

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] bigpart = [0,1,2,6,15]
smallpart = [0,1,2,4,6,9,12,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>""" html = """<table class="tiles_top"><tr>"""
@ -177,9 +177,18 @@ def module_artistcharts_tiles(**kwargs) :
if i in smallpart: if i in smallpart:
html += "<tr>" 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 "" if e is not None:
link = artistLink(e["artist"]) if e is not None else "" 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>" 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] bigpart = [0,1,2,6,15]
smallpart = [0,1,2,4,6,9,12,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>""" html = """<table class="tiles_top"><tr>"""
@ -222,9 +232,17 @@ def module_trackcharts_tiles(**kwargs) :
if i in smallpart: if i in smallpart:
html += "<tr>" 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 "" if e is not None:
link = trackLink(e["track"]) if e is not None else "" 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>" 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 import hashlib
from threading import Thread from threading import Thread
import pickle import pickle
import urllib
### TSV files ### TSV files
@ -257,7 +258,7 @@ def loadCache():
finally: finally:
fl.close() fl.close()
def getTrackInfo(artists,title): def getTrackInfo(artists,title,fast=False):
obj = (frozenset(artists),title) obj = (frozenset(artists),title)
filename = "-".join([re.sub("[^a-zA-Z0-9]","",artist) for artist in artists]) + "_" + re.sub("[^a-zA-Z0-9]","",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)]} return {"image":cachedTracks[(frozenset(artists),title)]}
except: except:
pass 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) result = apirequest(artists=artists,title=title)
if result.get("image") is not None: if result.get("image") is not None:
@ -289,7 +294,7 @@ def getTrackInfo(artists,title):
#cachedTracks[(frozenset(artists),title)] = result["image"] #cachedTracks[(frozenset(artists),title)] = result["image"]
return result return result
def getArtistInfo(artist): def getArtistInfo(artist,fast=False):
obj = artist obj = artist
filename = re.sub("[^a-zA-Z0-9]","",artist) filename = re.sub("[^a-zA-Z0-9]","",artist)
@ -314,6 +319,11 @@ def getArtistInfo(artist):
except: except:
pass 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) result = apirequest(artist=artist)
if result.get("image") is not None: if result.get("image") is not None:
cachedArtists[artist] = result["image"] cachedArtists[artist] = result["image"]
@ -321,12 +331,12 @@ def getArtistInfo(artist):
else: else:
return {"image":""} return {"image":""}
def getTracksInfo(trackobjectlist): def getTracksInfo(trackobjectlist,fast=False):
threads = [] threads = []
for track in trackobjectlist: 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() t.start()
threads.append(t) threads.append(t)
@ -336,12 +346,12 @@ def getTracksInfo(trackobjectlist):
return [getTrackInfo(t["artists"],t["title"]) for t in trackobjectlist] return [getTrackInfo(t["artists"],t["title"]) for t in trackobjectlist]
def getArtistsInfo(artistlist): def getArtistsInfo(artistlist,fast=False):
threads = [] threads = []
for artist in artistlist: for artist in artistlist:
t = Thread(target=getArtistInfo,args=(artist,)) t = Thread(target=getArtistInfo,args=(artist,),kwargs={"fast":fast})
t.start() t.start()
threads.append(t) threads.append(t)

View File

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