78 lines
3.7 KiB
Go
78 lines
3.7 KiB
Go
package state
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/briefing"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/report"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/weatherdata"
|
|
)
|
|
|
|
const MetadataSchemaVersion = "weatherreporter.metadata.v1"
|
|
|
|
type Metadata struct {
|
|
SchemaVersion string `json:"schemaVersion"`
|
|
RunID string `json:"runId"`
|
|
MetadataPath string `json:"-"`
|
|
ReportID report.ID `json:"reportId"`
|
|
Variant string `json:"variant,omitempty"`
|
|
PromptID string `json:"promptId"`
|
|
GeneratedAt time.Time `json:"generatedAt"`
|
|
Timezone string `json:"timezone"`
|
|
ValidPeriod timeutil.Period `json:"validPeriod"`
|
|
Location *briefing.LocationContext `json:"location,omitempty"`
|
|
SourceLocationID string `json:"sourceLocationId,omitempty"`
|
|
SourceLocation string `json:"sourceLocation,omitempty"`
|
|
Sources []briefing.SourceMetadata `json:"sources,omitempty"`
|
|
SourceWarnings []weatherdata.SourceWarning `json:"sourceWarnings,omitempty"`
|
|
ModuleSnapshotPath string `json:"moduleSnapshotPath"`
|
|
DataPackagePath string `json:"dataPackagePath"`
|
|
PreflightPath string `json:"preflightPath"`
|
|
NotificationPath string `json:"notificationPath,omitempty"`
|
|
RenderedReportPath string `json:"renderedReportPath,omitempty"`
|
|
GeneratedTextSchemaID string `json:"generatedTextSchemaId,omitempty"`
|
|
GeneratedTextRawPath string `json:"generatedTextRawPath,omitempty"`
|
|
GeneratedTextResultPath string `json:"generatedTextResultPath,omitempty"`
|
|
GeneratedTextPath string `json:"generatedTextPath,omitempty"`
|
|
RenderContextPath string `json:"renderContextPath,omitempty"`
|
|
}
|
|
|
|
func BuildMetadataFromBriefingMetadata(resolved report.Resolved, briefingMetadata briefing.Metadata, paths ArtifactPaths) Metadata {
|
|
metadata := resolved.Metadata()
|
|
out := Metadata{
|
|
SchemaVersion: MetadataSchemaVersion,
|
|
RunID: metadata.RunID,
|
|
MetadataPath: paths.Metadata,
|
|
ReportID: metadata.ReportID,
|
|
Variant: briefingMetadata.Variant,
|
|
PromptID: metadata.PromptID,
|
|
GeneratedAt: metadata.GeneratedAt,
|
|
Timezone: metadata.Timezone,
|
|
ValidPeriod: metadata.ValidPeriod,
|
|
Location: copyLocation(briefingMetadata.Location),
|
|
SourceLocationID: briefingMetadata.SourceLocationID,
|
|
SourceLocation: briefingMetadata.SourceLocation,
|
|
Sources: briefingMetadata.Sources,
|
|
SourceWarnings: briefingMetadata.SourceWarnings,
|
|
ModuleSnapshotPath: paths.ModuleSnapshot,
|
|
DataPackagePath: paths.DataPackage,
|
|
PreflightPath: paths.Preflight,
|
|
RenderedReportPath: paths.RenderedReport,
|
|
}
|
|
out.GeneratedTextSchemaID = resolved.Definition.GeneratedTextSchemaID
|
|
out.GeneratedTextRawPath = paths.GeneratedTextRaw
|
|
out.GeneratedTextResultPath = paths.GeneratedTextResult
|
|
out.GeneratedTextPath = paths.GeneratedText
|
|
out.RenderContextPath = paths.RenderContext
|
|
return out
|
|
}
|
|
|
|
func copyLocation(location *briefing.LocationContext) *briefing.LocationContext {
|
|
if location == nil {
|
|
return nil
|
|
}
|
|
copied := *location
|
|
return &copied
|
|
}
|