fix(api): 標示全零週報資料鏈異常
All checks were successful
Code Review / ai-code-review (push) Successful in 22s
CD Pipeline / tests (push) Successful in 1m40s
CD Pipeline / build-and-deploy (push) Successful in 4m10s
CD Pipeline / post-deploy-checks (push) Successful in 1m44s

This commit is contained in:
Your Name
2026-06-18 13:27:43 +08:00
parent 650b227a73
commit e0a32b3bd2
3 changed files with 100 additions and 5 deletions

View File

@@ -3168,6 +3168,11 @@ class WeeklyReportMessage:
disposition_manual: int = 0
disposition_cold_start: int = 0
disposition_total: int = 0
stats_source_ok: bool = True
k3s_source_ok: bool = True
git_source_ok: bool = True
cost_source_ok: bool = False
all_zero_actionable_anomaly: bool = False
def format(self) -> str:
"""格式化為 Telegram HTML"""
@@ -3175,6 +3180,29 @@ class WeeklyReportMessage:
alert_health = "" if self.resolved_rate >= 80 else "⚠️"
ai_health = "" if self.ai_success_rate >= 70 else "⚠️"
k3s_health = "" if self.k3s_uptime_pct >= 99 else "⚠️"
source_ok_count = sum([
self.stats_source_ok,
self.k3s_source_ok,
self.git_source_ok,
self.cost_source_ok,
])
all_zero = (
self.alert_total == 0
and self.ai_proposal_count == 0
and self.ai_executed_count == 0
and self.commits_count == 0
and self.deploy_count == 0
and self.ai_tokens_week == 0
and self.disposition_total == 0
)
actionable_all_zero = self.all_zero_actionable_anomaly or all_zero
report_trust = "低可信" if actionable_all_zero or source_ok_count < 4 else "可參考"
source_status = (
f"Stats={'ok' if self.stats_source_ok else 'fail'} / "
f"K3s={'ok' if self.k3s_source_ok else 'fail'} / "
f"Git={'ok' if self.git_source_ok else 'fail'} / "
f"Cost={'ok' if self.cost_source_ok else 'missing'}"
)
message = (
f"═══════════════════════════\n"
@@ -3182,6 +3210,11 @@ class WeeklyReportMessage:
f"═══════════════════════════\n"
f"📅 {html.escape(self.week_range)} | {html.escape(self.report_date)}\n"
f"━━━━━━━━━━━━━━━━━━━\n"
f"🧭 <b>報表資料信任度</b>\n"
f"├ 判定: <b>{report_trust}</b>\n"
f"├ 來源: <code>{html.escape(source_status)}</code>\n"
f"└ 全 0: <code>{'actionable_anomaly' if actionable_all_zero else 'no'}</code>\n"
f"━━━━━━━━━━━━━━━━━━━\n"
f"{alert_health} <b>告警統計</b>\n"
f"├ 總數: <code>{self.alert_total}</code>\n"
f"├ Critical: <code>{self.alert_critical}</code>\n"
@@ -3222,7 +3255,7 @@ class WeeklyReportMessage:
f"└ 自動化率: <b>{auto_rate}%</b>"
)
return message[:1200]
return message[:1800]
@dataclass