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

Experimental performance web view

This commit is contained in:
Krateng 2019-04-09 13:34:06 +02:00
parent b3423dabcf
commit 9846fd9952
7 changed files with 187 additions and 13 deletions

View File

@ -92,6 +92,29 @@ def scrobblesLink(timekeys,amount=None,percent=None,artist=None,track=None,assoc
def rankTrackLink(track,timekeys,rank=None,percent=None,medal=None):
cl = ""
if medal == 1: cl = "class='gold'"
if medal == 2: cl = "class='silver'"
if medal == 3: cl = "class='bronze'"
inner = str(rank) if rank is not None else "<div " + cl + " style='width:" + str(percent) + "%;'></div>"
return "<a href='/charts_tracks?" + compose_querystring(timekeys) + "'>" + inner + "</a>"
def rankArtistLink(artist,timekeys,rank=None,percent=None,medal=None):
cl = ""
if medal == 1: cl = "class='gold'"
if medal == 2: cl = "class='silver'"
if medal == 3: cl = "class='bronze'"
inner = str(rank) if rank is not None else "<div " + cl + " style='width:" + str(percent) + "%;'></div>"
return "<a " + cl + " href='/charts_artists?" + compose_querystring(timekeys) + "'>" + inner + "</a>"
def rankLink(timekeys,rank=None,percent=None,artist=None,track=None,medal=None):
if track is not None: return rankTrackLink(track,timekeys,rank,percent,medal)
if artist is not None: return rankArtistLink(artist,timekeys,rank,percent,medal)
# limit a multidict to only the specified keys
# would be a simple constructor expression, but multidicts apparently don't let me do that
def pickKeys(d,*keys):

View File

@ -93,6 +93,45 @@ def module_pulse(max_=None,**kwargs):
return html
def module_performance(max_=None,**kwargs):
kwargs_filter = pickKeys(kwargs,"artist","track")
kwargs_time = pickKeys(kwargs,"since","to","within","step","stepn","trail")
ranges = database.get_performance(**kwargs_time,**kwargs_filter)
if max_ is not None: ranges = ranges[:max_]
# if time range not explicitly specified, only show from first appearance
# if "since" not in kwargs:
# while ranges[0]["scrobbles"] == 0:
# del ranges[0]
minrank = 80
for t in ranges:
if t["rank"] is not None and t["rank"] > minrank: minrank = t["rank"]
#build list
html = "<table class='list'>"
for t in ranges:
fromstr = "/".join([str(e) for e in t["from"]])
tostr = "/".join([str(e) for e in t["to"]])
html += "<tr>"
html += "<td>" + range_desc(t["from"],t["to"],short=True) + "</td>"
html += "<td class='rank'>" + ("#" + str(t["rank"]) if t["rank"] is not None else "No scrobbles") + "</td>"
prct = (minrank+1-t["rank"])*100/minrank if t["rank"] is not None else 0
html += "<td class='chart'>" + rankLink({"since":fromstr,"to":tostr},percent=prct,**kwargs_filter,medal=t["rank"]) + "</td>"
html += "</tr>"
html += "</table>"
return html
def module_trackcharts(max_=None,**kwargs):
kwargs_filter = pickKeys(kwargs,"artist","associated")

View File

@ -20,13 +20,13 @@ def instructions(keys):
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 Artist in " + str(y) + "' class='hidelink medal gold' href='/charts_artists?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"
html_medals += "<a title='Best Artist in " + str(y) + "' class='hidelink medal shiny gold' href='/charts_artists?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 Artist in " + str(y) + "' class='hidelink medal silver' href='/charts_artists?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"
html_medals += "<a title='Second Best Artist in " + str(y) + "' class='hidelink medal shiny silver' href='/charts_artists?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 Artist in " + str(y) + "' class='hidelink medal bronze' href='/charts_artists?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"
html_medals += "<a title='Third Best Artist in " + str(y) + "' class='hidelink medal shiny bronze' href='/charts_artists?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"
credited = data.get("replace")
includestr = " "

View File

@ -305,16 +305,18 @@ span.stat_selector_pulse,span.stat_selector_topartists,span.stat_selector_toptra
/* SHINY*/
.medal {
top:5px;
position:relative;
overflow: hidden;
display: inline-block;
font-size:80%;
padding:3px;
margin:2px;
border-radius:2px;
}
.medal:after {
.shiny {
overflow: hidden;
position:relative;
display: inline-block;
}
.shiny:after {
content: "";
position: absolute;
top: -110%;
@ -333,7 +335,7 @@ span.stat_selector_pulse,span.stat_selector_topartists,span.stat_selector_toptra
rgba(255, 255, 255, 0.0) 100%
);
}
.medal:hover:after {
.shiny:hover:after {
opacity: 1;
top: -30%;
left: -30%;
@ -341,7 +343,7 @@ span.stat_selector_pulse,span.stat_selector_topartists,span.stat_selector_toptra
transition-duration: 0.7s, 0.7s, 0.15s;
transition-timing-function: ease;
}
.medal:active:after {
.shiny:active:after {
opacity: 0;
}
@ -502,6 +504,33 @@ table.list tr:hover td.bar div {
cursor:pointer;
}
table.list td.chart {
width:500px;
background-color:#333337;
/* Remove 5er separators for bars */
/*border-color:rgba(0,0,0,0)!important;*/
}
table.list td.chart div {
background-color:beige;
height:20px; /* can only do this absolute apparently */
position:relative;
}
table.list tr:hover td.chart div {
cursor:pointer;
}
table.list tr td.chart div.gold {
background-color:gold;
}
table.list tr td.chart div.silver {
background-color:silver;
}
table.list tr td.chart div.bronze {
background-color:#cd7f32;
}
table.list tr td.button {
width:200px;
cursor:pointer;

29
website/performance.html Normal file
View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Maloja - KEY_PULSEDETAILS Performance</title>
</head>
<body>
<table class="top_info">
<tr>
<td class="image">
<div style="background-image:url('KEY_IMAGEURL')"></div>
</td>
<td class="text">
<h1>KEY_PULSEDETAILS Performance</h1><br/>
<span>KEY_LIMITS</span>
<!--<p class="stats">KEY_SCROBBLES Scrobbles</p>-->
<br/><br/>
KEY_FILTERSELECTOR
</td>
</tr>
</table>
KEY_PERFORMANCE_TABLE
</body>
</html>

54
website/performance.py Normal file
View File

@ -0,0 +1,54 @@
import urllib
import database
def instructions(keys):
from utilities import getArtistImage, getTrackImage
from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesLink
from urihandler import compose_querystring, uri_to_internal
from htmlmodules import module_performance, module_filterselection
from malojatime import range_desc, delimit_desc
filterkeys, timekeys, delimitkeys, _ = uri_to_internal(keys)
# describe the scope (and creating a key for the relevant artist or track)
limitstring = ""
#limitkey = {}
if filterkeys.get("track") is not None:
#limitkey["track"] = {"artists":keys.getall("artist"),"title":keys.get("title")}
limitstring += "of " + trackLink(filterkeys["track"]) + " "
limitstring += "by " + artistLinks(filterkeys["track"]["artists"])
elif filterkeys.get("artist") is not None:
#limitkey["artist"], limitkey["associated"] = keys.get("artist"), (keys.get("associated")!=None)
limitstring += "of " + artistLink(filterkeys.get("artist"))
limitstring += " " + range_desc(**timekeys)
delimitstring = delimit_desc(**delimitkeys)
html_filterselector = module_filterselection(keys,delimit=True)
# get image
if filterkeys.get("track") is not None:
imgurl = getTrackImage(filterkeys.get("track")["artists"],filterkeys.get("track")["title"])
elif filterkeys.get("artist") is not None:
imgurl = getArtistImage(keys.get("artist"))
else:
imgurl = ""
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
html_performance = module_performance(**filterkeys,**timekeys,**delimitkeys)
replace = {"KEY_PERFORMANCE_TABLE":html_performance,
"KEY_IMAGEURL":imgurl,
"KEY_LIMITS":limitstring,
"KEY_PULSEDETAILS":delimitstring,
"KEY_FILTERSELECTOR":html_filterselector}
return (replace,pushresources)

View File

@ -25,13 +25,13 @@ def instructions(keys):
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>"
html_medals += "<a title='Best Track in " + str(y) + "' class='hidelink medal shiny 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>"
html_medals += "<a title='Second Best Track in " + str(y) + "' class='hidelink medal shiny 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_medals += "<a title='Third Best Track in " + str(y) + "' class='hidelink medal shiny bronze' href='/charts_tracks?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"