Coverage for seedboxsync/front/views/frontend/stats.py: 100%
15 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-26 17:14 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-26 17:14 +0000
1#
2# Copyright (C) 2015-2026 Guillaume Kulakowski <guillaume@kulakowski.fr>
3#
4# For the full copyright and license information, please view the LICENSE
5# file that was distributed with this source code.
6#
7"""SeedboxSync Flask view for stats."""
9from flask import render_template
10from humanize import filesize
11from seedboxsync.core.database.models import Download
12from seedboxsync.front.cache import cached
13from seedboxsync.front.login_manager import login_required
14from seedboxsync.front.views import bp_frontend as bp
17@bp.route("/stats")
18@cached(timeout=300) # pyright: ignore [reportUntypedFunctionDecorator]
19@login_required # type: ignore[untyped-decorator]
20def stats() -> str:
21 """
22 Render the statistics view.
24 Calculates the total number of finished downloads and their cumulative file
25 size, formats the size in human-readable format, and renders the stats page
26 (cached for 5 minutes).
28 Returns:
29 str: Rendered HTML template containing the summary statistics.
30 """
31 query = Download.select().where(Download.finished != 0)
32 total_files = query.count()
33 total_size = sum([d.seedbox_size for d in query if d.seedbox_size])
35 stats_total = {
36 "files": total_files,
37 "total_size": filesize.naturalsize(total_size, True),
38 }
40 return render_template("stats.html", stats_total=stats_total)