refactor(types): aggregate dashboard counts with integer totals

This commit is contained in:
jxxghp
2026-10-16 18:03:24 +08:00
parent 47e5f1ada1
commit 910df799fd
6 changed files with 59 additions and 14 deletions

View File

@@ -42,18 +42,23 @@ class DashboardQueryService:
"""返回媒体服务总量和本月新增量。"""
media_statistics = self._media_statistics(name)
if media_statistics:
result = Statistic()
movie_count = tv_count = music_count = user_count = episode_count = 0
has_episode_count = False
for item in media_statistics:
result.movie_count += item.movie_count or 0
result.tv_count += item.tv_count or 0
result.music_count += item.music_count or 0
result.user_count += item.user_count or 0
movie_count += item.movie_count or 0
tv_count += item.tv_count or 0
music_count += item.music_count or 0
user_count += item.user_count or 0
if item.episode_count is not None:
result.episode_count += item.episode_count or 0
episode_count += item.episode_count or 0
has_episode_count = True
if not has_episode_count:
result.episode_count = None
result = Statistic(
movie_count=movie_count,
tv_count=tv_count,
music_count=music_count,
user_count=user_count,
episode_count=episode_count if has_episode_count else None,
)
else:
result = Statistic()

View File

@@ -75,7 +75,7 @@ uv run --locked --no-sync python scripts/architecture/complexity.py
回调和返回值类型;全仓错误计数为零并不保证单独纳入 strict frontier 后也为零。
2026-10-16 开始逐文件清理类型债务,`app/domain/title.py` 通过局部可空类型声明保留
既有搜索解析行为,并纳入严格清单;当前清单共 101 个文件(100 个生产文件和 1 个脚本)。
既有搜索解析行为,并纳入严格清单;当前清单共 102 个文件(101 个生产文件和 1 个脚本)。
每个治理提交聚焦一个生产文件及其必要测试、门禁配置、真实下降基线和指标文档。
验收同时检查完整严格清单与全宿主 Linux 分析,避免 `follow_imports = skip` 隐藏依赖
签名冲突;不通过忽略诊断或放宽类型合同接受回退。最新文件清单以 `mypy.ini` 为准,

View File

@@ -106,9 +106,9 @@ ARCH-201 至 ARCH-204 均达到实现、验证、提交、推送和远端门禁
| Model/Oper 事务债务 | 0 | 自建 Session、自动事务装饰器、直接 commit/rollback 等基线均为零 |
| Module Contract | 215 specs / 211 methods / 263 calls | 动态方法名为 0;分类事实富化通过显式合同进入插件调度,旧 YAML 分类方法已移除;download 新增 custom_words 可选参数,旧 provider 签名通过显式合同兼容 |
| Event Contract | 53 | 均已有 payload model,但当前全部是 diagnostic enforcement |
| Python 源码量 | 372,311 行 | 本次重新扫描物理行数,排除 `app/plugins/**`;74 个文件超过 1,000 行,12 个超过 2,000 行;源码尺寸仅作观察 |
| Python 源码量 | 372,316 行 | 本次重新扫描物理行数,排除 `app/plugins/**`;74 个文件超过 1,000 行,12 个超过 2,000 行;源码尺寸仅作观察 |
| 长方法 | 309 个超过 80 行 | 本次 AST 扫描排除 `app/plugins/**`;61 个超过 150 行,17 个超过 250 行;新增函数仍受 C901/嵌套深度门禁约束 |
| 全量 mypy 历史债务 | 8,819 / 453 文件 | 通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项;Transmission 进度回退值归一化再减少 2 项,逐文件逐错误码无增长 |
| 全量 mypy 历史债务 | 8,814 / 452 文件 | 通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项;Transmission 进度回退值归一化再减少 2 项,逐文件逐错误码无增长 |
| Ruff 历史诊断 | 98 | 低水位门禁通过,但规则集只覆盖 `E4/E7/E9/F/I` |
| 覆盖率固定基线 | Application 80.00%,Domain 80.00% | Chain、Runtime、Agent、Adapter、Startup 未进入包级覆盖率门禁 |

View File

@@ -75,6 +75,7 @@ files =
app/application/security/token.py,
app/application/commands.py,
app/application/agent.py,
app/application/dashboard.py,
app/application/outbox.py,
app/application/torrent/cache.py,
app/application/configuration.py,

View File

@@ -573,9 +573,6 @@
"return": 1,
"type-arg": 1
},
"app/application/dashboard.py": {
"operator": 5
},
"app/application/directory.py": {
"arg-type": 6,
"assignment": 2,

View File

@@ -0,0 +1,42 @@
"""仪表板统计中未知数量、零数量和月度增量的契约。"""
from types import SimpleNamespace
from unittest.mock import Mock
import pytest
from app.application.dashboard import DashboardQueryService
from app.application.history import TransferHistoryMonthlyStatistics
from app.schemas.dashboard import Statistic
@pytest.mark.parametrize(
("episode_counts", "expected_episodes"),
[(None, 0), ([], 0), ([None], None), ([None, None], None), ([None, 0], 0), ([None, 3, 5], 8)],
)
def test_statistics_distinguishes_unknown_episodes_from_zero(episode_counts, expected_episodes):
"""缺少媒体服务、未知集数和已知零集数应保持不同返回语义。"""
rows = None if episode_counts is None else [
Statistic(movie_count=2, tv_count=None, music_count=1, user_count=None, episode_count=count)
for count in episode_counts
]
provide_statistics = Mock(return_value=rows)
monthly_statistics = Mock(return_value=TransferHistoryMonthlyStatistics(
movies=10, tv_shows=20, episodes=30, music=40,
))
service = DashboardQueryService(
repository=SimpleNamespace(monthly_media_statistics=monthly_statistics),
media_statistics=provide_statistics,
)
result = service.statistic(name="选定媒体库")
assert result.episode_count == expected_episodes
assert result.movie_count == 2 * len(rows or [])
assert result.music_count == len(rows or [])
assert result.tv_count == result.user_count == 0
assert (result.movie_count_month, result.tv_count_month,
result.episode_count_month, result.music_count_month) == (10, 20, 30, 40)
assert rows is None or [row.episode_count for row in rows] == episode_counts
provide_statistics.assert_called_once_with("选定媒体库")
monthly_statistics.assert_called_once_with()