feat: Add dashboard API endpoints and service for sound statistics
This commit is contained in:
@@ -178,3 +178,49 @@ class SoundRepository(BaseRepository[Sound]):
|
||||
search_query, sound_types, sort_by, sort_order
|
||||
)
|
||||
raise
|
||||
|
||||
async def get_soundboard_statistics(self) -> dict[str, int | float]:
|
||||
"""Get statistics for SDB type sounds."""
|
||||
try:
|
||||
statement = select(
|
||||
func.count(Sound.id).label("count"),
|
||||
func.sum(Sound.play_count).label("total_plays"),
|
||||
func.sum(Sound.duration).label("total_duration"),
|
||||
func.sum(Sound.size + func.coalesce(Sound.normalized_size, 0)).label("total_size")
|
||||
).where(Sound.type == "SDB")
|
||||
|
||||
result = await self.session.exec(statement)
|
||||
row = result.first()
|
||||
|
||||
return {
|
||||
"count": row.count if row.count is not None else 0,
|
||||
"total_plays": row.total_plays if row.total_plays is not None else 0,
|
||||
"total_duration": row.total_duration if row.total_duration is not None else 0,
|
||||
"total_size": row.total_size if row.total_size is not None else 0
|
||||
}
|
||||
except Exception:
|
||||
logger.exception("Failed to get soundboard statistics")
|
||||
raise
|
||||
|
||||
async def get_track_statistics(self) -> dict[str, int | float]:
|
||||
"""Get statistics for EXT type sounds."""
|
||||
try:
|
||||
statement = select(
|
||||
func.count(Sound.id).label("count"),
|
||||
func.sum(Sound.play_count).label("total_plays"),
|
||||
func.sum(Sound.duration).label("total_duration"),
|
||||
func.sum(Sound.size + func.coalesce(Sound.normalized_size, 0)).label("total_size")
|
||||
).where(Sound.type == "EXT")
|
||||
|
||||
result = await self.session.exec(statement)
|
||||
row = result.first()
|
||||
|
||||
return {
|
||||
"count": row.count if row.count is not None else 0,
|
||||
"total_plays": row.total_plays if row.total_plays is not None else 0,
|
||||
"total_duration": row.total_duration if row.total_duration is not None else 0,
|
||||
"total_size": row.total_size if row.total_size is not None else 0
|
||||
}
|
||||
except Exception:
|
||||
logger.exception("Failed to get track statistics")
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user