mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04: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)}
|
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")
|
@route("/top/artists")
|
||||||
def get_top_artists():
|
def get_top_artists():
|
||||||
date_start = datetime.datetime.utcfromtimestamp(min(timestamps))
|
since = request.query.get("since")
|
||||||
date_end = datetime.datetime.utcnow()
|
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]
|
d_end = [date_end.year,date_end.month,date_end.day]
|
||||||
|
|
||||||
step = request.query.get("step")
|
step = request.query.get("step")
|
||||||
@ -335,7 +384,7 @@ def db_query(artist=None,track=None,since=0,to=9999999999):
|
|||||||
|
|
||||||
|
|
||||||
# Queries that... well... aggregate
|
# 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)
|
(since, to) = getTimestamps(since,to)
|
||||||
|
|
||||||
if (by=="ARTIST"):
|
if (by=="ARTIST"):
|
||||||
@ -365,6 +414,9 @@ def db_aggregate(by,since=0,to=9999999999):
|
|||||||
ls = [{"track":getTrackObject(TRACKS[t]),"scrobbles":charts[t]} for t in charts]
|
ls = [{"track":getTrackObject(TRACKS[t]),"scrobbles":charts[t]} for t in charts]
|
||||||
return sorted(ls,key=lambda k:k["scrobbles"], reverse=True)
|
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.
|
# Takes user inputs like YYYY/MM and returns the timestamps. Returns timestamp if timestamp was already given.
|
||||||
def getTimestamps(f,t):
|
def getTimestamps(f,t):
|
||||||
@ -389,9 +441,9 @@ def getTimestamps(f,t):
|
|||||||
|
|
||||||
|
|
||||||
if (f==None):
|
if (f==None):
|
||||||
f = 0
|
f = min(timestamps)
|
||||||
if (t==None):
|
if (t==None):
|
||||||
t = 9999999999
|
t = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp()
|
||||||
|
|
||||||
return (f,t)
|
return (f,t)
|
||||||
|
|
||||||
|
3
logs/.gitignore
vendored
3
logs/.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
*.tsv
|
*.txt
|
||||||
*.csv
|
|
||||||
|
18
maloja
18
maloja
@ -1,6 +1,22 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import subprocess
|
neededmodules = [
|
||||||
|
"bottle",
|
||||||
|
"waitress"
|
||||||
|
]
|
||||||
|
toinstall = []
|
||||||
|
|
||||||
|
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)
|
subprocess.Popen(["python","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
||||||
print("Maloja started!")
|
print("Maloja started!")
|
||||||
|
@ -80,6 +80,7 @@ def static_html(name):
|
|||||||
|
|
||||||
#set graceful shutdown
|
#set graceful shutdown
|
||||||
signal.signal(signal.SIGINT, graceful_exit)
|
signal.signal(signal.SIGINT, graceful_exit)
|
||||||
|
signal.signal(signal.SIGTERM, graceful_exit)
|
||||||
|
|
||||||
#rename process, not important
|
#rename process, not important
|
||||||
try:
|
try:
|
||||||
|
@ -56,3 +56,7 @@ def createTSV(filename):
|
|||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
open(filename,"w").close()
|
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…
x
Reference in New Issue
Block a user