Beispiel #1
0
def instructions(keys):
    from utilities import getArtistImage
    from urihandler import compose_querystring, uri_to_internal
    from htmlmodules import module_artistcharts, module_filterselection
    from malojatime import range_desc

    _, timekeys, _, amountkeys = uri_to_internal(keys)

    limitstring = timekeys["timerange"].desc(prefix=True)

    html_filterselector = module_filterselection(keys)

    html_charts, rep = module_artistcharts(**amountkeys, **timekeys)

    if rep is not None:
        imgurl = getArtistImage(rep)
    else:
        imgurl = ""

    pushresources = [{
        "file": imgurl,
        "type": "image"
    }] if imgurl.startswith("/") else []

    replace = {
        "KEY_TOPARTIST_IMAGEURL": imgurl,
        "KEY_ARTISTLIST": html_charts,
        "KEY_RANGE": limitstring,
        "KEY_FILTERSELECTOR": html_filterselector
    }

    return (replace, pushresources)
Beispiel #2
0
def module_topartists(pictures=True,**kwargs):

	kwargs_time = pickKeys(kwargs,"timerange","since","to","within","step","stepn","trail")

	artists = database.get_top_artists(**kwargs_time)

	if artists != []:
		maxbar = max(a["scrobbles"] for a in artists)

		# artists with most #1 positions
		max_appear = 0
		representatives = list(a["artist"] for a in artists if a["artist"] is not None)
		for a in representatives:
			max_appear = max(max_appear,representatives.count(a))
		representatives = [a for a in artists if representatives.count(a["artist"]) == max_appear]
		# of these, artist with highest scrobbles in their #1 range
		representatives.sort(key=lambda a: a["scrobbles"])

		representative = representatives[-1]["artist"]
	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"]])
		range = e["range"]

		i += 1
		html += "<tr>"


		html += "<td>" + range.desc() + "</td>"

		if e["artist"] is None:
			if pictures:
				html += "<td><div></div></td>"
			html += "<td class='stats'>" + "No scrobbles" + "</td>"
			html += "<td class='amount'>" + "0" + "</td>"
			html += "<td class='bar'>" + "" + "</td>"
		else:
			if pictures:
				img = getArtistImage(e["artist"],fast=True)
			else: img = None
			html += entity_column(e["artist"],image=img)
			html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],range.urikeys(),amount=e["scrobbles"],associated=True) + "</td>"
			html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],range.urikeys(),percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
		html += "</tr>"
		prev = e
	html += "</table>"

	return (html,representative)
Beispiel #3
0
def instructions(keys):
	from utilities import getArtistImage, getTrackImage
	from htmlgenerators import artistLink, artistLinks, trackLink
	from urihandler import compose_querystring, uri_to_internal
	from htmlmodules import module_scrobblelist, module_filterselection
	from malojatime import range_desc


	filterkeys, timekeys, _, amountkeys = uri_to_internal(keys)

	# describe the scope
	limitstring = ""
	if filterkeys.get("track") is not None:
		limitstring += "of " + trackLink(filterkeys["track"]) + " "
		limitstring += "by " + artistLinks(filterkeys["track"]["artists"])

	elif filterkeys.get("artist") is not None:
		limitstring += "by " + artistLink(filterkeys.get("artist"))
		if filterkeys.get("associated"):
			data = database.artistInfo(filterkeys["artist"])
			moreartists = data.get("associated")
			if moreartists != []:
				limitstring += " <span class='extra'>including " + artistLinks(moreartists) + "</span>"

	limitstring += " " + timekeys["timerange"].desc(prefix=True)

	html_filterselector = module_filterselection(keys)


	html, amount, rep = module_scrobblelist(**filterkeys,**timekeys,**amountkeys)

	# get image
	if filterkeys.get("track") is not None:
		imgurl = getTrackImage(filterkeys.get("track")["artists"],filterkeys.get("track")["title"],fast=True)
	elif filterkeys.get("artist") is not None:
		imgurl = getArtistImage(keys.get("artist"),fast=True)
	elif rep is not None:
		imgurl = getTrackImage(rep["artists"],rep["title"],fast=True)
	else:
		imgurl = ""


	pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []


	replace = {"KEY_SCROBBLELIST":html,
	"KEY_SCROBBLES":str(amount),
	"KEY_IMAGEURL":imgurl,
	"KEY_LIMITS":limitstring,
	"KEY_FILTERSELECTOR":html_filterselector}

	return (replace,pushresources)
Beispiel #4
0
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
Beispiel #5
0
def instructions(keys):
    from utilities import getArtistImage, getTrackImage
    from htmlgenerators import artistLink
    from urihandler import compose_querystring, uri_to_internal
    from htmlmodules import module_trackcharts, module_filterselection
    from malojatime import range_desc

    filterkeys, timekeys, _, amountkeys = uri_to_internal(keys)

    if len(filterkeys) == 0:
        toptrackslink = "<a href='/top_tracks'><span>View #1 Tracks</span></a>"
    else:
        toptrackslink = ""

    limitstring = ""

    html_filterselector = module_filterselection(keys)

    html_charts, rep = module_trackcharts(**amountkeys, **timekeys,
                                          **filterkeys)

    if filterkeys.get("artist") is not None:
        imgurl = getArtistImage(filterkeys.get("artist"))
        limitstring = "by " + artistLink(filterkeys.get("artist"))
    elif rep is not None:
        imgurl = getTrackImage(rep["artists"], rep["title"])
    else:
        imgurl = ""

    limitstring += " " + timekeys["timerange"].desc(prefix=True)

    pushresources = [{
        "file": imgurl,
        "type": "image"
    }] if imgurl.startswith("/") else []

    replace = {
        "KEY_TOPARTIST_IMAGEURL": imgurl,
        "KEY_TRACKLIST": html_charts,
        "KEY_LIMITS": limitstring,
        "KEY_FILTERSELECTOR": html_filterselector,
        "TOP_TRACKS_LINK": toptrackslink,
    }

    return (replace, pushresources)
Beispiel #6
0
def instructions(keys):
    from utilities import getArtistImage, getTrackImage
    from htmlgenerators import artistLink
    from urihandler import compose_querystring, uri_to_internal
    from htmlmodules import module_topartists, module_filterselection
    from malojatime import range_desc

    _, timekeys, delimitkeys, _ = uri_to_internal(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 += " " + timekeys["timerange"].desc(prefix=True)

    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)
Beispiel #7
0
def instructions(keys):
	from utilities import getArtistImage
	from htmlgenerators import artistLink, artistLinks, link_address
	from urihandler import compose_querystring, uri_to_internal
	from htmlmodules import module_pulse, module_performance, module_trackcharts, module_scrobblelist

	filterkeys, _, _, _ = uri_to_internal(keys,forceArtist=True)
	artist = filterkeys.get("artist")
	imgurl = getArtistImage(filterkeys["artist"],fast=True)
	pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []

	data = database.artistInfo(filterkeys["artist"])
	scrobbles = str(data["scrobbles"])
	pos = "#" + str(data["position"])

	html_medals = ""
	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 shiny gold' href='/charts_artists?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 shiny silver' href='/charts_artists?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 shiny bronze' href='/charts_artists?in=" + str(y) + "'><span>" + str(y) + "</span></a>"

	html_cert = ""
	for track in database.get_tracks(artist=artist):
		info = database.trackInfo(track)
		if info.get("certification") is not None:
			img = "/media/record_{cert}.png".format(cert=info["certification"])
			trackname = track["title"].replace("'","&#39;")
			tracklink = link_address(track)
			tooltip = "{title} has reached {cert} status".format(title=trackname,cert=info["certification"].capitalize())
			html_cert += "<a href='{link}'><img class='certrecord_small' src='{img}' title='{tooltip}' /></a>".format(tooltip=tooltip,img=img,link=tracklink)


	html_topweeks = ""
	if data.get("topweeks") not in [0,None]:
		link = "/performance?artist=" + urllib.parse.quote(keys["artist"]) + "&trail=1&step=week"
		title = str(data["topweeks"]) + " weeks on #1"
		html_topweeks = "<a title='" + title + "' href='" + link + "'><img class='star' src='/media/star.png' />" + str(data["topweeks"]) + "</a>"


	credited = data.get("replace")
	includestr = " "
	if credited is not None:
		includestr = "Competing under " + artistLink(credited) + " (" + pos + ")"
		pos = ""
	else:
		credited = artist
	included = data.get("associated")
	if included is not None and included != []:
		includestr = "associated: "
		includestr += artistLinks(included)


	html_tracks, _ = module_trackcharts(**filterkeys,max_=15)

	html_scrobbles, _, _ = module_scrobblelist(artist=artist,max_=10,earlystop=True)

	# pulse and rankings
	html_pulse_days = module_pulse(**filterkeys,max_=7,since=today().next(-6),step="day",trail=1)
	html_pulse_weeks = module_pulse(**filterkeys,max_=12,since=thisweek().next(-11),step="week",trail=1)
	html_pulse_months = module_pulse(**filterkeys,max_=12,since=thismonth().next(-11),step="month",trail=1)
	html_pulse_years = module_pulse(**filterkeys,max_=10,since=thisyear().next(-9),step="year",trail=1)

	html_performance_days = module_performance(artist=credited,max_=7,since=today().next(-6),step="day",trail=1)
	html_performance_weeks = module_performance(artist=credited,max_=12,since=thisweek().next(-11),step="week",trail=1)
	html_performance_months = module_performance(artist=credited,max_=12,since=thismonth().next(-11),step="month",trail=1)
	html_performance_years = module_performance(artist=credited,max_=10,since=thisyear().next(-9),step="year",trail=1)

	replace = {
		# info
		"KEY_ARTISTNAME":keys["artist"],
		"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]),
		"KEY_ENC_CREDITEDARTISTNAME":urllib.parse.quote(credited),
		"KEY_IMAGEURL":imgurl,
		"KEY_DESCRIPTION":"",
		"KEY_SCROBBLES":scrobbles,
		"KEY_POSITION":pos,
		"KEY_ASSOCIATED":includestr,
		"KEY_MEDALS":html_medals,
		"KEY_CERTS":html_cert,
		"KEY_TOPWEEKS":html_topweeks,
		# tracks
		"KEY_TRACKLIST":html_tracks,
		# pulse
		"KEY_PULSE_MONTHS":html_pulse_months,
		"KEY_PULSE_YEARS":html_pulse_years,
		"KEY_PULSE_DAYS":html_pulse_days,
		"KEY_PULSE_WEEKS":html_pulse_weeks,
		# performance
		"KEY_PERFORMANCE_MONTHS":html_performance_months,
		"KEY_PERFORMANCE_YEARS":html_performance_years,
		"KEY_PERFORMANCE_DAYS":html_performance_days,
		"KEY_PERFORMANCE_WEEKS":html_performance_weeks,
		# scrobbles
		"KEY_SCROBBLELIST":html_scrobbles,
		"KEY_SCROBBLELINK":compose_querystring(keys),

	}

	return (replace,pushresources)
Beispiel #8
0
def instructions(keys):

	compareto = keys.get("to")
	compareurl = compareto + "/api/info"

	response = urllib.request.urlopen(compareurl)
	strangerinfo = json.loads(response.read())

	owninfo = database.info()

	artists = {}

	for a in owninfo["artists"]:
		artists[a.lower()] = {"name":a,"self":int(owninfo["artists"][a]*1000),"other":0}

	for a in strangerinfo["artists"]:
		artists[a.lower()] = artists.setdefault(a.lower(),{"name":a,"self":0})
		artists[a.lower()]["other"] = int(strangerinfo["artists"][a]*1000)

	for a in artists:
		common = min(artists[a]["self"],artists[a]["other"])
		artists[a]["self"] -= common
		artists[a]["other"] -= common
		artists[a]["common"] = common

	best = sorted((artists[a]["name"] for a in artists),key=lambda x: artists[x.lower()]["common"],reverse=True)

	result = {
		"unique_self":sum(artists[a]["self"] for a in artists if artists[a]["common"] == 0),
		"more_self":sum(artists[a]["self"] for a in artists if artists[a]["common"] != 0),
	#	"common":{
	#		**{
	#			artists[a]["name"]:artists[a]["common"]
	#		for a in best[:3]},
	#	None: sum(artists[a]["common"] for a in artists if a not in best[:3])
	#	},
		"common":sum(artists[a]["common"] for a in artists),
		"more_other":sum(artists[a]["other"] for a in artists if artists[a]["common"] != 0),
		"unique_other":sum(artists[a]["other"] for a in artists if artists[a]["common"] == 0)
	}

	total = sum(result[c] for c in result)

	percentages = {c:result[c]*100/total for c in result}
	css = []

	cumulative = 0
	for color,category in [
		("rgba(255,255,255,0.2)","unique_self"),
		("rgba(255,255,255,0.5)","more_self"),
		("white","common"),
		("rgba(255,255,255,0.5)","more_other"),
		("rgba(255,255,255,0.2)","unique_other")]:
		cumulative += percentages[category]
		css.append(color + " " + str(cumulative) + "%")


	fullmatch = percentages["common"]
	partialmatch = percentages["more_self"] + percentages["more_other"]

	match = fullmatch + (partialmatch)/2
	pixel_fullmatch = fullmatch * 2.5
	pixel_partialmatch = (fullmatch+partialmatch) * 2.5

	match = min(match,100)


	matchcolor = format(int(min(1,match/50)*255),"02x") * 2 + format(int(max(0,match/50-1)*255),"02x")


	return {
		"KEY_CIRCLE_CSS":",".join(css),
		"KEY_CICLE_COLOR":matchcolor,
		"KEY_MATCH":str(round(match,2)),
		"KEY_FULLMATCH":str(int(pixel_fullmatch)),
		"KEY_PARTIALMATCH":str(int(pixel_partialmatch)),
		"KEY_NAME_SELF":owninfo["name"],
		"KEY_NAME_OTHER":strangerinfo["name"],
		"KEY_BESTARTIST_LINK":artistLink(best[0]),
		"KEY_BESTARTIST_IMAGE":getArtistImage(best[0])
	},[]
Beispiel #9
0
def instructions(keys):
    from utilities import getArtistImage, getTrackImage
    from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesLink
    from urihandler import compose_querystring, uri_to_internal, internal_to_uri
    from htmlmodules import module_performance, module_filterselection
    from malojatime import range_desc, delimit_desc

    filterkeys, timekeys, delimitkeys, paginatekeys = uri_to_internal(keys)

    #equivalent pulse chart
    pulselink_keys = internal_to_uri({
        **filterkeys,
        **timekeys,
        **delimitkeys,
        **paginatekeys
    })
    pulselink = "/pulse?" + compose_querystring(pulselink_keys)

    pulselink = "<a href=\"" + pulselink + "\"><span>View Pulse</span></a>"

    # 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"))
        # associated are counted by default
        data = database.artistInfo(filterkeys["artist"])
        moreartists = data["associated"]
        if moreartists != []:
            limitstring += " <span class='extra'>including " + artistLinks(
                moreartists) + "</span>"

    limitstring += " " + timekeys["timerange"].desc(prefix=True)

    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, **paginatekeys)

    replace = {
        "KEY_PULSE_LINK": pulselink,
        "KEY_PERFORMANCE_TABLE": html_performance,
        "KEY_IMAGEURL": imgurl,
        "KEY_LIMITS": limitstring,
        "KEY_PULSEDETAILS": delimitstring,
        "KEY_FILTERSELECTOR": html_filterselector
    }

    return (replace, pushresources)
Beispiel #10
0
def instructions(keys):
	from utilities import getArtistImage
	from htmlgenerators import artistLink, artistLinks
	from urihandler import compose_querystring, uri_to_internal
	from htmlmodules import module_pulse, module_performance, module_trackcharts, module_scrobblelist

	filterkeys, _, _, _ = uri_to_internal(keys,forceArtist=True)
	artist = filterkeys.get("artist")
	imgurl = getArtistImage(filterkeys["artist"],fast=True)
	pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []

	data = database.artistInfo(filterkeys["artist"])
	scrobbles = str(data["scrobbles"])
	pos = "#" + str(data["position"])

	html_medals = ""
	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 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 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 shiny bronze' href='/charts_artists?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>"

	credited = data.get("replace")
	includestr = " "
	if credited is not None:
		includestr = "Competing under " + artistLink(credited) + " (" + pos + ")"
		pos = ""
	else:
		credited = artist
	included = data.get("associated")
	if included is not None and included != []:
		includestr = "associated: "
		includestr += artistLinks(included)


	html_tracks, _ = module_trackcharts(**filterkeys,max_=15)

	html_scrobbles, _, _ = module_scrobblelist(artist=artist,max_=10,earlystop=True)

	# pulse and rankings
	html_pulse_days = module_pulse(**filterkeys,max_=7,since=today().next(-6),step="day",trail=1)
	html_pulse_weeks = module_pulse(**filterkeys,max_=12,since=thisweek().next(-11),step="week",trail=1)
	html_pulse_months = module_pulse(**filterkeys,max_=12,since=thismonth().next(-11),step="month",trail=1)
	html_pulse_years = module_pulse(**filterkeys,max_=10,since=thisyear().next(-9),step="year",trail=1)

	html_performance_days = module_performance(artist=credited,max_=7,since=today().next(-6),step="day",trail=1)
	html_performance_weeks = module_performance(artist=credited,max_=12,since=thisweek().next(-11),step="week",trail=1)
	html_performance_months = module_performance(artist=credited,max_=12,since=thismonth().next(-11),step="month",trail=1)
	html_performance_years = module_performance(artist=credited,max_=10,since=thisyear().next(-9),step="year",trail=1)

	replace = {
		# info
		"KEY_ARTISTNAME":keys["artist"],
		"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]),
		"KEY_ENC_CREDITEDARTISTNAME":urllib.parse.quote(credited),
		"KEY_IMAGEURL":imgurl,
		"KEY_DESCRIPTION":"",
		"KEY_SCROBBLES":scrobbles,
		"KEY_POSITION":pos,
		"KEY_ASSOCIATED":includestr,
		"KEY_MEDALS":html_medals,
		# tracks
		"KEY_TRACKLIST":html_tracks,
		# pulse
		"KEY_PULSE_MONTHS":html_pulse_months,
		"KEY_PULSE_YEARS":html_pulse_years,
		"KEY_PULSE_DAYS":html_pulse_days,
		"KEY_PULSE_WEEKS":html_pulse_weeks,
		# performance
		"KEY_PERFORMANCE_MONTHS":html_performance_months,
		"KEY_PERFORMANCE_YEARS":html_performance_years,
		"KEY_PERFORMANCE_DAYS":html_performance_days,
		"KEY_PERFORMANCE_WEEKS":html_performance_weeks,
		# scrobbles
		"KEY_SCROBBLELIST":html_scrobbles,
		"KEY_SCROBBLELINK":compose_querystring(keys),

	}

	return (replace,pushresources)