Skip to content

Commit

Permalink
[132] Deprecate the root statistics API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinHeist committed Aug 28, 2024
1 parent f49b03a commit 8c6ce13
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
77 changes: 75 additions & 2 deletions app/routers/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
)


@statistics_router.get('/')
def get_all_statistics(
@statistics_router.get('/', deprecated=True)
def get_all_statistics_deprecated(
db: Session = Depends(get_database),
preferences: Preferences = Depends(get_preferences),
) -> list[Statistic]:
Expand Down Expand Up @@ -106,6 +106,79 @@ def get_all_statistics(
]


@statistics_router.get('/system')
def get_system_statistics(
db: Session = Depends(get_database),
preferences: Preferences = Depends(get_preferences),
) -> list[Statistic]:
"""Get all system statistics."""

# Count objects
card_count = db.query(Card).count()
episode_count = db.query(Episode).count()
font_count = db.query(Font).count()
loaded_count = db.query(Loaded).count()
series_count = db.query(Series).count()
monitored_count = db.query(Series).filter_by(monitored=True).count()
unmonitored_count = db.query(Series).filter_by(monitored=False).count()
sync_count = db.query(Sync).count()
template_count = db.query(Template).count()

# Get and format total asset size | pylint: disable=not-callable
asset_size = db.query(Card)\
.with_entities(func.sum(Card.filesize))\
.scalar()
asset_size = 0 if asset_size is None else asset_size
formatted_filesize = preferences.format_filesize(asset_size)

return [
Statistic(
value=card_count, value_text=f'{card_count:,}', unit='Cards',
description='Number of Title Cards',
),
Statistic(
value=series_count, value_text=f'{series_count:,}', unit='Series',
description='Number of Series',
),
Statistic(
value=monitored_count, value_text=f'{monitored_count:,}',
unit='Monitored',
description='Number of Monitored Series',
),
Statistic(
value=unmonitored_count, value_text=f'{unmonitored_count:,}',
unit='Unmonitored',
description='Number of Unmonitored Series',
),
Statistic(
value=episode_count, value_text=f'{episode_count:,}',
unit='Episodes',
description='Number of Episodes',
),
Statistic(
value=asset_size, value_text=formatted_filesize[0],
unit=formatted_filesize[1],
description='File size of all Title Cards',
),
Statistic(
value=font_count, value_text=f'{font_count:,}', unit='Fonts',
description='Number of Named Fonts',
),
Statistic(
value=template_count, value_text=f'{template_count:,}',
unit='Templates', description='Number of Templates',
),
Statistic(
value=sync_count, value_text=f'{sync_count:,}', unit='Syncs',
description='Number of Syncs',
),
Statistic(
value=loaded_count, value_text=f'{loaded_count:,}',
unit='Loaded Cards', description='Number of loaded Title Cards',
)
]


@statistics_router.get('/series/{series_id}')
def get_series_statistics(
series_id: int,
Expand Down
2 changes: 1 addition & 1 deletion modules/ref/version_webui
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0-alpha.11.0-webui131
v2.0-alpha.11.0-webui132

0 comments on commit 8c6ce13

Please sign in to comment.