70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package report
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/module"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
|
)
|
|
|
|
func stormDefinition() Definition {
|
|
return Definition{
|
|
ID: Storm,
|
|
Name: "Storm Report",
|
|
PromptID: "weather.storm_report",
|
|
ComparisonStrategy: CompareExplicitWindow,
|
|
ArtifactGroup: "storm",
|
|
BatchOutputName: "storm.md",
|
|
Generated: true,
|
|
CompatiblePriorIDs: []ID{Storm},
|
|
Modules: stormModules(),
|
|
resolve: resolveStorm,
|
|
}
|
|
}
|
|
|
|
func stormModules() []module.ConfigItem {
|
|
return moduleItems(
|
|
module.Metadata,
|
|
module.CurrentConditions,
|
|
module.PrecipTiming,
|
|
module.AlertDigest,
|
|
module.SPCConvectiveOutlooks,
|
|
module.AreaForecastDiscussion,
|
|
module.SPCConvectiveDiscussion,
|
|
module.WeatherStory,
|
|
)
|
|
}
|
|
|
|
func ParseStormPeriod(start string, end string, location *time.Location) (timeutil.Period, error) {
|
|
if location == nil {
|
|
location = time.UTC
|
|
}
|
|
startTime, err := timeutil.ParseStormTime(start, location)
|
|
if err != nil {
|
|
return timeutil.Period{}, err
|
|
}
|
|
endTime, err := timeutil.ParseStormTime(end, location)
|
|
if err != nil {
|
|
return timeutil.Period{}, err
|
|
}
|
|
period := timeutil.Period{Start: startTime, End: endTime}
|
|
if !period.IsValid() {
|
|
return timeutil.Period{}, fmt.Errorf("storm report requires end time after start time")
|
|
}
|
|
return period, nil
|
|
}
|
|
|
|
func resolveStorm(req ResolveRequest) (timeutil.Period, error) {
|
|
if req.StormStart.IsZero() {
|
|
return timeutil.Period{}, fmt.Errorf("storm report requires a start time")
|
|
}
|
|
if req.StormEnd.IsZero() {
|
|
return timeutil.Period{}, fmt.Errorf("storm report requires an end time")
|
|
}
|
|
if !req.StormEnd.After(req.StormStart) {
|
|
return timeutil.Period{}, fmt.Errorf("storm report requires end time after start time")
|
|
}
|
|
return timeutil.Period{Start: req.StormStart, End: req.StormEnd}, nil
|
|
}
|