From b3423dabcfe0528908c8099c0f71f15c22b52a7f Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 9 Apr 2019 12:13:07 +0200 Subject: [PATCH] Added chart performance database call --- database.py | 37 +++++++++++++++++++++++++++++++++++++ website/start.py | 12 ++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/database.py b/database.py index 0672b9f..473d604 100644 --- a/database.py +++ b/database.py @@ -394,6 +394,43 @@ def get_pulse(**keys): +@dbserver.route("/performance") +def get_performance_external(): + keys = FormsDict.decode(request.query) + k_filter, k_time, k_internal, k_amount = uri_to_internal(keys) + ckeys = {**k_filter, **k_time, **k_internal, **k_amount} + + results = get_performance(**ckeys) + return {"list":results} + +def get_performance(**keys): + + rngs = ranges(**{k:keys[k] for k in keys if k in ["since","to","within","step","stepn","trail"]}) + results = [] + + for (a,b) in rngs: + if "track" in keys: + charts = get_charts_tracks(since=a,to=b) + rank = None + for c in charts: + if c["track"] == keys["track"]: + rank = c["rank"] + break + elif "artist" in keys: + charts = get_charts_artists(since=a,to=b) + rank = None + for c in charts: + if c["artist"] == keys["artist"]: + rank = c["rank"] + break + results.append({"from":a,"to":b,"rank":rank}) + + return results + + + + + diff --git a/website/start.py b/website/start.py index 2f0f0c8..7c00310 100644 --- a/website/start.py +++ b/website/start.py @@ -21,7 +21,7 @@ def instructions(keys): newdate = tod - d weekstart = [newdate.year,newdate.month,newdate.day] - clock() + #clock() # artists @@ -30,7 +30,7 @@ def instructions(keys): topartists_month = module_artistcharts_tiles(since="month") topartists_week = module_artistcharts_tiles(since=weekstart) - clockp("Artists") + #clockp("Artists") # tracks @@ -40,7 +40,7 @@ def instructions(keys): toptracks_week = module_trackcharts_tiles(since=weekstart) - clockp("Tracks") + #clockp("Tracks") @@ -48,7 +48,7 @@ def instructions(keys): # scrobbles html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True) - clockp("Scrobbles") + #clockp("Scrobbles") # stats @@ -69,7 +69,7 @@ def instructions(keys): amount_total = database.get_scrobbles_num() scrobbles_total = "" + str(amount_total) + "" - clockp("Amounts") + #clockp("Amounts") # pulse dt = datetime.utcnow() @@ -91,7 +91,7 @@ def instructions(keys): #html_pulse_month = module_pulse(max_=30,since=[dt.year,dt.month],step="day",trail=1) #html_pulse_year = module_pulse(max_=12,since=[dt.year],step="month",trail=1) - clockp("Pulse") + #clockp("Pulse") #pushresources = [{"file":img,"type":"image"} for img in artistimages + trackimages] #can't push scrobble images as we don't get them from the module function, need to think about that pushresources = []