mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 13:03:02 +00:00
fix: show stats by logged in user
This commit is contained in:
+4
-3
@@ -257,9 +257,9 @@ class FavoritesTable(Base):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def count_favs_in_period(cls, start_time: int, end_time: int):
|
def count_favs_in_period(cls, start_time: int, end_time: int):
|
||||||
result = cls.execute(
|
result = cls.execute(
|
||||||
select(func.count(cls.id)).where(
|
select(func.count(cls.id))
|
||||||
and_(cls.timestamp >= start_time, cls.timestamp <= end_time)
|
.where((cls.userid == get_current_userid()))
|
||||||
)
|
.where(and_(cls.timestamp >= start_time, cls.timestamp <= end_time))
|
||||||
)
|
)
|
||||||
|
|
||||||
result = result.fetchone()
|
result = result.fetchone()
|
||||||
@@ -306,6 +306,7 @@ class ScrobbleTable(Base):
|
|||||||
def get_all_in_period(cls, start_time: int, end_time: int):
|
def get_all_in_period(cls, start_time: int, end_time: int):
|
||||||
result = cls.execute(
|
result = cls.execute(
|
||||||
select(cls)
|
select(cls)
|
||||||
|
.where(cls.userid == get_current_userid())
|
||||||
.where(and_(cls.timestamp >= start_time, cls.timestamp <= end_time))
|
.where(and_(cls.timestamp >= start_time, cls.timestamp <= end_time))
|
||||||
.order_by(cls.timestamp.desc())
|
.order_by(cls.timestamp.desc())
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -55,24 +55,6 @@ def check_is_track_folder(tracks: list[Track]):
|
|||||||
return [create_track(t) for t in tracks]
|
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):
|
def create_track(t: Track):
|
||||||
"""
|
"""
|
||||||
Creates a recently added track entry.
|
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):
|
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)
|
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, {})
|
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 = []
|
grouplist = []
|
||||||
|
|
||||||
# INFO: sort tracks by last modified date in descending order to get the most recent last modified date
|
# INFO: sort tracks by last modified date in descending order to get the most recent last modified date
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ def timestamp_from_days_ago(days_ago: int):
|
|||||||
return int(past_timestamp.timestamp())
|
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"
|
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.
|
: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)
|
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.
|
Converts a timestamp to time passed. e.g. 2 minutes ago, 1 hour ago, yesterday, 2 days ago, 2 weeks ago, etc.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from pprint import pprint
|
|
||||||
from typing import Any, Callable, TypeVar, List
|
from typing import Any, Callable, TypeVar, List
|
||||||
from app.db.userdata import ScrobbleTable
|
from app.db.userdata import ScrobbleTable
|
||||||
from app.models.stats import StatItem
|
from app.models.stats import StatItem
|
||||||
|
|||||||
Reference in New Issue
Block a user