From 9ed62f91d5eb6fd46ed7e054517d6cd2237bd0e6 Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 2 Apr 2019 14:17:19 +0200 Subject: [PATCH] Added web views for top artist / track pulse (no idea what to call it) --- database.py | 2 +- htmlmodules.py | 86 ++++++++++++++++++++++++++++++++++++++ website/chartsartists.html | 29 +++++++++++++ website/chartsartists.py | 39 +++++++++++++++++ website/chartstracks.html | 29 +++++++++++++ website/chartstracks.py | 36 ++++++++++++++++ 6 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 website/chartsartists.html create mode 100644 website/chartsartists.py create mode 100644 website/chartstracks.html create mode 100644 website/chartstracks.py diff --git a/database.py b/database.py index fbd0c36..cd3b359 100644 --- a/database.py +++ b/database.py @@ -393,7 +393,7 @@ def get_top_artists(**keys): for (a,b) in rngs: try: 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: results.append({"from":a,"to":b,"artist":None,"scrobbles":0}) diff --git a/htmlmodules.py b/htmlmodules.py index d29bfd0..bbf0a60 100644 --- a/htmlmodules.py +++ b/htmlmodules.py @@ -166,6 +166,92 @@ def module_artistcharts(max_=None,**kwargs): 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 = "" + 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 += "" + + + html += "" + if e["track"] is None: + html += "" + html += "" + html += "" + html += "" + else: + html += "" + html += "" + html += "" + html += "" + html += "" + prev = e + html += "
" + range_desc(e["from"],e["to"],short=True) + "" + "No scrobbles" + "" + "" + "" + "0" + "" + "" + "" + artistLinks(e["track"]["artists"]) + "" + trackLink(e["track"]) + "" + scrobblesTrackLink(e["track"],{"since":fromstr,"to":tostr},amount=e["scrobbles"]) + "" + scrobblesTrackLink(e["track"],{"since":fromstr,"to":tostr},percent=e["scrobbles"]*100/maxbar) + "
" + + 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 = "" + 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 += "" + + + html += "" + if e["artist"] is None: + html += "" + html += "" + html += "" + else: + html += "" + html += "" + html += "" + html += "" + prev = e + html += "
" + range_desc(e["from"],e["to"],short=True) + "" + "No scrobbles" + "" + "0" + "" + "" + "" + artistLink(e["artist"]) + if (e["counting"] != []): + html += " incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "" + html += "" + scrobblesArtistLink(e["artist"],{"since":fromstr,"to":tostr},amount=e["scrobbles"],associated=True) + "" + scrobblesArtistLink(e["artist"],{"since":fromstr,"to":tostr},percent=e["scrobbles"]*100/maxbar,associated=True) + "
" + + return (html,representative) + + def module_artistcharts_tiles(**kwargs): kwargs_filter = pickKeys(kwargs,"associated") #not used right now diff --git a/website/chartsartists.html b/website/chartsartists.html new file mode 100644 index 0000000..3ec5bea --- /dev/null +++ b/website/chartsartists.html @@ -0,0 +1,29 @@ + + + + + + Maloja - Favorite Artists + + + + + + + + +
+
+
+

Favorite Artists


+ KEY_LIMITS + +

+ KEY_FILTERSELECTOR +
+ + + KEY_ARTISTLIST + + + diff --git a/website/chartsartists.py b/website/chartsartists.py new file mode 100644 index 0000000..2476159 --- /dev/null +++ b/website/chartsartists.py @@ -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) diff --git a/website/chartstracks.html b/website/chartstracks.html new file mode 100644 index 0000000..e74211b --- /dev/null +++ b/website/chartstracks.html @@ -0,0 +1,29 @@ + + + + + + Maloja - Favorite Tracks + + + + + + + + +
+
+
+

Favorite Tracks


+ KEY_LIMITS + +

+ KEY_FILTERSELECTOR +
+ + + KEY_TRACKLIST + + + diff --git a/website/chartstracks.py b/website/chartstracks.py new file mode 100644 index 0000000..565b1eb --- /dev/null +++ b/website/chartstracks.py @@ -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)