31 lines
1.3 KiB
Go
31 lines
1.3 KiB
Go
package briefing
|
|
|
|
import (
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/forecast"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/module"
|
|
)
|
|
|
|
type PrecipTimingModule struct {
|
|
MaxPopPercent *int `json:"max_pop_percent,omitempty"`
|
|
MaxPopTime string `json:"max_pop_time,omitempty"`
|
|
FirstPrecipHour string `json:"first_precip_hour,omitempty"`
|
|
LastPrecipHour string `json:"last_precip_hour,omitempty"`
|
|
ThunderMentioned bool `json:"thunder_mentioned"`
|
|
}
|
|
|
|
func buildPrecipTimingModule(ctx ModuleContext, _ any) (*module.Output, error) {
|
|
value := precipTimingValue(ctx.Derived.PrecipTiming, ctx.Timezone)
|
|
return &module.Output{ID: module.PrecipTiming, StanzaName: "precip_timing", Value: value}, nil
|
|
}
|
|
|
|
func precipTimingValue(timing forecast.PrecipTiming, timezone string) PrecipTimingModule {
|
|
value := PrecipTimingModule{ThunderMentioned: timing.ThunderMentioned}
|
|
if timing.MaxPrecipitationProbability != nil {
|
|
value.MaxPopPercent = roundedInt(&timing.MaxPrecipitationProbability.Value)
|
|
value.MaxPopTime = clockLabel(timing.MaxPrecipitationProbability.Time, timezone)
|
|
}
|
|
value.FirstPrecipHour = timedClockLabel(timing.FirstPrecipitation, timezone)
|
|
value.LastPrecipHour = timedClockLabel(timing.LastPrecipitation, timezone)
|
|
return value
|
|
}
|