예제 #1
0
파일: database.py 프로젝트: Rfvgyhn/maloja
def get_performance(**keys):

    rngs = ranges(
        **{
            k: keys[k]
            for k in keys if k in
            ["since", "to", "within", "timerange", "step", "stepn", "trail"]
        })
    results = []

    for rng in rngs:
        if "track" in keys:
            charts = get_charts_tracks(timerange=rng)
            rank = None
            for c in charts:
                if c["track"] == keys["track"]:
                    rank = c["rank"]
                    break
        elif "artist" in keys:
            charts = get_charts_artists(timerange=rng)
            rank = None
            for c in charts:
                if c["artist"] == keys["artist"]:
                    rank = c["rank"]
                    break
        results.append({"range": rng, "rank": rank})

    return results
예제 #2
0
파일: database.py 프로젝트: Rfvgyhn/maloja
def get_pulse(**keys):

    rngs = ranges(
        **{
            k: keys[k]
            for k in keys if k in
            ["since", "to", "within", "timerange", "step", "stepn", "trail"]
        })
    results = []
    for rng in rngs:
        res = len(
            db_query(timerange=rng,
                     **{
                         k: keys[k]
                         for k in keys if k in
                         ["artists", "artist", "track", "title", "associated"]
                     }))
        results.append({"range": rng, "scrobbles": res})

    return results
예제 #3
0
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
예제 #4
0
파일: database.py 프로젝트: Rfvgyhn/maloja
def get_top_tracks(**keys):

    rngs = ranges(
        **{
            k: keys[k]
            for k in keys if k in
            ["since", "to", "within", "timerange", "step", "stepn", "trail"]
        })
    results = []

    for rng in rngs:
        try:
            res = db_aggregate(timerange=rng, by="TRACK")[0]
            results.append({
                "range": rng,
                "track": res["track"],
                "scrobbles": res["scrobbles"]
            })
        except:
            results.append({"range": rng, "track": None, "scrobbles": 0})

    return results
예제 #5
0
파일: database.py 프로젝트: Rfvgyhn/maloja
def get_top_artists(**keys):

    rngs = ranges(
        **{
            k: keys[k]
            for k in keys if k in
            ["since", "to", "within", "timerange", "step", "stepn", "trail"]
        })
    results = []

    for rng in rngs:
        try:
            res = db_aggregate(timerange=rng, by="ARTIST")[0]
            results.append({
                "range": rng,
                "artist": res["artist"],
                "counting": res["counting"],
                "scrobbles": res["scrobbles"]
            })
        except:
            results.append({"range": rng, "artist": None, "scrobbles": 0})

    return results