def module_artistcharts_tiles(**kwargs): kwargs_filter = pickKeys(kwargs,"associated") #not used right now kwargs_time = pickKeys(kwargs,"timerange","since","to","within") artists = database.get_charts_artists(**kwargs_filter,**kwargs_time)[:14] while len(artists)<14: artists.append(None) i = 1 bigpart = [0,1,2,6,15] smallpart = [0,1,2,4,6,9,12,15] #rnk = (0,0) #temporary store so entries with the same scrobble amount get the same rank html = """<table class="tiles_top"><tr>""" for e in artists: if i in bigpart: n = bigpart.index(i) html += """<td><table class="tiles_""" + str(n) + """x""" + str(n) + """ tiles_sub">""" if i in smallpart: html += "<tr>" if e is not None: html += "<td onclick='window.location.href=\"" \ + link_address(e["artist"]) \ + "\"' style='cursor:pointer;background-image:url(\"" + getArtistImage(e["artist"],fast=True) + "\");'>" \ + "<span class='stats'>" + "#" + str(e["rank"]) + "</span> <span>" + html_link(e["artist"]) + "</span></td>" else: html += "<td><span class='stats'></span> <span></span></td>" i += 1 if i in smallpart: html += "</tr>" if i in bigpart: html += "</table></td>" html += """</tr></table>""" return html
def update_medals(): from database import MEDALS, MEDALS_TRACKS, STAMPS, get_charts_artists, get_charts_tracks firstyear = datetime.datetime.utcfromtimestamp(STAMPS[0]).year currentyear = datetime.datetime.utcnow().year MEDALS.clear() for year in range(firstyear, currentyear): charts = get_charts_artists(within=[year]) for a in charts: artist = a["artist"] if a["rank"] == 1: MEDALS.setdefault(artist, {}).setdefault("gold", []).append(year) elif a["rank"] == 2: MEDALS.setdefault(artist, {}).setdefault("silver", []).append(year) elif a["rank"] == 3: MEDALS.setdefault(artist, {}).setdefault("bronze", []).append(year) else: break MEDALS_TRACKS.clear() for year in range(firstyear, currentyear): charts = get_charts_tracks(within=[year]) for t in charts: track = (frozenset(t["track"]["artists"]), t["track"]["title"]) if t["rank"] == 1: MEDALS_TRACKS.setdefault(track, {}).setdefault("gold", []).append(year) elif t["rank"] == 2: MEDALS_TRACKS.setdefault(track, {}).setdefault("silver", []).append(year) elif t["rank"] == 3: MEDALS_TRACKS.setdefault(track, {}).setdefault("bronze", []).append(year) else: break
def update_weekly(): from database import WEEKLY_TOPTRACKS, WEEKLY_TOPARTISTS, get_charts_artists, get_charts_tracks from malojatime import ranges, thisweek WEEKLY_TOPARTISTS.clear() WEEKLY_TOPTRACKS.clear() for week in ranges(step="week"): if week == thisweek(): break for a in get_charts_artists(timerange=week): artist = a["artist"] if a["rank"] == 1: WEEKLY_TOPARTISTS[artist] = WEEKLY_TOPARTISTS.setdefault( artist, 0) + 1 for t in get_charts_tracks(timerange=week): track = (frozenset(t["track"]["artists"]), t["track"]["title"]) if t["rank"] == 1: WEEKLY_TOPTRACKS[track] = WEEKLY_TOPTRACKS.setdefault( track, 0) + 1
def module_artistcharts(max_=None,**kwargs): kwargs_filter = pickKeys(kwargs,"associated") #not used right now kwargs_time = pickKeys(kwargs,"timerange","since","to","within") artists = database.get_charts_artists(**kwargs_filter,**kwargs_time) # last time range (to compare) try: #from malojatime import _get_next artistslast = database.get_charts_artists(**kwargs_filter,timerange=kwargs_time["timerange"].next(step=-1)) # create rank association lastrank = {} for al in artistslast: lastrank[al["artist"]] = al["rank"] for a in artists: try: a["delta"] = lastrank[a["artist"]] - a["rank"] except: a["delta"] = math.inf except: pass if artists != []: maxbar = artists[0]["scrobbles"] representative = artists[0]["artist"] else: representative = None i = 0 html = "<table class='list'>" for e in artists: i += 1 if max_ is not None and i>max_: break html += "<tr>" # rank if i == 1 or e["scrobbles"] < prev["scrobbles"]: html += "<td class='rank'>#" + str(i) + "</td>" else: html += "<td class='rank'></td>" # rank change #if "within" not in kwargs_time: pass if e.get("delta") is None: pass elif e["delta"] is math.inf: html += "<td class='rankup' title='New'>🆕</td>" elif e["delta"] > 0: html += "<td class='rankup' title='up from #" + str(e["rank"]+e["delta"]) + "'>↗</td>" elif e["delta"] < 0: html += "<td class='rankdown' title='down from #" + str(e["rank"]+e["delta"]) + "'>↘</td>" else: html += "<td class='ranksame' title='Unchanged'>➡</td>" # artist html += entity_column(e["artist"],counting=e["counting"]) # scrobbles html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],internal_to_uri(kwargs_time),amount=e["scrobbles"],associated=True) + "</td>" html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],internal_to_uri(kwargs_time),percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>" html += "</tr>" prev = e html += "</table>" return (html, representative)