1
0
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:
krateng 2022-01-05 08:16:30 +01:00
parent 9fc838e4c8
commit 40e733a054
3 changed files with 16 additions and 11 deletions

View File

@ -584,7 +584,7 @@ def db_query_full(artist=None,artists=None,title=None,track=None,timerange=None,
# Queries that... well... aggregate # 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() if not dbstatus['healthy']: raise DatabaseNotBuilt()
(since, to) = time_stamps(range=timerange) (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"): if (by=="ARTIST"):
trackcharts = {}
charts = {} charts = {}
scrobbles = sqldb.get_scrobbles(since=since,to=to) scrobbles = sqldb.get_scrobbles(since=since,to=to,resolve_references=False)
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
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) ls.sort(key=lambda k:k["scrobbles"],reverse=True)
# add ranks # add ranks
for rnk in range(len(ls)): for rnk in range(len(ls)):

View File

@ -15,7 +15,7 @@ from ..globalconf import malojaconfig
from .. import utilities from .. import utilities
from .. import database as dbmain from .. import database as dbmain
if malojaconfig["USE_DB_CACHE"]: if False:
def db_query(**kwargs): def db_query(**kwargs):
return db_query_cached(**kwargs) return db_query_cached(**kwargs)
def db_aggregate(**kwargs): def db_aggregate(**kwargs):

View File

@ -291,14 +291,14 @@ def get_artist(id):
artistinfo = result[0] artistinfo = result[0]
return artist_db_to_dict(artistinfo) 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: with engine.begin() as conn:
op = DB['trackartists'].select().where( op = DB['trackartists'].select().where(
DB['trackartists'].c.track_id==track_id DB['trackartists'].c.track_id==track_id
) )
result = conn.execute(op).all() 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 return artists