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

Added medals for tracks

This commit is contained in:
Krateng 2019-04-04 21:29:03 +02:00
parent 3a70b0df1a
commit 5c2d9640ac
4 changed files with 37 additions and 12 deletions

View File

@ -34,6 +34,7 @@ SCROBBLESDICT = {} # timestamps to scrobble mapping
STAMPS = [] # sorted
#STAMPS_SET = set() # as set for easier check if exists
MEDALS = {} #literally only changes once per year, no need to calculate that on the fly
MEDALS_TRACKS = {}
cla = CleanerAgent()
coa = CollectorAgent()
@ -492,7 +493,7 @@ def trackInfo(artists,title):
position = charts.index(c)
while position != 0 and c["scrobbles"] == charts[position-1]["scrobbles"]: position -= 1
return {"scrobbles":scrobbles,"position":position + 1}
return {"scrobbles":scrobbles,"position":position + 1,"medals":MEDALS_TRACKS.get((frozenset(artists),title))}

View File

@ -491,26 +491,35 @@ def startpulse():
def yearly():
#medals
from database import MEDALS, STAMPS, get_charts_artists
MEDALS.clear()
from database import MEDALS, MEDALS_TRACKS, STAMPS, get_charts_artists, get_charts_tracks
firstyear = datetime.datetime.utcfromtimestamp(STAMPS[0]).year
currentyear = datetime.datetime.utcnow().year
MEDALS.clear()
for year in range(firstyear,currentyear):
charts = get_charts_artists(within=[year])
scr = -1
rank = 0
for a in charts:
if a["scrobbles"] != scr: rank = charts.index(a) + 1
if rank > 3: break
artist = a["artist"]
if rank == 1: MEDALS.setdefault(artist,{}).setdefault("gold",[]).append(year)
if rank == 2: MEDALS.setdefault(artist,{}).setdefault("silver",[]).append(year)
if rank == 3: MEDALS.setdefault(artist,{}).setdefault("bronze",[]).append(year)
if a["rank"] == 1: MEDALS.setdefault(artist,{}).setdefault("gold",[]).append(year)
elif a["rank"] == 2: MEDALS.setdefault(artist,{}).setdefault("silver",[]).append(year)
elif a["rank"] == 3: MEDALS.setdefault(artist,{}).setdefault("bronze",[]).append(year)
else: break
MEDALS_TRACKS.clear()
for year in range(firstyear,currentyear):
charts = get_charts_tracks(within=[year])
for t in charts:
track = (frozenset(t["track"]["artists"]),t["track"]["title"])
if t["rank"] == 1: MEDALS_TRACKS.setdefault(track,{}).setdefault("gold",[]).append(year)
elif t["rank"] == 2: MEDALS_TRACKS.setdefault(track,{}).setdefault("silver",[]).append(year)
elif t["rank"] == 3: MEDALS_TRACKS.setdefault(track,{}).setdefault("bronze",[]).append(year)
else: break
scr = a["scrobbles"]
# schedule for next year

View File

@ -19,6 +19,7 @@
<p class="stats"><a href="/scrobbles?KEY_SCROBBLELINK">KEY_SCROBBLES Scrobbles</a></p>
<p class="desc"></p>
<span>KEY_MEDALS</span>
</td>
</tr>
</table>

View File

@ -20,13 +20,27 @@ def instructions(keys):
pos = "#" + str(data["position"])
html_medals = ""
if "medals" in data and data["medals"] is not None:
if "gold" in data["medals"]:
for y in data["medals"]["gold"]:
html_medals += "<a title='Best Track in " + str(y) + "' class='hidelink medal gold' href='/charts_tracks?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"
if "silver" in data["medals"]:
for y in data["medals"]["silver"]:
html_medals += "<a title='Second Best Track in " + str(y) + "' class='hidelink medal silver' href='/charts_tracks?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"
if "bronze" in data["medals"]:
for y in data["medals"]["bronze"]:
html_medals += "<a title='Third Best Track in " + str(y) + "' class='hidelink medal bronze' href='/charts_tracks?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"
html_scrobbles, _, _ = module_scrobblelist(track=track,max_=100,earlystop=True) # we have the number already from the trackinfo
html_pulse = module_pulse(track=track,step="year",stepn=1,trail=1)
replace = {"KEY_TRACKTITLE":track.get("title"),"KEY_ARTISTS":artistLinks(track.get("artists")),"KEY_SCROBBLES":scrobblesnum,"KEY_POSITION":pos,"KEY_IMAGEURL":imgurl,
"KEY_SCROBBLELINK":keysToUrl(keys),
"KEY_SCROBBLELINK":keysToUrl(keys),"KEY_MEDALS":html_medals,
"KEY_SCROBBLELIST":html_scrobbles,"KEY_PULSE":html_pulse}
return (replace,pushresources)