62 lines
2.3 KiB
Go
62 lines
2.3 KiB
Go
package briefing
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/module"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/report"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/weatherdata"
|
|
)
|
|
|
|
type MetadataModule struct {
|
|
RunID string `json:"run_id"`
|
|
ReportID report.ID `json:"report_id"`
|
|
Variant string `json:"variant,omitempty"`
|
|
PromptID string `json:"prompt_id"`
|
|
GeneratedAt time.Time `json:"generated_at"`
|
|
Units string `json:"units"`
|
|
Timezone string `json:"timezone"`
|
|
ValidPeriod timeutil.Period `json:"valid_period"`
|
|
Location *LocationContext `json:"location,omitempty"`
|
|
SourceWarnings []SourceWarningSummary `json:"source_warnings,omitempty"`
|
|
}
|
|
|
|
type SourceWarningSummary struct {
|
|
Source string `json:"source"`
|
|
Code string `json:"code"`
|
|
Severity string `json:"severity"`
|
|
Message string `json:"message"`
|
|
CompletenessImpact string `json:"completeness_impact,omitempty"`
|
|
}
|
|
|
|
func buildMetadataModule(ctx ModuleContext, _ any) (*module.Output, error) {
|
|
value := MetadataModule{
|
|
RunID: ctx.Identity.RunID,
|
|
ReportID: ctx.Identity.ReportID,
|
|
Variant: ctx.Identity.Variant,
|
|
PromptID: ctx.Identity.PromptID,
|
|
GeneratedAt: ctx.Identity.GeneratedAt,
|
|
Units: ctx.Identity.Units,
|
|
Timezone: ctx.Identity.Timezone,
|
|
ValidPeriod: ctx.Identity.ValidPeriod,
|
|
Location: copyLocation(ctx.Identity.Location),
|
|
SourceWarnings: sourceWarningSummaries(ctx.Identity.SourceWarnings),
|
|
}
|
|
return &module.Output{ID: module.Metadata, StanzaName: "metadata", Value: value}, nil
|
|
}
|
|
|
|
func sourceWarningSummaries(warnings []weatherdata.SourceWarning) []SourceWarningSummary {
|
|
out := make([]SourceWarningSummary, 0, len(warnings))
|
|
for _, warning := range warnings {
|
|
out = append(out, SourceWarningSummary{
|
|
Source: warning.Source,
|
|
Code: warning.Code,
|
|
Severity: warning.Severity,
|
|
Message: warning.Message,
|
|
CompletenessImpact: warning.CompletenessImpact,
|
|
})
|
|
}
|
|
return out
|
|
}
|