fix: show stats by logged in user

This commit is contained in:
cwilvx
2024-10-21 10:01:41 +03:00
parent a7666ad935
commit aea8c15f6f
4 changed files with 6 additions and 39 deletions
+4 -3
View File
@@ -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())
)
-33
View File
@@ -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
+2 -2
View File
@@ -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.
"""
-1
View File
@@ -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