mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented track charts
This commit is contained in:
parent
11bebce807
commit
f68fe04760
@ -120,7 +120,7 @@ def get_scrobbles(**keys):
|
|||||||
else:
|
else:
|
||||||
result = sqldb.get_scrobbles(since=since,to=to)
|
result = sqldb.get_scrobbles(since=since,to=to)
|
||||||
#return result[keys['page']*keys['perpage']:(keys['page']+1)*keys['perpage']]
|
#return result[keys['page']*keys['perpage']:(keys['page']+1)*keys['perpage']]
|
||||||
return result
|
return list(reversed(result))
|
||||||
|
|
||||||
@waitfordb
|
@waitfordb
|
||||||
def get_scrobbles_num(**keys):
|
def get_scrobbles_num(**keys):
|
||||||
@ -145,9 +145,11 @@ def get_charts_artists(**keys):
|
|||||||
result = sqldb.count_scrobbles_by_artist(since=since,to=to)
|
result = sqldb.count_scrobbles_by_artist(since=since,to=to)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@waitfordb
|
||||||
def get_charts_tracks(**keys):
|
def get_charts_tracks(**keys):
|
||||||
return db_aggregate(by="TRACK",**{k:keys[k] for k in keys if k in ["since","to","within","timerange","artist"]})
|
(since,to) = keys.get('timerange').timestamps()
|
||||||
|
result = sqldb.count_scrobbles_by_track(since=since,to=to)
|
||||||
|
return result
|
||||||
|
|
||||||
def get_pulse(**keys):
|
def get_pulse(**keys):
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ def get_scrobbles_of_artist(artist,since=None,to=None):
|
|||||||
DB['scrobbles'].c.timestamp<=to,
|
DB['scrobbles'].c.timestamp<=to,
|
||||||
DB['scrobbles'].c.timestamp>=since,
|
DB['scrobbles'].c.timestamp>=since,
|
||||||
DB['trackartists'].c.artist_id==artist_id
|
DB['trackartists'].c.artist_id==artist_id
|
||||||
).order_by(sql.desc('timestamp'))
|
).order_by(sql.asc('timestamp'))
|
||||||
result = conn.execute(op).all()
|
result = conn.execute(op).all()
|
||||||
|
|
||||||
result = scrobbles_db_to_dict(result)
|
result = scrobbles_db_to_dict(result)
|
||||||
@ -294,7 +294,7 @@ def get_scrobbles_of_track(track,since=None,to=None):
|
|||||||
DB['scrobbles'].c.timestamp<=to,
|
DB['scrobbles'].c.timestamp<=to,
|
||||||
DB['scrobbles'].c.timestamp>=since,
|
DB['scrobbles'].c.timestamp>=since,
|
||||||
DB['scrobbles'].c.track_id==track_id
|
DB['scrobbles'].c.track_id==track_id
|
||||||
).order_by(sql.desc('timestamp'))
|
).order_by(sql.asc('timestamp'))
|
||||||
result = conn.execute(op).all()
|
result = conn.execute(op).all()
|
||||||
|
|
||||||
result = scrobbles_db_to_dict(result)
|
result = scrobbles_db_to_dict(result)
|
||||||
@ -311,7 +311,7 @@ def get_scrobbles(since=None,to=None,resolve_references=True,max=math.inf):
|
|||||||
op = DB['scrobbles'].select().where(
|
op = DB['scrobbles'].select().where(
|
||||||
DB['scrobbles'].c.timestamp<=to,
|
DB['scrobbles'].c.timestamp<=to,
|
||||||
DB['scrobbles'].c.timestamp>=since,
|
DB['scrobbles'].c.timestamp>=since,
|
||||||
).order_by(sql.desc('timestamp'))
|
).order_by(sql.asc('timestamp'))
|
||||||
result = conn.execute(op).all()
|
result = conn.execute(op).all()
|
||||||
|
|
||||||
result = scrobbles_db_to_dict(result)
|
result = scrobbles_db_to_dict(result)
|
||||||
@ -393,6 +393,27 @@ def count_scrobbles_by_artist(since,to):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def count_scrobbles_by_track(since,to):
|
||||||
|
print(since,to)
|
||||||
|
|
||||||
|
with engine.begin() as conn:
|
||||||
|
op = sql.select(
|
||||||
|
sql.func.count(sql.func.distinct(DB['scrobbles'].c.timestamp)).label('count'),
|
||||||
|
DB['scrobbles'].c.track_id
|
||||||
|
).select_from(DB['scrobbles']).where(
|
||||||
|
DB['scrobbles'].c.timestamp<=to,
|
||||||
|
DB['scrobbles'].c.timestamp>=since
|
||||||
|
).group_by(DB['scrobbles'].c.track_id).order_by(sql.desc('count'))
|
||||||
|
result = conn.execute(op).all()
|
||||||
|
|
||||||
|
|
||||||
|
counts = [row.count for row in result]
|
||||||
|
tracks = get_tracks_map(row.track_id for row in result)
|
||||||
|
result = [{'scrobbles':row.count,'track':tracks[row.track_id]} for row in result]
|
||||||
|
result = rank(result,key='scrobbles')
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### functions that get mappings for several entities -> rows
|
### functions that get mappings for several entities -> rows
|
||||||
|
Loading…
Reference in New Issue
Block a user