mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Enabled caching of weekly #1
This commit is contained in:
parent
495b00803d
commit
cfa0734c0a
10
database.py
10
database.py
@ -50,8 +50,11 @@ TRACKS_LOWER = []
|
|||||||
ARTISTS_LOWER = []
|
ARTISTS_LOWER = []
|
||||||
ARTIST_SET = set()
|
ARTIST_SET = set()
|
||||||
TRACK_SET = set()
|
TRACK_SET = set()
|
||||||
|
|
||||||
MEDALS = {} #literally only changes once per year, no need to calculate that on the fly
|
MEDALS = {} #literally only changes once per year, no need to calculate that on the fly
|
||||||
MEDALS_TRACKS = {}
|
MEDALS_TRACKS = {}
|
||||||
|
WEEKLY_TOPTRACKS = []
|
||||||
|
WEEKLY_TOPARTISTS = []
|
||||||
|
|
||||||
cla = CleanerAgent()
|
cla = CleanerAgent()
|
||||||
coa = CollectorAgent()
|
coa = CollectorAgent()
|
||||||
@ -541,7 +544,7 @@ def artistInfo(artist):
|
|||||||
"position":position,
|
"position":position,
|
||||||
"associated":others,
|
"associated":others,
|
||||||
"medals":MEDALS.get(artist),
|
"medals":MEDALS.get(artist),
|
||||||
"topweeks":len([p for p in performance if p["rank"] == 1])
|
"topweeks":len([a for a in WEEKLY_TOPARTISTS if a == artist])
|
||||||
}
|
}
|
||||||
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
|
||||||
@ -574,19 +577,19 @@ def trackInfo(track):
|
|||||||
c = [e for e in charts if e["track"] == track][0]
|
c = [e for e in charts if e["track"] == track][0]
|
||||||
scrobbles = c["scrobbles"]
|
scrobbles = c["scrobbles"]
|
||||||
position = c["rank"]
|
position = c["rank"]
|
||||||
performance = get_performance(track=track,step="week")
|
|
||||||
cert = None
|
cert = None
|
||||||
threshold_gold, threshold_platinum, threshold_diamond = settings.get_settings("SCROBBLES_GOLD","SCROBBLES_PLATINUM","SCROBBLES_DIAMOND")
|
threshold_gold, threshold_platinum, threshold_diamond = settings.get_settings("SCROBBLES_GOLD","SCROBBLES_PLATINUM","SCROBBLES_DIAMOND")
|
||||||
if scrobbles >= threshold_diamond: cert = "diamond"
|
if scrobbles >= threshold_diamond: cert = "diamond"
|
||||||
elif scrobbles >= threshold_platinum: cert = "platinum"
|
elif scrobbles >= threshold_platinum: cert = "platinum"
|
||||||
elif scrobbles >= threshold_gold: cert = "gold"
|
elif scrobbles >= threshold_gold: cert = "gold"
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"scrobbles":scrobbles,
|
"scrobbles":scrobbles,
|
||||||
"position":position,
|
"position":position,
|
||||||
"medals":MEDALS_TRACKS.get((frozenset(track["artists"]),track["title"])),
|
"medals":MEDALS_TRACKS.get((frozenset(track["artists"]),track["title"])),
|
||||||
"certification":cert,
|
"certification":cert,
|
||||||
"topweeks":len([p for p in performance if p["rank"] == 1])
|
"topweeks":len([t for t in WEEKLY_TOPTRACKS if t == track])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -913,6 +916,7 @@ def build_db():
|
|||||||
|
|
||||||
#start regular tasks
|
#start regular tasks
|
||||||
utilities.update_medals()
|
utilities.update_medals()
|
||||||
|
utilities.update_weekly()
|
||||||
|
|
||||||
global db_rulestate
|
global db_rulestate
|
||||||
db_rulestate = utilities.consistentRulestate("scrobbles",cla.checksums)
|
db_rulestate = utilities.consistentRulestate("scrobbles",cla.checksums)
|
||||||
|
16
utilities.py
16
utilities.py
@ -468,3 +468,19 @@ def update_medals():
|
|||||||
elif t["rank"] == 2: MEDALS_TRACKS.setdefault(track,{}).setdefault("silver",[]).append(year)
|
elif t["rank"] == 2: MEDALS_TRACKS.setdefault(track,{}).setdefault("silver",[]).append(year)
|
||||||
elif t["rank"] == 3: MEDALS_TRACKS.setdefault(track,{}).setdefault("bronze",[]).append(year)
|
elif t["rank"] == 3: MEDALS_TRACKS.setdefault(track,{}).setdefault("bronze",[]).append(year)
|
||||||
else: break
|
else: break
|
||||||
|
|
||||||
|
@daily
|
||||||
|
def update_weekly():
|
||||||
|
|
||||||
|
from database import WEEKLY_TOPTRACKS, WEEKLY_TOPARTISTS, get_top_artists, get_top_tracks
|
||||||
|
|
||||||
|
topartists = get_top_artists(step="week")
|
||||||
|
toptracks = get_top_tracks(step="week")
|
||||||
|
|
||||||
|
WEEKLY_TOPTRACKS.clear()
|
||||||
|
WEEKLY_TOPTRACKS += [t["track"] for t in toptracks][:-1]
|
||||||
|
|
||||||
|
WEEKLY_TOPARTISTS.clear()
|
||||||
|
WEEKLY_TOPARTISTS += [t["artist"] for t in topartists][:-1]
|
||||||
|
|
||||||
|
#print(WEEKLY_TOPTRACKS)
|
||||||
|
Loading…
Reference in New Issue
Block a user