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

Added medals

This commit is contained in:
Krateng 2019-04-02 16:53:57 +02:00
parent 632aa2a8d7
commit 45e9586951
4 changed files with 71 additions and 4 deletions

View File

@ -33,6 +33,7 @@ TRACKS = [] # Format: tuple(frozenset(artist_ref,...),title)
SCROBBLESDICT = {} # timestamps to scrobble mapping SCROBBLESDICT = {} # timestamps to scrobble mapping
STAMPS = [] # sorted STAMPS = [] # sorted
#STAMPS_SET = set() # as set for easier check if exists #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
cla = CleanerAgent() cla = CleanerAgent()
coa = CollectorAgent() coa = CollectorAgent()
@ -461,7 +462,7 @@ def artistInfo(artist):
others = coa.getAllAssociated(artist) others = coa.getAllAssociated(artist)
position = charts.index(c) position = charts.index(c)
while position != 0 and c["scrobbles"] == charts[position-1]["scrobbles"]: position -= 1 while position != 0 and c["scrobbles"] == charts[position-1]["scrobbles"]: position -= 1
return {"scrobbles":scrobbles,"position":position + 1,"associated":others} return {"scrobbles":scrobbles,"position":position + 1,"associated":others,"medals":MEDALS.get(artist)}
except: except:
# if the artist isnt in the charts, they are not being credited and we need to show information about the credited one # if the artist isnt in the charts, they are not being credited and we need to show information about the credited one
artist = coa.getCredited(artist) artist = coa.getCredited(artist)
@ -787,6 +788,32 @@ def build_db():
# load cached images # load cached images
#loadCache() #loadCache()
#medals
global MEDALS
firstyear = datetime.datetime.utcfromtimestamp(STAMPS[0]).year
currentyear = datetime.datetime.utcnow().year
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)
scr = a["scrobbles"]
print(MEDALS)
log("Database fully built!") log("Database fully built!")

View File

@ -13,7 +13,10 @@
<div style="background-image:url('KEY_IMAGEURL')"></div> <div style="background-image:url('KEY_IMAGEURL')"></div>
</td> </td>
<td class="text"> <td class="text">
<h1>KEY_ARTISTNAME</h1> <span class="rank"><a href="/charts_artists?max=100">KEY_POSITION</a></span><br/> <h1>KEY_ARTISTNAME</h1>
<span class="rank"><a href="/charts_artists?max=100">KEY_POSITION</a></span>
<span>KEY_MEDALS</span>
<br/>
<span>KEY_ASSOCIATED</span> <span>KEY_ASSOCIATED</span>
<p class="stats"><a href="/scrobbles?artist=KEY_ENC_ARTISTNAME">KEY_SCROBBLES Scrobbles</a></p> <p class="stats"><a href="/scrobbles?artist=KEY_ENC_ARTISTNAME">KEY_SCROBBLES Scrobbles</a></p>

View File

@ -15,6 +15,18 @@ def instructions(keys):
scrobbles = str(data["scrobbles"]) scrobbles = str(data["scrobbles"])
pos = "#" + str(data["position"]) 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 += "<span title='Best Artist in " + str(y) + "' class='gold'><a href='/charts_artists?max=50&in=" + str(y) + "'>" + str(y) + "</a></span>"
if "silver" in data["medals"]:
for y in data["medals"]["silver"]:
html_medals += "<span title='Second Best Artist in " + str(y) + "' class='silver'><a href='/charts_artists?max=50&in=" + str(y) + "'>" + str(y) + "</a></span>"
if "bronze" in data["medals"]:
for y in data["medals"]["bronze"]:
html_medals += "<span title='Third Best Artist in " + str(y) + "' class='bronze'><a href='/charts_artists?max=50&in=" + str(y) + "'>" + str(y) + "</a></span>"
credited = data.get("replace") credited = data.get("replace")
includestr = " " includestr = " "
if credited is not None: if credited is not None:
@ -32,7 +44,7 @@ def instructions(keys):
html_pulse = module_pulse(**filterkeys,step="year",stepn=1,trail=1) html_pulse = module_pulse(**filterkeys,step="year",stepn=1,trail=1)
replace = {"KEY_ARTISTNAME":keys["artist"],"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]), replace = {"KEY_ARTISTNAME":keys["artist"],"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]),
"KEY_IMAGEURL":imgurl, "KEY_DESCRIPTION":"", "KEY_IMAGEURL":imgurl, "KEY_DESCRIPTION":"","KEY_MEDALS":html_medals,
"KEY_TRACKLIST":html_tracks,"KEY_PULSE":html_pulse, "KEY_TRACKLIST":html_tracks,"KEY_PULSE":html_pulse,
"KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos, "KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos,
"KEY_ASSOCIATED":includestr} "KEY_ASSOCIATED":includestr}

View File

@ -248,6 +248,31 @@ span.stat_selector_pulse,span.stat_selector_topartists,span.stat_selector_toptra
.gold,.silver,.bronze {
font-size:80%;
padding:3px;
margin:2px;
border-radius:2px;
}
.gold a:hover,.silver a:hover,.bronze a:hover {
text-decoration:none;
}
.gold {
background-color:gold;
color:black;
}
.silver {
background-color:silver;
color:black;
}
.bronze {
background-color:darkred;
color:black;
}
/* /*
** **