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 += "" + range_desc(e["from"],e["to"],short=True) + " | "
+ if e["track"] is None:
+ html += "" + "No scrobbles" + " | "
+ html += "" + "" + " | "
+ html += "" + "0" + " | "
+ html += "" + "" + " | "
+ else:
+ html += "" + artistLinks(e["track"]["artists"]) + " | "
+ html += "" + trackLink(e["track"]) + " | "
+ html += "" + scrobblesTrackLink(e["track"],{"since":fromstr,"to":tostr},amount=e["scrobbles"]) + " | "
+ html += "" + scrobblesTrackLink(e["track"],{"since":fromstr,"to":tostr},percent=e["scrobbles"]*100/maxbar) + " | "
+ html += "
"
+ prev = e
+ html += "
"
+
+ 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 += "" + range_desc(e["from"],e["to"],short=True) + " | "
+ if e["artist"] is None:
+ html += "" + "No scrobbles" + " | "
+ html += "" + "0" + " | "
+ html += "" + "" + " | "
+ else:
+ html += "" + artistLink(e["artist"])
+ if (e["counting"] != []):
+ html += " "
+ html += " | "
+ html += "" + scrobblesArtistLink(e["artist"],{"since":fromstr,"to":tostr},amount=e["scrobbles"],associated=True) + " | "
+ html += "" + scrobblesArtistLink(e["artist"],{"since":fromstr,"to":tostr},percent=e["scrobbles"]*100/maxbar,associated=True) + " | "
+ html += "
"
+ prev = e
+ html += "
"
+
+ 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)