mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added total scrobble count stats
This commit is contained in:
parent
98c23cd8af
commit
e7e4cdebee
62
database.py
62
database.py
@ -128,10 +128,59 @@ def get_charts_tracks():
|
||||
|
||||
return {"list":db_aggregate(by="TRACK",since=since,to=to)}
|
||||
|
||||
@route("/charts")
|
||||
def get_charts():
|
||||
since = request.query.get("since")
|
||||
to = request.query.get("to")
|
||||
|
||||
return {"number":db_aggregate(since=since,to=to)}
|
||||
|
||||
@route("/pulse")
|
||||
def get_pulse():
|
||||
since = request.query.get("since")
|
||||
to = request.query.get("to")
|
||||
(ts_start,ts_end) = getTimestamps(since,to)
|
||||
date_start = datetime.datetime.utcfromtimestamp(ts_start)
|
||||
date_end = datetime.datetime.utcfromtimestamp(ts_end)
|
||||
#date_start = datetime.datetime.utcfromtimestamp(min(timestamps))
|
||||
#date_end = datetime.datetime.utcnow()
|
||||
d_end = [date_end.year,date_end.month,date_end.day]
|
||||
|
||||
step = request.query.get("step")
|
||||
if (step == None):
|
||||
step = "month"
|
||||
|
||||
[step,stepn] = (step.split("-") + [1])[:2] # makes the multiplier 1 if not assigned
|
||||
|
||||
if step == "year":
|
||||
d_start = [date_start.year,1,1]
|
||||
elif step == "month":
|
||||
d_start = [date_start.year,date_start.month,1]
|
||||
|
||||
inc = [i*int(stepn) for i in {"year":[1,0,0],"month":[0,1,0]}[step]]
|
||||
|
||||
|
||||
results = []
|
||||
|
||||
d_current = d_start
|
||||
while True:
|
||||
d_current_end = addDate(d_current,inc)
|
||||
res = db_aggregate(since=d_current,to=d_current_end)
|
||||
results.append({"from":d_current,"to":d_current_end,"scrobbles":res})
|
||||
d_current = d_current_end
|
||||
if isPast(d_current_end,d_end):
|
||||
break
|
||||
|
||||
return {"list":results}
|
||||
|
||||
|
||||
@route("/top/artists")
|
||||
def get_top_artists():
|
||||
date_start = datetime.datetime.utcfromtimestamp(min(timestamps))
|
||||
date_end = datetime.datetime.utcnow()
|
||||
since = request.query.get("since")
|
||||
to = request.query.get("to")
|
||||
(ts_start,ts_end) = getTimestamps(since,to)
|
||||
date_start = datetime.datetime.utcfromtimestamp(ts_start)
|
||||
date_end = datetime.datetime.utcfromtimestamp(ts_end)
|
||||
d_end = [date_end.year,date_end.month,date_end.day]
|
||||
|
||||
step = request.query.get("step")
|
||||
@ -335,7 +384,7 @@ def db_query(artist=None,track=None,since=0,to=9999999999):
|
||||
|
||||
|
||||
# Queries that... well... aggregate
|
||||
def db_aggregate(by,since=0,to=9999999999):
|
||||
def db_aggregate(by=None,since=0,to=9999999999):
|
||||
(since, to) = getTimestamps(since,to)
|
||||
|
||||
if (by=="ARTIST"):
|
||||
@ -364,6 +413,9 @@ def db_aggregate(by,since=0,to=9999999999):
|
||||
|
||||
ls = [{"track":getTrackObject(TRACKS[t]),"scrobbles":charts[t]} for t in charts]
|
||||
return sorted(ls,key=lambda k:k["scrobbles"], reverse=True)
|
||||
|
||||
else:
|
||||
return len([scr for scr in SCROBBLES if since < scr[1] < to])
|
||||
|
||||
|
||||
# Takes user inputs like YYYY/MM and returns the timestamps. Returns timestamp if timestamp was already given.
|
||||
@ -389,9 +441,9 @@ def getTimestamps(f,t):
|
||||
|
||||
|
||||
if (f==None):
|
||||
f = 0
|
||||
f = min(timestamps)
|
||||
if (t==None):
|
||||
t = 9999999999
|
||||
t = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp()
|
||||
|
||||
return (f,t)
|
||||
|
||||
|
3
logs/.gitignore
vendored
3
logs/.gitignore
vendored
@ -1,2 +1 @@
|
||||
*.tsv
|
||||
*.csv
|
||||
*.txt
|
||||
|
22
maloja
22
maloja
@ -1,6 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import subprocess
|
||||
neededmodules = [
|
||||
"bottle",
|
||||
"waitress"
|
||||
]
|
||||
toinstall = []
|
||||
|
||||
subprocess.Popen(["python","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
||||
print("Maloja started!")
|
||||
for m in neededmodules:
|
||||
try:
|
||||
exec("import " + m) #I'm sorry
|
||||
except:
|
||||
toinstall.append(m)
|
||||
|
||||
if toinstall != []:
|
||||
print("The following python modules need to be installed:")
|
||||
for m in toinstall:
|
||||
print("\t" + m)
|
||||
else:
|
||||
import subprocess
|
||||
subprocess.Popen(["python","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
||||
print("Maloja started!")
|
||||
|
@ -80,6 +80,7 @@ def static_html(name):
|
||||
|
||||
#set graceful shutdown
|
||||
signal.signal(signal.SIGINT, graceful_exit)
|
||||
signal.signal(signal.SIGTERM, graceful_exit)
|
||||
|
||||
#rename process, not important
|
||||
try:
|
||||
|
@ -55,4 +55,8 @@ def createTSV(filename):
|
||||
|
||||
if not os.path.exists(filename):
|
||||
open(filename,"w").close()
|
||||
|
||||
|
||||
def log(msg):
|
||||
print(msg)
|
||||
|
||||
|
8
website/maloja.css
Normal file
8
website/maloja.css
Normal file
@ -0,0 +1,8 @@
|
||||
@import url('https://fonts.googleapis.com/css?family=Ubuntu');
|
||||
|
||||
body {
|
||||
background-color:#111114;
|
||||
color:beige;
|
||||
font-family:"Ubuntu";
|
||||
padding:15px;
|
||||
}
|
14
website/topartists.html
Normal file
14
website/topartists.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Maloja</title>
|
||||
<link rel="stylesheet" href="maloja.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Top Artists</h1>
|
||||
<h2>in January 2018</h2>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user