mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
fix: new artists played report on charts
This commit is contained in:
@@ -200,7 +200,7 @@ def get_top_artists(query: ChartItemsQuery):
|
|||||||
current_period_artists = get_artists_in_period(start_time, end_time)
|
current_period_artists = get_artists_in_period(start_time, end_time)
|
||||||
previous_period_artists = get_artists_in_period(previous_start_time, start_time)
|
previous_period_artists = get_artists_in_period(previous_start_time, start_time)
|
||||||
|
|
||||||
new_artists = calculate_new_artists(current_period_artists, previous_period_artists)
|
new_artists = calculate_new_artists(current_period_artists, start_time)
|
||||||
scrobble_trend = calculate_scrobble_trend(
|
scrobble_trend = calculate_scrobble_trend(
|
||||||
len(current_period_artists), len(previous_period_artists)
|
len(current_period_artists), len(previous_period_artists)
|
||||||
)
|
)
|
||||||
|
|||||||
+24
-5
@@ -63,7 +63,9 @@ def get_tracks_in_period(start_time: int, end_time: int):
|
|||||||
for scrobble in scrobbles:
|
for scrobble in scrobbles:
|
||||||
if scrobble.trackhash not in tracks:
|
if scrobble.trackhash not in tracks:
|
||||||
try:
|
try:
|
||||||
track = copy.deepcopy(TrackStore.get_tracks_by_trackhashes([scrobble.trackhash])[0])
|
track = copy.deepcopy(
|
||||||
|
TrackStore.get_tracks_by_trackhashes([scrobble.trackhash])[0]
|
||||||
|
)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -153,11 +155,28 @@ def calculate_scrobble_trend(current_scrobbles: int, previous_scrobbles: int) ->
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def calculate_new_artists(
|
def calculate_new_artists(current_artists: List[dict[str, Any]], timestamp: int):
|
||||||
current_artists: List[dict[str, Any]], previous_artists: List[dict[str, Any]]
|
"""
|
||||||
):
|
Calculate the number of new artists based on the current and all previous scrobbles.
|
||||||
|
"""
|
||||||
current_artists_set = set(artist["artisthash"] for artist in current_artists)
|
current_artists_set = set(artist["artisthash"] for artist in current_artists)
|
||||||
previous_artists_set = set(artist["artisthash"] for artist in previous_artists)
|
all_records = ScrobbleTable.get_all(0, None)
|
||||||
|
trackhashes = set(
|
||||||
|
record.trackhash for record in all_records if record.timestamp < timestamp
|
||||||
|
)
|
||||||
|
|
||||||
|
previous_artists_set = set()
|
||||||
|
|
||||||
|
for record in trackhashes:
|
||||||
|
entry = TrackStore.trackhashmap.get(record)
|
||||||
|
if not entry:
|
||||||
|
continue
|
||||||
|
|
||||||
|
entry = entry.tracks[0]
|
||||||
|
|
||||||
|
for artist in entry.artists:
|
||||||
|
artisthash = artist["artisthash"]
|
||||||
|
previous_artists_set.add(artisthash)
|
||||||
|
|
||||||
return len(current_artists_set - previous_artists_set)
|
return len(current_artists_set - previous_artists_set)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user