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

Added web views for top artist / track pulse (no idea what to call it)

This commit is contained in:
Krateng 2019-04-02 14:17:19 +02:00
parent c96103ad28
commit 9ed62f91d5
6 changed files with 220 additions and 1 deletions

View File

@ -393,7 +393,7 @@ def get_top_artists(**keys):
for (a,b) in rngs: for (a,b) in rngs:
try: try:
res = db_aggregate(since=a,to=b,by="ARTIST")[0] res = db_aggregate(since=a,to=b,by="ARTIST")[0]
results.append({"from":a,"to":b,"artist":res["artist"],"scrobbles":res["scrobbles"]}) results.append({"from":a,"to":b,"artist":res["artist"],"counting":res["counting"],"scrobbles":res["scrobbles"]})
except: except:
results.append({"from":a,"to":b,"artist":None,"scrobbles":0}) results.append({"from":a,"to":b,"artist":None,"scrobbles":0})

View File

@ -166,6 +166,92 @@ def module_artistcharts(max_=None,**kwargs):
return (html, representative) return (html, representative)
def module_toptracks(**kwargs):
kwargs_filter = pickKeys(kwargs,"artist","associated")
kwargs_time = pickKeys(kwargs,"since","to","within","step","stepn","trail")
tracks = database.get_top_tracks(**kwargs_filter,**kwargs_time)
if tracks != []:
maxbar = max(t["scrobbles"] for t in tracks)
representative = [t["track"] for t in tracks if t["scrobbles"] == maxbar][0]
else:
representative = None
i = 0
html = "<table class='list'>"
for e in tracks:
fromstr = "/".join([str(p) for p in e["from"]])
tostr = "/".join([str(p) for p in e["to"]])
i += 1
html += "<tr>"
html += "<td>" + range_desc(e["from"],e["to"],short=True) + "</td>"
if e["track"] is None:
html += "<td class='stats'>" + "No scrobbles" + "</td>"
html += "<td>" + "" + "</td>"
html += "<td class='amount'>" + "0" + "</td>"
html += "<td class='bar'>" + "" + "</td>"
else:
html += "<td class='artists'>" + artistLinks(e["track"]["artists"]) + "</td>"
html += "<td class='title'>" + trackLink(e["track"]) + "</td>"
html += "<td class='amount'>" + scrobblesTrackLink(e["track"],{"since":fromstr,"to":tostr},amount=e["scrobbles"]) + "</td>"
html += "<td class='bar'>" + scrobblesTrackLink(e["track"],{"since":fromstr,"to":tostr},percent=e["scrobbles"]*100/maxbar) + "</td>"
html += "</tr>"
prev = e
html += "</table>"
return (html,representative)
def module_topartists(**kwargs):
kwargs_time = pickKeys(kwargs,"since","to","within","step","stepn","trail")
artists = database.get_top_artists(**kwargs_time)
if artists != []:
maxbar = max(a["scrobbles"] for a in artists)
representative = [a["artist"] for a in artists if a["scrobbles"] == maxbar][0]
else:
representative = None
i = 0
html = "<table class='list'>"
for e in artists:
fromstr = "/".join([str(p) for p in e["from"]])
tostr = "/".join([str(p) for p in e["to"]])
i += 1
html += "<tr>"
html += "<td>" + range_desc(e["from"],e["to"],short=True) + "</td>"
if e["artist"] is None:
html += "<td class='stats'>" + "No scrobbles" + "</td>"
html += "<td class='amount'>" + "0" + "</td>"
html += "<td class='bar'>" + "" + "</td>"
else:
html += "<td class='artist'>" + artistLink(e["artist"])
if (e["counting"] != []):
html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "</span>"
html += "</td>"
html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],{"since":fromstr,"to":tostr},amount=e["scrobbles"],associated=True) + "</td>"
html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],{"since":fromstr,"to":tostr},percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
html += "</tr>"
prev = e
html += "</table>"
return (html,representative)
def module_artistcharts_tiles(**kwargs): def module_artistcharts_tiles(**kwargs):
kwargs_filter = pickKeys(kwargs,"associated") #not used right now kwargs_filter = pickKeys(kwargs,"associated") #not used right now

View File

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

39
website/chartsartists.py Normal file
View File

@ -0,0 +1,39 @@
import urllib
def instructions(keys):
from utilities import getArtistImage, getTrackImage
from htmlgenerators import artistLink, KeySplit
from htmlmodules import module_topartists, module_filterselection
from malojatime import range_desc
_, timekeys, delimitkeys, _ = KeySplit(keys)
limitstring = ""
html_filterselector = module_filterselection(keys,delimit=True)
html_charts, rep = module_topartists(**timekeys, **delimitkeys)
#if filterkeys.get("artist") is not None:
# imgurl = getArtistImage(filterkeys.get("artist"))
# limitstring = "by " + artistLink(filterkeys.get("artist"))
if rep is not None:
imgurl = getArtistImage(rep)
else:
imgurl = ""
limitstring += " " + range_desc(**timekeys)
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,
"KEY_ARTISTLIST":html_charts,
"KEY_LIMITS":limitstring,
"KEY_FILTERSELECTOR":html_filterselector}
return (replace,pushresources)

29
website/chartstracks.html Normal file
View File

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

36
website/chartstracks.py Normal file
View File

@ -0,0 +1,36 @@
import urllib
def instructions(keys):
from utilities import getArtistImage, getTrackImage
from htmlgenerators import artistLink, KeySplit
from htmlmodules import module_toptracks, module_filterselection
from malojatime import range_desc
filterkeys, timekeys, delimitkeys, _ = KeySplit(keys)
limitstring = ""
html_filterselector = module_filterselection(keys,delimit=True)
html_charts, rep = module_toptracks(**timekeys, **delimitkeys) ### **filterkeys implementing?
#if filterkeys.get("artist") is not None:
# imgurl = getArtistImage(filterkeys.get("artist"))
# limitstring = "by " + artistLink(filterkeys.get("artist"))
if rep is not None:
imgurl = getTrackImage(rep["artists"],rep["title"])
else:
imgurl = ""
limitstring += " " + range_desc(**timekeys)
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
replace = {"KEY_TOPTRACK_IMAGEURL":imgurl,"KEY_TRACKLIST":html_charts,"KEY_LIMITS":limitstring,"KEY_FILTERSELECTOR":html_filterselector}
return (replace,pushresources)