Updated precipitation timing language in the shared template

This commit is contained in:
2026-06-16 19:10:11 -05:00
parent d9ab1e47ec
commit f9d6d42b1b
8 changed files with 195 additions and 13 deletions

View File

@@ -81,6 +81,7 @@ type PrecipitationWindow struct {
End *time.Time `json:"end,omitempty"`
MaxPrecipitationProbability TimedValue `json:"maxPrecipitationProbability"`
ProbabilityThreshold float64 `json:"probabilityThreshold"`
TextDescriptions []string `json:"textDescriptions,omitempty"`
}
func BuildPrecipTiming(periods []weatherdata.ForecastPeriod) PrecipTiming {
@@ -114,6 +115,7 @@ func buildPrecipTimingWithThreshold(periods []weatherdata.ForecastPeriod, thresh
},
ProbabilityThreshold: threshold,
}
appendActiveTextDescription(active, forecastPeriod.TextDescription)
activeLastEnd = forecastPeriod.EndTime
if timing.FirstPrecipitation == nil {
timing.FirstPrecipitation = &TimedValue{
@@ -135,6 +137,8 @@ func buildPrecipTimingWithThreshold(periods []weatherdata.ForecastPeriod, thresh
if forecastPeriod.StartTime.After(activeLastEnd) {
closeActive()
startActive(forecastPeriod, probability)
} else {
appendActiveTextDescription(active, forecastPeriod.TextDescription)
}
if probability > active.MaxPrecipitationProbability.Value {
active.MaxPrecipitationProbability = TimedValue{
@@ -166,6 +170,17 @@ func buildPrecipTimingWithThreshold(periods []weatherdata.ForecastPeriod, thresh
return timing
}
func appendActiveTextDescription(window *PrecipitationWindow, text string) {
if window == nil {
return
}
text = strings.TrimSpace(text)
if text == "" {
return
}
window.TextDescriptions = append(window.TextDescriptions, text)
}
func BuildDailySummary(bundle *weatherdata.Bundle, date time.Time, location *time.Location, dayparts []DaypartDefinition) (*DailySummary, error) {
if bundle == nil {
return nil, fmt.Errorf("forecast bundle is required")