feat(server-go): 和风天气接入与高发病天气预警规则(#12)
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"silk-server-go/internal/model"
|
||||
)
|
||||
|
||||
// WeatherTextRainy 天气现象是否降雨/雷/雪
|
||||
func WeatherTextRainy(text string) bool {
|
||||
return strings.Contains(text, "雨") || strings.Contains(text, "雷") || strings.Contains(text, "雪")
|
||||
}
|
||||
|
||||
// RainDays 预报中降雨天数
|
||||
func RainDays(daily []DailyForecast) int {
|
||||
n := 0
|
||||
for _, d := range daily {
|
||||
if WeatherTextRainy(d.TextDay) || WeatherTextRainy(d.TextNight) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// FungalRisk 白僵病:湿度 ≥80% 且(连续阴雨 ≥2 天 或 当前降雨)
|
||||
func FungalRisk(now WeatherNow, daily []DailyForecast) (string, string) {
|
||||
if now.Humidity >= 80 && (RainDays(daily) >= 2 || WeatherTextRainy(now.Text)) {
|
||||
return "orange", fmt.Sprintf("实时湿度 %.0f%% 且未来 %d 天有降雨(连续阴雨),符合白僵病高发条件(湿度大于80)", now.Humidity, RainDays(daily))
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// TempSwingRisk 核型多角体病:温度突变(>30℃ 或 <20℃)
|
||||
func TempSwingRisk(temp float64) (string, string) {
|
||||
if temp > 30 || temp < 20 {
|
||||
return "yellow", fmt.Sprintf("实时温度 %.0f℃ 波动剧烈(>30℃ 或 <20℃),易诱发核型多角体病潜伏感染转急性", temp)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// SofteningRisk 软化病:湿度 >75%(结合密度/通风可升级)
|
||||
func SofteningRisk(now WeatherNow) (string, string) {
|
||||
if now.Humidity >= 75 {
|
||||
return "yellow", fmt.Sprintf("实时湿度 %.0f%%(大于75),若蚕头密度过大、通风不良易发软化病", now.Humidity)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// EvaluateWeatherRules 综合天气规则 → 预警列表(规则取自规格书 3.2.3)
|
||||
func EvaluateWeatherRules(now WeatherNow, daily []DailyForecast, stage string) []model.WeatherAlert {
|
||||
var alerts []model.WeatherAlert
|
||||
|
||||
if level, reason := FungalRisk(now, daily); level != "" {
|
||||
alerts = append(alerts, model.WeatherAlert{Disease: "白僵病", Level: level, Reason: reason})
|
||||
}
|
||||
if level, reason := TempSwingRisk(now.Temp); level != "" {
|
||||
if stage == "late5" {
|
||||
level = "orange"
|
||||
reason += ";当前为 5 龄后期,风险升级"
|
||||
}
|
||||
alerts = append(alerts, model.WeatherAlert{Disease: "核型多角体病", Level: level, Reason: reason})
|
||||
}
|
||||
if level, reason := SofteningRisk(now); level != "" {
|
||||
alerts = append(alerts, model.WeatherAlert{Disease: "软化病", Level: level, Reason: reason})
|
||||
}
|
||||
return alerts
|
||||
}
|
||||
Reference in New Issue
Block a user