From aea8c15f6f25a0dcc21606e4770a87ff0854d3d1 Mon Sep 17 00:00:00 2001 From: cwilvx Date: Mon, 21 Oct 2024 10:01:41 +0300 Subject: [PATCH] fix: show stats by logged in user --- app/db/userdata.py | 7 ++++--- app/lib/home/recentlyadded.py | 33 --------------------------------- app/utils/dates.py | 4 ++-- app/utils/stats.py | 1 - 4 files changed, 6 insertions(+), 39 deletions(-) diff --git a/app/db/userdata.py b/app/db/userdata.py index f7a90d0d..2a7d838c 100644 --- a/app/db/userdata.py +++ b/app/db/userdata.py @@ -257,9 +257,9 @@ class FavoritesTable(Base): @classmethod def count_favs_in_period(cls, start_time: int, end_time: int): result = cls.execute( - select(func.count(cls.id)).where( - and_(cls.timestamp >= start_time, cls.timestamp <= end_time) - ) + select(func.count(cls.id)) + .where((cls.userid == get_current_userid())) + .where(and_(cls.timestamp >= start_time, cls.timestamp <= end_time)) ) result = result.fetchone() @@ -306,6 +306,7 @@ class ScrobbleTable(Base): def get_all_in_period(cls, start_time: int, end_time: int): result = cls.execute( select(cls) + .where(cls.userid == get_current_userid()) .where(and_(cls.timestamp >= start_time, cls.timestamp <= end_time)) .order_by(cls.timestamp.desc()) ) diff --git a/app/lib/home/recentlyadded.py b/app/lib/home/recentlyadded.py index 4c2c98ab..abb93ae6 100644 --- a/app/lib/home/recentlyadded.py +++ b/app/lib/home/recentlyadded.py @@ -55,24 +55,6 @@ def check_is_track_folder(tracks: list[Track]): return [create_track(t) for t in tracks] -# def check_is_new_artist(hashes: set[str], artisthash: str, timestamp: int): -# """ -# Checks if an artist already exists in the library. -# """ -# return artisthash not in hashes - - -# def check_is_new_album(albumhash: str, timestamp: int): -# """ -# Checks if an album already exists in the library. -# """ -# tracks = filter( -# lambda t: t.last_mod < timestamp and t.albumhash == albumhash, TrackStore.tracks -# ) - -# return next(tracks, None) is None - - def create_track(t: Track): """ Creates a recently added track entry. @@ -187,23 +169,8 @@ def group_track_by_folders(tracks: list[Track], groups: dict[str, list[Track]]): def get_recently_added_items(limit: int = 7): - # tracks = sorted(TrackStore.tracks, key=lambda t: t.created_date) - now = time() tracks = get_recently_added_tracks(start=0, limit=None) - then = time() - - print(f"Time taken to get tracks: {then - now}") groups = group_track_by_folders(tracks, {}) - # print(groups) - # last_trackcount: int = len(tracks) - - # while len(groups.keys()) < limit and last_trackcount > 0: - # distracks = get_recently_added_tracks(start=len(tracks), limit=100) - # last_trackcount = len(distracks) - - # tracks.extend(distracks) - # groups = group_track_by_folders(tracks, groups) - grouplist = [] # INFO: sort tracks by last modified date in descending order to get the most recent last modified date diff --git a/app/utils/dates.py b/app/utils/dates.py index 4ee2f47e..9d5228dd 100644 --- a/app/utils/dates.py +++ b/app/utils/dates.py @@ -15,7 +15,7 @@ def timestamp_from_days_ago(days_ago: int): return int(past_timestamp.timestamp()) -def create_new_date(date: datetime = None) -> str: +def create_new_date(date: datetime | None = None) -> str: """ Creates a new date and time string in the format of "YYYY-MM-DD HH:MM:SS" :return: A string of the current date and time. @@ -26,7 +26,7 @@ def create_new_date(date: datetime = None) -> str: return date.strftime(_format) -def timestamp_to_time_passed(timestamp: str | int): +def timestamp_to_time_passed(timestamp: str | int | float): """ Converts a timestamp to time passed. e.g. 2 minutes ago, 1 hour ago, yesterday, 2 days ago, 2 weeks ago, etc. """ diff --git a/app/utils/stats.py b/app/utils/stats.py index b09bb930..8d353b3a 100644 --- a/app/utils/stats.py +++ b/app/utils/stats.py @@ -1,7 +1,6 @@ from collections import defaultdict import copy -from pprint import pprint from typing import Any, Callable, TypeVar, List from app.db.userdata import ScrobbleTable from app.models.stats import StatItem