1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Fixed weekly #1 for ties

This commit is contained in:
Krateng 2019-06-27 11:25:11 +02:00
parent cfa0734c0a
commit ffb12045f5
2 changed files with 16 additions and 12 deletions

View File

@ -53,8 +53,8 @@ TRACK_SET = set()
MEDALS = {} #literally only changes once per year, no need to calculate that on the fly
MEDALS_TRACKS = {}
WEEKLY_TOPTRACKS = []
WEEKLY_TOPARTISTS = []
WEEKLY_TOPTRACKS = {}
WEEKLY_TOPARTISTS = {}
cla = CleanerAgent()
coa = CollectorAgent()
@ -544,7 +544,7 @@ def artistInfo(artist):
"position":position,
"associated":others,
"medals":MEDALS.get(artist),
"topweeks":len([a for a in WEEKLY_TOPARTISTS if a == artist])
"topweeks":WEEKLY_TOPARTISTS.get(artist,0)
}
except:
# if the artist isnt in the charts, they are not being credited and we
@ -589,7 +589,7 @@ def trackInfo(track):
"position":position,
"medals":MEDALS_TRACKS.get((frozenset(track["artists"]),track["title"])),
"certification":cert,
"topweeks":len([t for t in WEEKLY_TOPTRACKS if t == track])
"topweeks":WEEKLY_TOPTRACKS.get(((frozenset(track["artists"]),track["title"])),0)
}

View File

@ -472,15 +472,19 @@ def update_medals():
@daily
def update_weekly():
from database import WEEKLY_TOPTRACKS, WEEKLY_TOPARTISTS, get_top_artists, get_top_tracks
from database import WEEKLY_TOPTRACKS, WEEKLY_TOPARTISTS, get_charts_artists, get_charts_tracks
from malojatime import ranges, thisweek
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]
WEEKLY_TOPTRACKS.clear()
#print(WEEKLY_TOPTRACKS)
for week in ranges(step="week"):
if week == thisweek(): break
for a in get_charts_artists(timerange=week):
artist = a["artist"]
if a["rank"] == 1: WEEKLY_TOPARTISTS[artist] = WEEKLY_TOPARTISTS.setdefault(artist,0) + 1
for t in get_charts_tracks(timerange=week):
track = (frozenset(t["track"]["artists"]),t["track"]["title"])
if t["rank"] == 1: WEEKLY_TOPTRACKS[track] = WEEKLY_TOPTRACKS.setdefault(track,0) + 1