Add convective outlook presentation
This commit is contained in:
@@ -3,14 +3,64 @@
|
||||
package presenter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/ejr/weatherfeeder/model"
|
||||
)
|
||||
|
||||
func OutlookRunPayload(run *model.WeatherOutlookRun, _ Units, _ *time.Location) any {
|
||||
func OutlookRunPayload(run *model.WeatherOutlookRun, _ Units, tz *time.Location) any {
|
||||
if run == nil {
|
||||
return nil
|
||||
}
|
||||
return run
|
||||
|
||||
out := model.WeatherOutlookRun{
|
||||
LocationID: run.LocationID,
|
||||
LocationName: run.LocationName,
|
||||
Latitude: copyFloat64Ptr(run.Latitude),
|
||||
Longitude: copyFloat64Ptr(run.Longitude),
|
||||
AsOf: inLocationTime(run.AsOf, tz),
|
||||
IssuedAt: inLocationTimePtr(run.IssuedAt, tz),
|
||||
Outlooks: make([]model.WeatherOutlook, 0, len(run.Outlooks)),
|
||||
}
|
||||
for _, outlook := range run.Outlooks {
|
||||
out.Outlooks = append(out.Outlooks, copyOutlook(outlook, tz))
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
func copyOutlook(outlook model.WeatherOutlook, tz *time.Location) model.WeatherOutlook {
|
||||
out := model.WeatherOutlook{
|
||||
ID: outlook.ID,
|
||||
Provider: outlook.Provider,
|
||||
Product: outlook.Product,
|
||||
Day: outlook.Day,
|
||||
OutlookType: outlook.OutlookType,
|
||||
Label: outlook.Label,
|
||||
LabelText: outlook.LabelText,
|
||||
SeverityRank: copyIntPtr(outlook.SeverityRank),
|
||||
ValidFrom: inLocationTime(outlook.ValidFrom, tz),
|
||||
ValidTo: inLocationTime(outlook.ValidTo, tz),
|
||||
IssuedAt: inLocationTime(outlook.IssuedAt, tz),
|
||||
ExpiresAt: inLocationTime(outlook.ExpiresAt, tz),
|
||||
Forecaster: outlook.Forecaster,
|
||||
Headline: outlook.Headline,
|
||||
Summary: outlook.Summary,
|
||||
Discussion: outlook.Discussion,
|
||||
SourceURL: outlook.SourceURL,
|
||||
ImageURL: outlook.ImageURL,
|
||||
ContainsLocation: outlook.ContainsLocation,
|
||||
}
|
||||
if outlook.Geometry != nil {
|
||||
out.Geometry = json.RawMessage(append([]byte(nil), outlook.Geometry...))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func copyIntPtr(v *int) *int {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
out := *v
|
||||
return &out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user