From ffb12045f5d94f6e1dcfc9e467b7629a812d66b8 Mon Sep 17 00:00:00 2001 From: Krateng Date: Thu, 27 Jun 2019 11:25:11 +0200 Subject: [PATCH] Fixed weekly #1 for ties --- database.py | 8 ++++---- utilities.py | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/database.py b/database.py index 6b62651..3595bab 100644 --- a/database.py +++ b/database.py @@ -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) } diff --git a/utilities.py b/utilities.py index e0c6c6c..5b242d6 100644 --- a/utilities.py +++ b/utilities.py @@ -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