Exemplo n.º 1
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)
Exemplo n.º 2
0
def module_toptracks(pictures=True,**kwargs):

	kwargs_filter = pickKeys(kwargs,"artist","associated")
	kwargs_time = pickKeys(kwargs,"timerange","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)


		# track with most #1 positions
		max_appear = 0
		representatives = list(t["track"] for t in tracks if t["track"] is not None)
		for t in representatives:
			max_appear = max(max_appear,representatives.count(t))
		#representatives.sort(key=lambda reftrack:len([t for t in tracks if t["track"] == reftrack["track"] and t["track"] is not None]))
		representatives = [t for t in tracks if representatives.count(t["track"]) == max_appear]
		# of these, track with highest scrobbles in its #1 range
		representatives.sort(key=lambda t: t["scrobbles"])
		representative = representatives[-1]["track"]
	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"]])
		range = e["range"]

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


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

	return (html,representative)
Exemplo n.º 3
0
def module_scrobblelist(page=0,perpage=100,max_=None,pictures=False,shortTimeDesc=False,earlystop=False,**kwargs):

	kwargs_filter = pickKeys(kwargs,"artist","track","associated")
	kwargs_time = pickKeys(kwargs,"timerange","since","to","within")

	if max_ is not None: perpage,page=max_,0

	firstindex = page * perpage
	lastindex = firstindex + perpage

	# if earlystop, we don't care about the actual amount and only request as many from the db
	# without, we request everything and filter on site
	maxkey = {"max_":lastindex} if earlystop else {}
	scrobbles = database.get_scrobbles(**kwargs_time,**kwargs_filter,**maxkey)
	if pictures:
		scrobbleswithpictures = [""] * firstindex + scrobbles[firstindex:lastindex]
		#scrobbleimages = [e.get("image") for e in getTracksInfo(scrobbleswithpictures)] #will still work with scrobble objects as they are a technically a subset of track objects
		#scrobbleimages = ["/image?title=" + urllib.parse.quote(t["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in t["artists"]])  for t in scrobbleswithpictures]
		scrobbleimages = [getTrackImage(t["artists"],t["title"],fast=True) for t in scrobbleswithpictures]

	pages = math.ceil(len(scrobbles) / perpage)

	representative = scrobbles[0] if len(scrobbles) is not 0 else None

	# build list
	i = 0
	html = "<table class='list'>"
	for s in scrobbles:
		if i<firstindex:
			i += 1
			continue

		html += "<tr>"
		html += "<td class='time'>" + timestamp_desc(s["time"],short=shortTimeDesc) + "</td>"
		if pictures:
			img = scrobbleimages[i]
		else: img = None
		html += entity_column(s,image=img)
		html += "</tr>"

		i += 1
		if i>=lastindex:
			break


	html += "</table>"

	if max_ is None: html += module_paginate(page=page,pages=pages,perpage=perpage,**kwargs)

	return (html,len(scrobbles),representative)
Exemplo n.º 4
0
def module_scrobblelist(max_=None,
                        pictures=False,
                        shortTimeDesc=False,
                        earlystop=False,
                        **kwargs):

    kwargs_filter = pickKeys(kwargs, "artist", "track", "associated")
    kwargs_time = pickKeys(kwargs, "timerange", "since", "to", "within")

    # if earlystop, we don't care about the actual amount and only request as many from the db
    # without, we request everything and filter on site
    maxkey = {"max_": max_} if earlystop else {}
    scrobbles = database.get_scrobbles(**kwargs_time, **kwargs_filter,
                                       **maxkey)
    if pictures:
        scrobbleswithpictures = scrobbles if max_ is None else scrobbles[:max_]
        #scrobbleimages = [e.get("image") for e in getTracksInfo(scrobbleswithpictures)] #will still work with scrobble objects as they are a technically a subset of track objects
        #scrobbleimages = ["/image?title=" + urllib.parse.quote(t["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in t["artists"]])  for t in scrobbleswithpictures]
        scrobbleimages = [
            getTrackImage(t["artists"], t["title"], fast=True)
            for t in scrobbleswithpictures
        ]

    representative = scrobbles[0] if len(scrobbles) is not 0 else None

    # build list
    i = 0
    html = "<table class='list'>"
    for s in scrobbles:

        html += "<tr>"
        html += "<td class='time'>" + timestamp_desc(
            s["time"], short=shortTimeDesc) + "</td>"
        if pictures:
            img = scrobbleimages[i]
        else:
            img = None
        html += entity_column(s, image=img)
        # Alternative way: Do it in one cell
        #html += "<td class='title'><span>" + artistLinks(s["artists"]) + "</span> — " + trackLink({"artists":s["artists"],"title":s["title"]}) + "</td>"
        html += "</tr>"

        i += 1
        if max_ is not None and i >= max_:
            break

    html += "</table>"

    return (html, len(scrobbles), representative)
Exemplo n.º 5
0
def module_trackcharts_tiles(**kwargs):

	kwargs_filter = pickKeys(kwargs,"artist","associated")
	kwargs_time = pickKeys(kwargs,"timerange","since","to","within")

	tracks = database.get_charts_tracks(**kwargs_filter,**kwargs_time)[:14]
	while len(tracks)<14: tracks.append(None) #{"track":{"title":"","artists":[]}}

	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 tracks:


		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["track"]) \
				+ "\"' style='cursor:pointer;background-image:url(\"" + getTrackImage(e["track"]["artists"],e["track"]["title"],fast=True) + "\");'>" \
				+ "<span class='stats'>" + "#" + str(e["rank"]) + "</span> <span>" + html_link(e["track"]) + "</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
Exemplo n.º 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_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)
Exemplo n.º 7
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_toptracks, module_filterselection
    from malojatime import range_desc

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

    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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
def instructions(keys):
    from utilities import getArtistImage, getTrackImage
    from htmlgenerators import artistLinks
    from urihandler import compose_querystring, uri_to_internal
    from htmlmodules import module_scrobblelist, module_pulse, module_performance

    filterkeys, _, _, _ = uri_to_internal(keys, forceTrack=True)

    track = filterkeys.get("track")
    imgurl = getTrackImage(track["artists"], track["title"], fast=True)
    pushresources = [{
        "file": imgurl,
        "type": "image"
    }] if imgurl.startswith("/") else []

    data = database.trackInfo(track)

    scrobblesnum = str(data["scrobbles"])
    pos = "#" + str(data["position"])

    html_cert = ""
    if data["certification"] is not None:
        html_cert = "<img class='certrecord' src='/media/record_{cert}.png' title='This track has reached {certc} status' />".format(
            cert=data["certification"],
            certc=data["certification"].capitalize())

    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 Track in " + str(
                    y
                ) + "' class='hidelink medal shiny gold' href='/charts_tracks?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 Track in " + str(
                    y
                ) + "' class='hidelink medal shiny silver' href='/charts_tracks?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 Track in " + str(
                    y
                ) + "' class='hidelink medal shiny bronze' href='/charts_tracks?in=" + str(
                    y) + "'><span>" + str(y) + "</span></a>"

    html_topweeks = ""
    if data.get("topweeks") not in [0, None]:
        link = "/performance?" + compose_querystring(
            keys) + "&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>"

    html_scrobbles, _, _ = module_scrobblelist(
        track=track, max_=10,
        earlystop=True)  # we have the number already from the trackinfo

    html_pulse = module_pulse(track=track, step="year", stepn=1, trail=1)
    html_performance = module_performance(track=track,
                                          step="year",
                                          stepn=1,
                                          trail=1)

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

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

    replace = {
        "KEY_TRACKTITLE": track.get("title"),
        "KEY_ARTISTS": artistLinks(track.get("artists")),
        "KEY_SCROBBLES": scrobblesnum,
        "KEY_POSITION": pos,
        "KEY_IMAGEURL": imgurl,
        "KEY_SCROBBLELINK": compose_querystring(keys),
        "KEY_MEDALS": html_medals,
        "KEY_CERTS": html_cert,
        "KEY_TOPWEEKS": html_topweeks,
        "KEY_SCROBBLELIST": html_scrobbles,
        # 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,
    }

    return (replace, pushresources)