refactor(normalizers): deduplicate synthetic station ID generation
- Add common SynthStationID helpers for coordinate-based providers - Use shared helper for Open-Meteo and OpenWeather station ID synthesis - Require both lat/lon when generating synthetic IDs to avoid misleading defaults - Remove unused Open-Meteo normalizer wrapper code This reduces cross-provider duplication while keeping provider-specific mapping logic explicit and readable.
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
// FILE: ./internal/normalizers/openmeteo/common.go
|
||||
package openmeteo
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
openmeteo "gitea.maximumdirect.net/ejr/weatherfeeder/internal/providers/openmeteo"
|
||||
)
|
||||
|
||||
// parseOpenMeteoTime parses Open-Meteo timestamps.
|
||||
//
|
||||
// The actual parsing logic lives in internal/providers/openmeteo so both the
|
||||
// source (envelope EffectiveAt / event ID) and normalizer (canonical payload)
|
||||
// can share identical timestamp behavior.
|
||||
//
|
||||
// We keep this thin wrapper to avoid churn in the normalizer package.
|
||||
func parseOpenMeteoTime(s string, tz string, utcOffsetSeconds int) (time.Time, error) {
|
||||
return openmeteo.ParseTime(s, tz, utcOffsetSeconds)
|
||||
}
|
||||
@@ -78,18 +78,8 @@ func buildObservation(parsed omResponse) (model.WeatherObservation, time.Time, e
|
||||
canonicalText := standards.WMOText(wmo, isDay)
|
||||
|
||||
// Station identity: Open-Meteo is not a station feed; synthesize from coordinates.
|
||||
stationID := ""
|
||||
if parsed.Latitude != nil || parsed.Longitude != nil {
|
||||
lat := 0.0
|
||||
lon := 0.0
|
||||
if parsed.Latitude != nil {
|
||||
lat = *parsed.Latitude
|
||||
}
|
||||
if parsed.Longitude != nil {
|
||||
lon = *parsed.Longitude
|
||||
}
|
||||
stationID = fmt.Sprintf("OPENMETEO(%.5f,%.5f)", lat, lon)
|
||||
}
|
||||
// Require BOTH lat/lon to avoid misleading OPENMETEO(0.00000,...) IDs.
|
||||
stationID := normcommon.SynthStationIDPtr("OPENMETEO", parsed.Latitude, parsed.Longitude)
|
||||
|
||||
obs := model.WeatherObservation{
|
||||
StationID: stationID,
|
||||
|
||||
Reference in New Issue
Block a user