feat: 完善环境规则、会诊治理、知识审核与效果评估

This commit is contained in:
weijuesen
2026-08-14 10:33:17 +08:00
parent 69ef5a0704
commit 126c215a6b
27 changed files with 963 additions and 88 deletions
@@ -1,17 +1,20 @@
package service
import "testing"
import (
"testing"
"time"
)
func TestComputeHealthScore(t *testing.T) {
if s, g := ComputeHealthScore(HealthInput{}); s != 100 || g != "优" {
t.Errorf("空输入应 100/优,实际 %.1f/%s", s, g)
}
bad := HealthInput{
RecentRiskLevels: []string{"red", "red"},
LampPositive: 1,
LampTotal: 2,
RecentRiskLevels: []string{"red", "red"},
LampPositive: 1,
LampTotal: 2,
ConsultationCount: 1,
TraceCount: 1,
TraceCount: 1,
}
s, g := ComputeHealthScore(bad)
if s >= 80 {
@@ -50,3 +53,33 @@ func TestAggregateMonthlyStats(t *testing.T) {
t.Error("空输入应返回空")
}
}
func TestEvaluateControlEffectComparesWindows(t *testing.T) {
window := EffectWindow{
BeforeStart: time.Date(2026, 8, 1, 0, 0, 0, 0, time.UTC),
BeforeEnd: time.Date(2026, 8, 7, 0, 0, 0, 0, time.UTC),
AfterStart: time.Date(2026, 8, 8, 0, 0, 0, 0, time.UTC),
AfterEnd: time.Date(2026, 8, 14, 0, 0, 0, 0, time.UTC),
}
report := EvaluateControlEffect("event-1", window, EffectMetrics{
RiskSamples: []float64{80}, LampPositive: 2, LampTotal: 3,
}, EffectMetrics{
RiskSamples: []float64{40}, LampPositive: 1, LampTotal: 4,
})
if report.Conclusion != "改善" {
t.Fatalf("结论 = %s, want 改善", report.Conclusion)
}
if report.BeforeRiskAvg == nil || *report.BeforeRiskAvg != 80 {
t.Fatalf("before risk = %+v", report.BeforeRiskAvg)
}
}
func TestEvaluateControlEffectReportsMissing(t *testing.T) {
report := EvaluateControlEffect("event-1", EffectWindow{}, EffectMetrics{}, EffectMetrics{})
if report.Conclusion != "证据不足,无法判断效果" {
t.Fatalf("无数据结论应为证据不足,实际 %s", report.Conclusion)
}
if len(report.Missing) < 4 {
t.Fatalf("缺失维度应单独列出: %v", report.Missing)
}
}