mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Some testing utilities
This commit is contained in:
parent
713975d0cb
commit
936c3892b9
40
database.py
40
database.py
@ -66,12 +66,12 @@ def getTrackObject(o):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def createScrobble(artists,title,time):
|
def createScrobble(artists,title,time,volatile=False):
|
||||||
while (time in STAMPS_SET):
|
while (time in STAMPS_SET):
|
||||||
time += 1
|
time += 1
|
||||||
STAMPS_SET.add(time)
|
STAMPS_SET.add(time)
|
||||||
i = getTrackID(artists,title)
|
i = getTrackID(artists,title)
|
||||||
obj = (i,time,False)
|
obj = (i,time,volatile) # if volatile generated, we simply pretend we have already saved it to disk
|
||||||
#SCROBBLES.append(obj)
|
#SCROBBLES.append(obj)
|
||||||
# immediately insert scrobble correctly so we can guarantee sorted list
|
# immediately insert scrobble correctly so we can guarantee sorted list
|
||||||
index = insert(SCROBBLES,obj,key=lambda x:x[1])
|
index = insert(SCROBBLES,obj,key=lambda x:x[1])
|
||||||
@ -733,7 +733,6 @@ def build_db():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Saves all cached entries to disk
|
# Saves all cached entries to disk
|
||||||
def sync():
|
def sync():
|
||||||
|
|
||||||
@ -816,14 +815,13 @@ def db_query(artist=None,artists=None,title=None,track=None,since=None,to=None,w
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# right now we always request everything by name, maybe we don't actually need the request by number, but i'll leave it in for now
|
|
||||||
|
|
||||||
if associated:
|
if associated:
|
||||||
#return [getScrobbleObject(s) for s in SCROBBLES if (s[0] == track or track==None) and (artist==None or artist in coa.getCreditedList(TRACKS[s[0]][0])) and (since < s[1] < to)]
|
#return [getScrobbleObject(s) for s in SCROBBLES if (s[0] == track or track==None) and (artist==None or artist in coa.getCreditedList(TRACKS[s[0]][0])) and (since < s[1] < to)]
|
||||||
return [getScrobbleObject(s) for s in scrobbles_in_range(since,to) if (s[0] == track or track==None) and (artist==None or artist in coa.getCreditedList(TRACKS[s[0]][0]))]
|
return [getScrobbleObject(s) for s in scrobbles_in_range(since,to) if (track is None or s[0] == track) and (artist is None or artist in coa.getCreditedList(TRACKS[s[0]][0]))]
|
||||||
else:
|
else:
|
||||||
#return [getScrobbleObject(s) for s in SCROBBLES if (s[0] == track or track==None) and (artist==None or artist in TRACKS[s[0]][0]) and (since < s[1] < to)]
|
#return [getScrobbleObject(s) for s in SCROBBLES if (s[0] == track or track==None) and (artist==None or artist in TRACKS[s[0]][0]) and (since < s[1] < to)]
|
||||||
return [getScrobbleObject(s) for s in scrobbles_in_range(since,to) if (s[0] == track or track==None) and (artist==None or artist in TRACKS[s[0]][0])]
|
return [getScrobbleObject(s) for s in scrobbles_in_range(since,to) if (track is None or s[0] == track) and (artist is None or artist in TRACKS[s[0]][0])]
|
||||||
# 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
|
# 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
|
||||||
|
|
||||||
|
|
||||||
@ -924,7 +922,14 @@ def insert(list_,item,key=lambda x:x):
|
|||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
def scrobbles_in_range(start,end):
|
def scrobbles_in_range(start,end,reverse=False):
|
||||||
|
if reverse:
|
||||||
|
for stamp in reversed(STAMPS):
|
||||||
|
#print("Checking " + str(stamp))
|
||||||
|
if stamp < start: return
|
||||||
|
if stamp > end: continue
|
||||||
|
yield SCROBBLESDICT[stamp]
|
||||||
|
else:
|
||||||
for stamp in STAMPS:
|
for stamp in STAMPS:
|
||||||
#print("Checking " + str(stamp))
|
#print("Checking " + str(stamp))
|
||||||
if stamp < start: continue
|
if stamp < start: continue
|
||||||
@ -935,3 +940,24 @@ def scrobbles_in_range(start,end):
|
|||||||
# if stamp%1000 == 0: print("testing " + str(stamp))
|
# if stamp%1000 == 0: print("testing " + str(stamp))
|
||||||
# if stamp in SCROBBLESDICT:
|
# if stamp in SCROBBLESDICT:
|
||||||
# yield SCROBBLESDICT[stamp]
|
# yield SCROBBLESDICT[stamp]
|
||||||
|
|
||||||
|
|
||||||
|
# for performance testing
|
||||||
|
def generateStuff(num=0,pertrack=0,mult=0):
|
||||||
|
import random
|
||||||
|
for i in range(num):
|
||||||
|
track = random.choice(TRACKS)
|
||||||
|
t = getTrackObject(track)
|
||||||
|
time = random.randint(STAMPS[0],STAMPS[-1])
|
||||||
|
createScrobble(t["artists"],t["title"],time,volatile=True)
|
||||||
|
|
||||||
|
for track in TRACKS:
|
||||||
|
t = getTrackObject(track)
|
||||||
|
for i in range(pertrack):
|
||||||
|
time = random.randint(STAMPS[0],STAMPS[-1])
|
||||||
|
createScrobble(t["artists"],t["title"],time,volatile=True)
|
||||||
|
|
||||||
|
for scrobble in SCROBBLES:
|
||||||
|
s = getScrobbleObject(scrobble)
|
||||||
|
for i in range(mult):
|
||||||
|
createScrobble(s["artists"],s["title"],s["time"] - i*500,volatile=True)
|
||||||
|
@ -141,6 +141,7 @@ def static_html(name):
|
|||||||
headerhtml = headerfile.read()
|
headerhtml = headerfile.read()
|
||||||
html = html.replace("</body>",footerhtml + "</body>").replace("</head>",headerhtml + "</head>")
|
html = html.replace("</body>",footerhtml + "</body>").replace("</head>",headerhtml + "</head>")
|
||||||
|
|
||||||
|
|
||||||
# If a python file exists, it provides the replacement dict for the html file
|
# If a python file exists, it provides the replacement dict for the html file
|
||||||
if os.path.exists("website/" + name + ".py"):
|
if os.path.exists("website/" + name + ".py"):
|
||||||
#txt_keys = SourceFileLoader(name,"website/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT)
|
#txt_keys = SourceFileLoader(name,"website/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT)
|
||||||
@ -160,7 +161,6 @@ def static_html(name):
|
|||||||
html = html.replace(k,txt_keys[k])
|
html = html.replace(k,txt_keys[k])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
response.set_header("Link",",".join(linkheaders))
|
response.set_header("Link",",".join(linkheaders))
|
||||||
|
|
||||||
return html
|
return html
|
||||||
|
@ -175,6 +175,15 @@ def log(msg,module=None):
|
|||||||
logfile.write(now + " " + msg + "\n")
|
logfile.write(now + " " + msg + "\n")
|
||||||
|
|
||||||
|
|
||||||
|
### not meant to be precise, just for a rough idea
|
||||||
|
measurement = 0
|
||||||
|
def clock(*args):
|
||||||
|
import time
|
||||||
|
global measurement
|
||||||
|
now = time.time()
|
||||||
|
if len(args) > 0:
|
||||||
|
print(args[0] + ": " + str(now - measurement))
|
||||||
|
measurement = now
|
||||||
|
|
||||||
### Media info
|
### Media info
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import urllib
|
import urllib
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import database
|
import database
|
||||||
|
from utilities import clock
|
||||||
|
|
||||||
from htmlmodules import module_scrobblelist, module_pulse, module_artistcharts_tiles, module_trackcharts_tiles
|
from htmlmodules import module_scrobblelist, module_pulse, module_artistcharts_tiles, module_trackcharts_tiles
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ def instructions(keys):
|
|||||||
newdate = tod - d
|
newdate = tod - d
|
||||||
weekstart = [newdate.year,newdate.month,newdate.day]
|
weekstart = [newdate.year,newdate.month,newdate.day]
|
||||||
|
|
||||||
|
clock()
|
||||||
|
|
||||||
# artists
|
# artists
|
||||||
|
|
||||||
topartists_total = module_artistcharts_tiles()
|
topartists_total = module_artistcharts_tiles()
|
||||||
@ -21,6 +24,7 @@ def instructions(keys):
|
|||||||
topartists_month = module_artistcharts_tiles(since="month")
|
topartists_month = module_artistcharts_tiles(since="month")
|
||||||
topartists_week = module_artistcharts_tiles(since=weekstart)
|
topartists_week = module_artistcharts_tiles(since=weekstart)
|
||||||
|
|
||||||
|
clock("Artists")
|
||||||
|
|
||||||
# tracks
|
# tracks
|
||||||
|
|
||||||
@ -30,9 +34,13 @@ def instructions(keys):
|
|||||||
toptracks_week = module_trackcharts_tiles(since=weekstart)
|
toptracks_week = module_trackcharts_tiles(since=weekstart)
|
||||||
|
|
||||||
|
|
||||||
|
clock("Tracks")
|
||||||
|
|
||||||
|
|
||||||
# scrobbles
|
# scrobbles
|
||||||
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True)
|
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True)
|
||||||
|
|
||||||
|
clock("Scrobbles")
|
||||||
|
|
||||||
# stats
|
# stats
|
||||||
amount = database.get_scrobbles_num(since="today")
|
amount = database.get_scrobbles_num(since="today")
|
||||||
@ -48,6 +56,8 @@ def instructions(keys):
|
|||||||
scrobbles_total = "<a href='/scrobbles'>" + str(amount) + "</a>"
|
scrobbles_total = "<a href='/scrobbles'>" + str(amount) + "</a>"
|
||||||
|
|
||||||
|
|
||||||
|
clock("Amounts")
|
||||||
|
|
||||||
# pulse
|
# pulse
|
||||||
dt = datetime.utcnow()
|
dt = datetime.utcnow()
|
||||||
first_month = [dt.year-1,dt.month+1]
|
first_month = [dt.year-1,dt.month+1]
|
||||||
@ -68,7 +78,7 @@ def instructions(keys):
|
|||||||
#html_pulse_month = module_pulse(max_=30,since=[dt.year,dt.month],step="day",trail=1)
|
#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)
|
#html_pulse_year = module_pulse(max_=12,since=[dt.year],step="month",trail=1)
|
||||||
|
|
||||||
|
clock("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 = [{"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 = []
|
pushresources = []
|
||||||
|
Loading…
Reference in New Issue
Block a user