There was an attempt

This commit is contained in:
Krateng 2019-03-12 16:06:09 +01:00
parent 0de84629bb
commit f0010fd6bb
3 changed files with 58 additions and 11 deletions

View File

@ -214,6 +214,38 @@ def get_scrobbles_num(**keys):
return len(r)
#for multiple since values (must be ordered)
# DOESN'T SEEM TO ACTUALLY BE FASTER
# REEVALUATE
#def get_scrobbles_num_multiple(sinces=[],to=None,**keys):
#
# sinces_stamps = [time_stamps(since,to,None)[0] for since in sinces]
# #print(sinces)
# #print(sinces_stamps)
# minsince = sinces[-1]
# r = db_query(**{k:keys[k] for k in keys if k in ["artist","track","artists","title","associated","to"]},since=minsince)
#
# #print(r)
#
# validtracks = [0 for s in sinces]
#
# i = 0
# si = 0
# while True:
# if si == len(sinces): break
# if i == len(r): break
# if r[i]["time"] >= sinces_stamps[si]:
# validtracks[si] += 1
# else:
# si += 1
# continue
# i += 1
#
#
# return validtracks
# UNUSED
#@dbserver.route("/charts")
#def get_charts_external():
@ -871,7 +903,7 @@ def db_query_full(artist=None,artists=None,title=None,track=None,since=None,to=N
# pointless to check for artist when track is checked because every track has a fixed set of artists, but it's more elegant this way
# Queries that... well... aggregate
def db_aggregate_full(by=None,since=None,to=None,within=None,artist=None):
(since, to) = time_stamps(since,to,within)

View File

@ -279,6 +279,16 @@ def loadCache():
(cachedTracks, cachedArtists) = ob
finally:
fl.close()
# remove corrupt caching from previous versions
for k in cachedTracks:
if cachedTracks[k] == "":
del cachedTracks[k]
log("Removed invalid cache key: " + str(k))
for k in cachedArtists:
if cachedArtists[k] == "":
del cachedArtists[k]
log("Removed invalid cache key: " + str(k))
def getTrackImage(artists,title,fast=False):

View File

@ -43,18 +43,23 @@ def instructions(keys):
clock("Scrobbles")
# stats
amount = database.get_scrobbles_num(since="today")
scrobbles_today = "<a href='/scrobbles?since=today'>" + str(amount) + "</a>"
amount = database.get_scrobbles_num(since="month")
scrobbles_month = "<a href='/scrobbles?since=month'>" + str(amount) + "</a>"
amount = database.get_scrobbles_num(since="year")
scrobbles_year = "<a href='/scrobbles?since=year'>" + str(amount) + "</a>"
amount = database.get_scrobbles_num()
scrobbles_total = "<a href='/scrobbles'>" + str(amount) + "</a>"
#(amount_day,amount_month,amount_year,amount_total) = database.get_scrobbles_num_multiple(("today","month","year",None))
#amount_month += amount_day
#amount_year += amount_month
#amount_total += amount_year
amount_day = database.get_scrobbles_num(since="today")
scrobbles_today = "<a href='/scrobbles?since=today'>" + str(amount_day) + "</a>"
amount_month = database.get_scrobbles_num(since="month")
scrobbles_month = "<a href='/scrobbles?since=month'>" + str(amount_month) + "</a>"
amount_year = database.get_scrobbles_num(since="year")
scrobbles_year = "<a href='/scrobbles?since=year'>" + str(amount_year) + "</a>"
amount_total = database.get_scrobbles_num()
scrobbles_total = "<a href='/scrobbles'>" + str(amount_total) + "</a>"
clock("Amounts")