mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented artist and track info, improved performance of artist page
This commit is contained in:
parent
632905a1c7
commit
1df51748b6
@ -228,6 +228,7 @@ def get_top_tracks(**keys):
|
||||
@waitfordb
|
||||
def artist_info(artist):
|
||||
|
||||
artist = sqldb.get_artist(sqldb.get_artist_id(artist))
|
||||
alltimecharts = get_charts_artists(timerange=alltime())
|
||||
scrobbles = get_scrobbles_num(artist=artist,timerange=alltime())
|
||||
#we cant take the scrobble number from the charts because that includes all countas scrobbles
|
||||
@ -235,12 +236,19 @@ def artist_info(artist):
|
||||
c = [e for e in alltimecharts if e["artist"] == artist][0]
|
||||
others = sqldb.get_associated_artists(artist)
|
||||
position = c["rank"]
|
||||
performance = get_performance(artist=artist,step="week")
|
||||
performance_weekly = get_performance(artist=artist,step="week")[:-1] #current week doesn't count
|
||||
performance_yearly = get_performance(artist=artist,step="year")[:-1] #current year doesn't count
|
||||
return {
|
||||
"artist":artist,
|
||||
"scrobbles":scrobbles,
|
||||
"position":position,
|
||||
"associated":others
|
||||
"associated":others,
|
||||
"medals":{
|
||||
"gold":[e['range'] for e in performance_yearly if e['rank'] == 1],
|
||||
"silver":[e['range'] for e in performance_yearly if e['rank'] == 2],
|
||||
"bronze":[e['range'] for e in performance_yearly if e['rank'] == 3]
|
||||
},
|
||||
"topweeks":len([e for e in performance_weekly if e['rank'] == 1])
|
||||
}
|
||||
except:
|
||||
# if the artist isnt in the charts, they are not being credited and we
|
||||
@ -254,12 +262,13 @@ def artist_info(artist):
|
||||
|
||||
|
||||
|
||||
|
||||
def track_info(track):
|
||||
charts = db_aggregate(by="TRACK")
|
||||
#scrobbles = len(db_query(artists=artists,title=title)) #chart entry of track always has right scrobble number, no countas rules here
|
||||
#c = [e for e in charts if set(e["track"]["artists"]) == set(artists) and e["track"]["title"] == title][0]
|
||||
c = [e for e in charts if e["track"] == track][0]
|
||||
|
||||
track = sqldb.get_track(sqldb.get_track_id(track))
|
||||
alltimecharts = get_charts_tracks(timerange=alltime())
|
||||
#scrobbles = get_scrobbles_num(track=track,timerange=alltime())
|
||||
|
||||
c = [e for e in alltimecharts if e["track"] == track][0]
|
||||
scrobbles = c["scrobbles"]
|
||||
position = c["rank"]
|
||||
cert = None
|
||||
@ -268,17 +277,56 @@ def track_info(track):
|
||||
elif scrobbles >= threshold_platinum: cert = "platinum"
|
||||
elif scrobbles >= threshold_gold: cert = "gold"
|
||||
|
||||
performance_weekly = get_performance(track=track,step="week")[:-1] #current week doesn't count
|
||||
performance_yearly = get_performance(track=track,step="year")[:-1] #current year doesn't count
|
||||
|
||||
|
||||
return {
|
||||
"track":track,
|
||||
"scrobbles":scrobbles,
|
||||
"position":position,
|
||||
"medals":{"gold":[],"silver":[],"bronze":[],**MEDALS_TRACKS.get((frozenset(track["artists"]),track["title"]),{})},
|
||||
"medals":{
|
||||
"gold":[e['range'] for e in performance_yearly if e['rank'] == 1],
|
||||
"silver":[e['range'] for e in performance_yearly if e['rank'] == 2],
|
||||
"bronze":[e['range'] for e in performance_yearly if e['rank'] == 3]
|
||||
},
|
||||
"certification":cert,
|
||||
"topweeks":WEEKLY_TOPTRACKS.get(((frozenset(track["artists"]),track["title"])),0)
|
||||
"topweeks":len([e for e in performance_weekly if e['rank'] == 1])
|
||||
}
|
||||
|
||||
def tracks_info(tracks):
|
||||
|
||||
tracks = [sqldb.get_track(sqldb.get_track_id(track)) for track in tracks]
|
||||
alltimecharts = get_charts_tracks(timerange=alltime())
|
||||
|
||||
result = []
|
||||
for track in tracks:
|
||||
c = [e for e in alltimecharts if e["track"] == track][0]
|
||||
scrobbles = c["scrobbles"]
|
||||
position = c["rank"]
|
||||
cert = None
|
||||
threshold_gold, threshold_platinum, threshold_diamond = malojaconfig["SCROBBLES_GOLD","SCROBBLES_PLATINUM","SCROBBLES_DIAMOND"]
|
||||
if scrobbles >= threshold_diamond: cert = "diamond"
|
||||
elif scrobbles >= threshold_platinum: cert = "platinum"
|
||||
elif scrobbles >= threshold_gold: cert = "gold"
|
||||
|
||||
performance_weekly = get_performance(track=track,step="week")[:-1] #current week doesn't count
|
||||
performance_yearly = get_performance(track=track,step="year")[:-1] #current year doesn't count
|
||||
|
||||
result.append({
|
||||
"track":track,
|
||||
"scrobbles":scrobbles,
|
||||
"position":position,
|
||||
"medals":{
|
||||
"gold":[e['range'] for e in performance_yearly if e['rank'] == 1],
|
||||
"silver":[e['range'] for e in performance_yearly if e['rank'] == 2],
|
||||
"bronze":[e['range'] for e in performance_yearly if e['rank'] == 3]
|
||||
},
|
||||
"certification":cert,
|
||||
"topweeks":len([e for e in performance_weekly if e['rank'] == 1])
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def compare(remoteurl):
|
||||
|
@ -88,7 +88,6 @@ meta.create_all(engine)
|
||||
|
||||
|
||||
### DB -> DICT
|
||||
|
||||
def scrobbles_db_to_dict(rows):
|
||||
tracks = get_tracks_map(set(row.track_id for row in rows))
|
||||
return [
|
||||
@ -100,10 +99,10 @@ def scrobbles_db_to_dict(rows):
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
|
||||
def scrobble_db_to_dict(row):
|
||||
return scrobbles_db_to_dict([row])[0]
|
||||
|
||||
|
||||
def tracks_db_to_dict(rows):
|
||||
artists = get_artists_of_tracks(set(row.id for row in rows))
|
||||
return [
|
||||
@ -114,15 +113,16 @@ def tracks_db_to_dict(rows):
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
|
||||
def track_db_to_dict(row):
|
||||
return tracks_db_to_dict([row])[0]
|
||||
|
||||
|
||||
def artists_db_to_dict(rows):
|
||||
return [
|
||||
row.name
|
||||
for row in rows
|
||||
]
|
||||
|
||||
def artist_db_to_dict(row):
|
||||
return artists_db_to_dict([row])[0]
|
||||
|
||||
@ -131,6 +131,7 @@ def artist_db_to_dict(row):
|
||||
|
||||
### DICT -> DB
|
||||
# TODO
|
||||
|
||||
def scrobble_dict_to_db(info):
|
||||
return {
|
||||
"rawscrobble":json.dumps(info),
|
||||
@ -182,7 +183,6 @@ def add_scrobbles(scrobbleslist):
|
||||
|
||||
### these will 'get' the ID of an entity, creating it if necessary
|
||||
|
||||
|
||||
def get_track_id(trackdict):
|
||||
ntitle = normalize_name(trackdict['title'])
|
||||
artist_ids = [get_artist_id(a) for a in trackdict['artists']]
|
||||
@ -260,7 +260,6 @@ def get_artist_id(artistname):
|
||||
|
||||
### Functions that get rows according to parameters
|
||||
|
||||
|
||||
def get_scrobbles_of_artist(artist,since=None,to=None):
|
||||
|
||||
if since is None: since=0
|
||||
@ -281,7 +280,6 @@ def get_scrobbles_of_artist(artist,since=None,to=None):
|
||||
#result = [scrobble_db_to_dict(row,resolve_references=resolve_references) for row in result]
|
||||
return result
|
||||
|
||||
|
||||
def get_scrobbles_of_track(track,since=None,to=None):
|
||||
|
||||
if since is None: since=0
|
||||
@ -301,7 +299,6 @@ def get_scrobbles_of_track(track,since=None,to=None):
|
||||
#result = [scrobble_db_to_dict(row) for row in result]
|
||||
return result
|
||||
|
||||
|
||||
def get_scrobbles(since=None,to=None,resolve_references=True):
|
||||
|
||||
if since is None: since=0
|
||||
@ -318,7 +315,6 @@ def get_scrobbles(since=None,to=None,resolve_references=True):
|
||||
#result = [scrobble_db_to_dict(row,resolve_references=resolve_references) for i,row in enumerate(result) if i<max]
|
||||
return result
|
||||
|
||||
|
||||
def get_artists_of_track(track_id,resolve_references=True):
|
||||
with engine.begin() as conn:
|
||||
op = DB['trackartists'].select().where(
|
||||
@ -329,7 +325,6 @@ def get_artists_of_track(track_id,resolve_references=True):
|
||||
artists = [get_artist(row.artist_id) if resolve_references else row.artist_id for row in result]
|
||||
return artists
|
||||
|
||||
|
||||
def get_tracks_of_artist(artist):
|
||||
|
||||
artist_id = get_artist_id(artist)
|
||||
@ -392,7 +387,6 @@ def count_scrobbles_by_artist(since,to):
|
||||
result = rank(result,key='scrobbles')
|
||||
return result
|
||||
|
||||
|
||||
def count_scrobbles_by_track(since,to):
|
||||
|
||||
with engine.begin() as conn:
|
||||
@ -412,7 +406,6 @@ def count_scrobbles_by_track(since,to):
|
||||
result = rank(result,key='scrobbles')
|
||||
return result
|
||||
|
||||
|
||||
def count_scrobbles_by_track_of_artist(since,to,artist):
|
||||
|
||||
artist_id = get_artist_id(artist)
|
||||
@ -529,7 +522,6 @@ def get_credited_artists(*artists):
|
||||
|
||||
### get a specific entity by id
|
||||
|
||||
|
||||
def get_track(id):
|
||||
with engine.begin() as conn:
|
||||
op = DB['tracks'].select().where(
|
||||
@ -540,7 +532,6 @@ def get_track(id):
|
||||
trackinfo = result[0]
|
||||
return track_db_to_dict(trackinfo)
|
||||
|
||||
|
||||
def get_artist(id):
|
||||
with engine.begin() as conn:
|
||||
op = DB['artists'].select().where(
|
||||
|
@ -55,13 +55,19 @@
|
||||
{% macro certs(artist) %}
|
||||
|
||||
<!-- CERTS -->
|
||||
{% for track in db.get_tracks(artist=artist) -%}
|
||||
{% set info = db.track_info(track) %}
|
||||
{% if info.certification is not none -%}
|
||||
<a href='{{ links.url(track) }}'><img class="certrecord_small"
|
||||
src="/media/record_{{ info.certification }}.png"
|
||||
title="{{ track.title }} has reached {{ info.certification.capitalize() }} status" /></a>
|
||||
|
||||
{% set charts = db.get_charts_tracks(artist=artist,timerange=malojatime.alltime()) %}
|
||||
{% for e in charts -%}
|
||||
{%- if e.scrobbles >= settings.scrobbles_gold -%}{% set cert = 'gold' %}{%- endif -%}
|
||||
{%- if e.scrobbles >= settings.scrobbles_platinum -%}{% set cert = 'platinum' %}{%- endif -%}
|
||||
{%- if e.scrobbles >= settings.scrobbles_diamond -%}{% set cert = 'diamond' %}{%- endif -%}
|
||||
|
||||
{%- if cert -%}
|
||||
<a href='{{ links.url(e.track) }}'><img class="certrecord_small"
|
||||
src="/media/record_{{ cert }}.png"
|
||||
title="{{ e.track.title }} has reached {{ cert.capitalize() }} status" /></a>
|
||||
{%- endif %}
|
||||
|
||||
{%- endfor %}
|
||||
|
||||
{%- endmacro %}
|
||||
|
Loading…
Reference in New Issue
Block a user