mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
first recommendation draft
This commit is contained in:
+10
-3
@@ -66,16 +66,23 @@ def seconds_to_time_string(seconds):
|
||||
return f"{remaining_seconds} sec"
|
||||
|
||||
|
||||
def get_date_range(duration: str):
|
||||
def get_date_range(duration: str, units_ago: int = 0):
|
||||
"""
|
||||
Returns a tuple of dates representing the start and end of a given duration.
|
||||
"""
|
||||
date_range = None
|
||||
seconds_ago = (
|
||||
pendulum.now() - pendulum.now().subtract().start_of(duration)
|
||||
).total_seconds() * units_ago
|
||||
print("seconds_ago", duration, str(seconds_ago))
|
||||
|
||||
match duration:
|
||||
case "week" | "month" | "year":
|
||||
case "day" | "week" | "month" | "year":
|
||||
date_range = (
|
||||
pendulum.now().subtract().start_of(duration).timestamp(),
|
||||
pendulum.now()
|
||||
.subtract(seconds=seconds_ago)
|
||||
.start_of(duration)
|
||||
.timestamp(),
|
||||
pendulum.now().end_of(duration).timestamp(),
|
||||
)
|
||||
case "alltime":
|
||||
|
||||
+4
-2
@@ -13,7 +13,7 @@ from app.utils.dates import seconds_to_time_string
|
||||
|
||||
def get_artists_in_period(start_time: int, end_time: int):
|
||||
scrobbles = ScrobbleTable.get_all_in_period(start_time, end_time)
|
||||
artists = defaultdict(lambda: {"playcount": 0, "playduration": 0})
|
||||
artists: Any = defaultdict(lambda: {"playcount": 0, "playduration": 0})
|
||||
|
||||
for scrobble in scrobbles:
|
||||
track = TrackStore.get_tracks_by_trackhashes([scrobble.trackhash])
|
||||
@@ -24,11 +24,13 @@ def get_artists_in_period(start_time: int, end_time: int):
|
||||
for artist in track.artists:
|
||||
artisthash = artist["artisthash"]
|
||||
|
||||
artists[artisthash]["artist"] = artist["name"]
|
||||
artists[artisthash]["artisthash"] = artist["artisthash"]
|
||||
artists[artisthash]["playcount"] += 1
|
||||
artists[artisthash]["playduration"] += scrobble.duration
|
||||
|
||||
return list(artists.values())
|
||||
artists = list(artists.values())
|
||||
return sorted(artists, key=lambda x: x["playduration"], reverse=True)
|
||||
|
||||
|
||||
def get_albums_in_period(start_time: int, end_time: int):
|
||||
|
||||
Reference in New Issue
Block a user