39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package briefing
|
|
|
|
import "gitea.maximumdirect.net/eric/weatherreporter/internal/module"
|
|
|
|
type OutdoorWindowsModule struct {
|
|
Best *OutdoorWindowModule `json:"best,omitempty"`
|
|
Worst *OutdoorWindowModule `json:"worst,omitempty"`
|
|
}
|
|
|
|
type OutdoorWindowModule struct {
|
|
Daypart string `json:"daypart"`
|
|
PeriodBegins string `json:"period_begins,omitempty"`
|
|
PeriodEnds string `json:"period_ends,omitempty"`
|
|
Reasons []string `json:"reasons,omitempty"`
|
|
Score float64 `json:"score"`
|
|
}
|
|
|
|
func buildOutdoorWindowsModule(ctx ModuleContext, _ any) (*module.Output, error) {
|
|
windows := buildOutdoorWindows(ctx.Derived.DaypartSummaries)
|
|
value := OutdoorWindowsModule{
|
|
Best: outdoorWindowValue(windows.Best, ctx.Timezone),
|
|
Worst: outdoorWindowValue(windows.Worst, ctx.Timezone),
|
|
}
|
|
return &module.Output{ID: module.OutdoorWindows, StanzaName: "outdoor_windows", Value: value}, nil
|
|
}
|
|
|
|
func outdoorWindowValue(window *OutdoorWindow, timezone string) *OutdoorWindowModule {
|
|
if window == nil {
|
|
return nil
|
|
}
|
|
return &OutdoorWindowModule{
|
|
Daypart: window.Daypart,
|
|
PeriodBegins: friendlyPeriodBeginsLabel(window.Period, timezone),
|
|
PeriodEnds: friendlyPeriodEndsLabel(window.Period, timezone),
|
|
Reasons: append([]string(nil), window.Reasons...),
|
|
Score: window.Score,
|
|
}
|
|
}
|