mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented aggregating by artist
This commit is contained in:
parent
9fc838e4c8
commit
40e733a054
@ -584,7 +584,7 @@ def db_query_full(artist=None,artists=None,title=None,track=None,timerange=None,
|
||||
|
||||
|
||||
# Queries that... well... aggregate
|
||||
def db_aggregate_full(by=None,within=None,timerange=None,artist=None):
|
||||
def db_aggregate_full(by=None,timerange=None,artist=None):
|
||||
|
||||
if not dbstatus['healthy']: raise DatabaseNotBuilt()
|
||||
(since, to) = time_stamps(range=timerange)
|
||||
@ -592,15 +592,20 @@ def db_aggregate_full(by=None,within=None,timerange=None,artist=None):
|
||||
|
||||
if (by=="ARTIST"):
|
||||
|
||||
trackcharts = {}
|
||||
charts = {}
|
||||
scrobbles = sqldb.get_scrobbles(since=since,to=to)
|
||||
for s in scrobbles_in_range(since,to):
|
||||
artists = TRACKS[s[0]][0]
|
||||
for a in coa.getCreditedList(artists):
|
||||
# this either creates the new entry or increments the existing one
|
||||
charts[a] = charts.setdefault(a,0) + 1
|
||||
scrobbles = sqldb.get_scrobbles(since=since,to=to,resolve_references=False)
|
||||
|
||||
ls = [{"artist":get_artist_dict(ARTISTS[a]),"scrobbles":charts[a],"counting":[arti for arti in coa.getAllAssociated(ARTISTS[a]) if arti in ARTISTS]} for a in charts]
|
||||
for s in scrobbles:
|
||||
trackcharts[s['track']] = trackcharts.setdefault(s['track'],0) + 1
|
||||
|
||||
for t in trackcharts:
|
||||
artists = sqldb.get_artists_of_track(t,resolve_references=False)
|
||||
for a in coa.getCreditedList(artists):
|
||||
charts[a] = charts.setdefault(a,0) + trackcharts[t]
|
||||
|
||||
|
||||
ls = [{"artist":sqldb.get_artist(a),"scrobbles":charts[a],"counting":[]} for a in charts]
|
||||
ls.sort(key=lambda k:k["scrobbles"],reverse=True)
|
||||
# add ranks
|
||||
for rnk in range(len(ls)):
|
||||
|
@ -15,7 +15,7 @@ from ..globalconf import malojaconfig
|
||||
from .. import utilities
|
||||
from .. import database as dbmain
|
||||
|
||||
if malojaconfig["USE_DB_CACHE"]:
|
||||
if False:
|
||||
def db_query(**kwargs):
|
||||
return db_query_cached(**kwargs)
|
||||
def db_aggregate(**kwargs):
|
||||
|
@ -291,14 +291,14 @@ def get_artist(id):
|
||||
artistinfo = result[0]
|
||||
return artist_db_to_dict(artistinfo)
|
||||
|
||||
def get_artists_of_track(track_id):
|
||||
def get_artists_of_track(track_id,resolve_references=True):
|
||||
with engine.begin() as conn:
|
||||
op = DB['trackartists'].select().where(
|
||||
DB['trackartists'].c.track_id==track_id
|
||||
)
|
||||
result = conn.execute(op).all()
|
||||
|
||||
artists = [get_artist(row.artist_id) for row in result]
|
||||
artists = [get_artist(row.artist_id) if resolve_references else row.artist_id for row in result]
|
||||
return artists
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user