mirror of
https://github.com/krateng/maloja.git
synced 2025-06-12 21:32:12 +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
|
@waitfordb
|
||||||
def artist_info(artist):
|
def artist_info(artist):
|
||||||
|
|
||||||
|
artist = sqldb.get_artist(sqldb.get_artist_id(artist))
|
||||||
alltimecharts = get_charts_artists(timerange=alltime())
|
alltimecharts = get_charts_artists(timerange=alltime())
|
||||||
scrobbles = get_scrobbles_num(artist=artist,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
|
#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]
|
c = [e for e in alltimecharts if e["artist"] == artist][0]
|
||||||
others = sqldb.get_associated_artists(artist)
|
others = sqldb.get_associated_artists(artist)
|
||||||
position = c["rank"]
|
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 {
|
return {
|
||||||
"artist":artist,
|
"artist":artist,
|
||||||
"scrobbles":scrobbles,
|
"scrobbles":scrobbles,
|
||||||
"position":position,
|
"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:
|
except:
|
||||||
# if the artist isnt in the charts, they are not being credited and we
|
# 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):
|
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
|
track = sqldb.get_track(sqldb.get_track_id(track))
|
||||||
#c = [e for e in charts if set(e["track"]["artists"]) == set(artists) and e["track"]["title"] == title][0]
|
alltimecharts = get_charts_tracks(timerange=alltime())
|
||||||
c = [e for e in charts if e["track"] == track][0]
|
#scrobbles = get_scrobbles_num(track=track,timerange=alltime())
|
||||||
|
|
||||||
|
c = [e for e in alltimecharts if e["track"] == track][0]
|
||||||
scrobbles = c["scrobbles"]
|
scrobbles = c["scrobbles"]
|
||||||
position = c["rank"]
|
position = c["rank"]
|
||||||
cert = None
|
cert = None
|
||||||
@ -268,17 +277,56 @@ def track_info(track):
|
|||||||
elif scrobbles >= threshold_platinum: cert = "platinum"
|
elif scrobbles >= threshold_platinum: cert = "platinum"
|
||||||
elif scrobbles >= threshold_gold: cert = "gold"
|
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 {
|
return {
|
||||||
"track":track,
|
"track":track,
|
||||||
"scrobbles":scrobbles,
|
"scrobbles":scrobbles,
|
||||||
"position":position,
|
"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,
|
"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):
|
def compare(remoteurl):
|
||||||
|
@ -88,7 +88,6 @@ meta.create_all(engine)
|
|||||||
|
|
||||||
|
|
||||||
### DB -> DICT
|
### DB -> DICT
|
||||||
|
|
||||||
def scrobbles_db_to_dict(rows):
|
def scrobbles_db_to_dict(rows):
|
||||||
tracks = get_tracks_map(set(row.track_id for row in rows))
|
tracks = get_tracks_map(set(row.track_id for row in rows))
|
||||||
return [
|
return [
|
||||||
@ -100,10 +99,10 @@ def scrobbles_db_to_dict(rows):
|
|||||||
}
|
}
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
|
|
||||||
def scrobble_db_to_dict(row):
|
def scrobble_db_to_dict(row):
|
||||||
return scrobbles_db_to_dict([row])[0]
|
return scrobbles_db_to_dict([row])[0]
|
||||||
|
|
||||||
|
|
||||||
def tracks_db_to_dict(rows):
|
def tracks_db_to_dict(rows):
|
||||||
artists = get_artists_of_tracks(set(row.id for row in rows))
|
artists = get_artists_of_tracks(set(row.id for row in rows))
|
||||||
return [
|
return [
|
||||||
@ -114,15 +113,16 @@ def tracks_db_to_dict(rows):
|
|||||||
}
|
}
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
|
|
||||||
def track_db_to_dict(row):
|
def track_db_to_dict(row):
|
||||||
return tracks_db_to_dict([row])[0]
|
return tracks_db_to_dict([row])[0]
|
||||||
|
|
||||||
|
|
||||||
def artists_db_to_dict(rows):
|
def artists_db_to_dict(rows):
|
||||||
return [
|
return [
|
||||||
row.name
|
row.name
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
|
|
||||||
def artist_db_to_dict(row):
|
def artist_db_to_dict(row):
|
||||||
return artists_db_to_dict([row])[0]
|
return artists_db_to_dict([row])[0]
|
||||||
|
|
||||||
@ -131,6 +131,7 @@ def artist_db_to_dict(row):
|
|||||||
|
|
||||||
### DICT -> DB
|
### DICT -> DB
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
def scrobble_dict_to_db(info):
|
def scrobble_dict_to_db(info):
|
||||||
return {
|
return {
|
||||||
"rawscrobble":json.dumps(info),
|
"rawscrobble":json.dumps(info),
|
||||||
@ -182,7 +183,6 @@ def add_scrobbles(scrobbleslist):
|
|||||||
|
|
||||||
### these will 'get' the ID of an entity, creating it if necessary
|
### these will 'get' the ID of an entity, creating it if necessary
|
||||||
|
|
||||||
|
|
||||||
def get_track_id(trackdict):
|
def get_track_id(trackdict):
|
||||||
ntitle = normalize_name(trackdict['title'])
|
ntitle = normalize_name(trackdict['title'])
|
||||||
artist_ids = [get_artist_id(a) for a in trackdict['artists']]
|
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
|
### Functions that get rows according to parameters
|
||||||
|
|
||||||
|
|
||||||
def get_scrobbles_of_artist(artist,since=None,to=None):
|
def get_scrobbles_of_artist(artist,since=None,to=None):
|
||||||
|
|
||||||
if since is None: since=0
|
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]
|
#result = [scrobble_db_to_dict(row,resolve_references=resolve_references) for row in result]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_scrobbles_of_track(track,since=None,to=None):
|
def get_scrobbles_of_track(track,since=None,to=None):
|
||||||
|
|
||||||
if since is None: since=0
|
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]
|
#result = [scrobble_db_to_dict(row) for row in result]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_scrobbles(since=None,to=None,resolve_references=True):
|
def get_scrobbles(since=None,to=None,resolve_references=True):
|
||||||
|
|
||||||
if since is None: since=0
|
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]
|
#result = [scrobble_db_to_dict(row,resolve_references=resolve_references) for i,row in enumerate(result) if i<max]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_artists_of_track(track_id,resolve_references=True):
|
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(
|
||||||
@ -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]
|
artists = [get_artist(row.artist_id) if resolve_references else row.artist_id for row in result]
|
||||||
return artists
|
return artists
|
||||||
|
|
||||||
|
|
||||||
def get_tracks_of_artist(artist):
|
def get_tracks_of_artist(artist):
|
||||||
|
|
||||||
artist_id = get_artist_id(artist)
|
artist_id = get_artist_id(artist)
|
||||||
@ -392,7 +387,6 @@ def count_scrobbles_by_artist(since,to):
|
|||||||
result = rank(result,key='scrobbles')
|
result = rank(result,key='scrobbles')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def count_scrobbles_by_track(since,to):
|
def count_scrobbles_by_track(since,to):
|
||||||
|
|
||||||
with engine.begin() as conn:
|
with engine.begin() as conn:
|
||||||
@ -412,7 +406,6 @@ def count_scrobbles_by_track(since,to):
|
|||||||
result = rank(result,key='scrobbles')
|
result = rank(result,key='scrobbles')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def count_scrobbles_by_track_of_artist(since,to,artist):
|
def count_scrobbles_by_track_of_artist(since,to,artist):
|
||||||
|
|
||||||
artist_id = get_artist_id(artist)
|
artist_id = get_artist_id(artist)
|
||||||
@ -529,7 +522,6 @@ def get_credited_artists(*artists):
|
|||||||
|
|
||||||
### get a specific entity by id
|
### get a specific entity by id
|
||||||
|
|
||||||
|
|
||||||
def get_track(id):
|
def get_track(id):
|
||||||
with engine.begin() as conn:
|
with engine.begin() as conn:
|
||||||
op = DB['tracks'].select().where(
|
op = DB['tracks'].select().where(
|
||||||
@ -540,7 +532,6 @@ def get_track(id):
|
|||||||
trackinfo = result[0]
|
trackinfo = result[0]
|
||||||
return track_db_to_dict(trackinfo)
|
return track_db_to_dict(trackinfo)
|
||||||
|
|
||||||
|
|
||||||
def get_artist(id):
|
def get_artist(id):
|
||||||
with engine.begin() as conn:
|
with engine.begin() as conn:
|
||||||
op = DB['artists'].select().where(
|
op = DB['artists'].select().where(
|
||||||
|
@ -55,13 +55,19 @@
|
|||||||
{% macro certs(artist) %}
|
{% macro certs(artist) %}
|
||||||
|
|
||||||
<!-- CERTS -->
|
<!-- CERTS -->
|
||||||
{% for track in db.get_tracks(artist=artist) -%}
|
|
||||||
{% set info = db.track_info(track) %}
|
{% set charts = db.get_charts_tracks(artist=artist,timerange=malojatime.alltime()) %}
|
||||||
{% if info.certification is not none -%}
|
{% for e in charts -%}
|
||||||
<a href='{{ links.url(track) }}'><img class="certrecord_small"
|
{%- if e.scrobbles >= settings.scrobbles_gold -%}{% set cert = 'gold' %}{%- endif -%}
|
||||||
src="/media/record_{{ info.certification }}.png"
|
{%- if e.scrobbles >= settings.scrobbles_platinum -%}{% set cert = 'platinum' %}{%- endif -%}
|
||||||
title="{{ track.title }} has reached {{ info.certification.capitalize() }} status" /></a>
|
{%- 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 %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user