2026-01-15 10:36:18 -06:00
|
|
|
// FILE: ./internal/normalizers/common/finalize.go
|
|
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/ejr/feedkit/event"
|
2026-03-28 11:30:20 -05:00
|
|
|
fknormalize "gitea.maximumdirect.net/ejr/feedkit/processors/normalize"
|
2026-01-15 10:36:18 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Finalize builds the output event envelope by copying the input and applying the
|
2026-06-10 20:28:41 +00:00
|
|
|
// canonical schema/payload, plus an optional effective time.
|
2026-01-15 10:36:18 -06:00
|
|
|
//
|
|
|
|
|
// Important behavior:
|
|
|
|
|
// - ID/Kind/Source/EmittedAt are preserved by copying the input event.
|
2026-06-10 20:28:41 +00:00
|
|
|
// - EffectiveAt is only overwritten when the supplied effective time is non-zero.
|
|
|
|
|
// If the supplied time is zero, any existing in.EffectiveAt is preserved.
|
feat(nws, normalizers): add NWS hourly forecast normalization and enforce canonical float rounding
- Implement full NWS hourly forecast normalizer (raw.nws.hourly.forecast.v1 → weather.forecast.v1)
- Add GeoJSON forecast types and helpers for NWS gridpoint hourly payloads
- Normalize temperatures, winds, humidity, PoP, and infer WMO condition codes from forecast text/icons
- Treat forecast IssuedAt as EffectiveAt for stable, dedupe-friendly event IDs
- Introduce project-wide float rounding at normalization finalization
- Round all float values in canonical payloads to 2 decimal places
- Apply consistently across pointers, slices, maps, and nested structs
- Preserve opaque structs (e.g., time.Time) unchanged
- Add SchemaRawNWSHourlyForecastV1 and align schema matching/comments
- Clean up NWS helper organization and comments
- Update documentation to reflect numeric wire-format and normalization policies
This establishes a complete, deterministic hourly forecast pipeline for NWS
and improves JSON output stability across all canonical weather schemas.
2026-01-16 10:28:32 -06:00
|
|
|
// - Payload floats are rounded to a stable wire-friendly precision (see round.go).
|
2026-01-15 10:36:18 -06:00
|
|
|
func Finalize(in event.Event, outSchema string, outPayload any, effectiveAt time.Time) (*event.Event, error) {
|
2026-03-28 11:30:20 -05:00
|
|
|
// Enforce stable numeric presentation for weather payloads before delegating to feedkit's
|
|
|
|
|
// generic envelope finalizer.
|
|
|
|
|
return fknormalize.FinalizeEvent(in, outSchema, RoundFloats(outPayload, DefaultFloatPrecision), effectiveAt)
|
2026-01-15 10:36:18 -06:00
|
|
|
}
|