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:
23
internal/normalizers/common/id.go
Normal file
23
internal/normalizers/common/id.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// FILE: internal/normalizers/common/id.go
|
||||
package common
|
||||
|
||||
import "fmt"
|
||||
|
||||
// SynthStationID formats a stable synthetic station identifier for providers that are
|
||||
// coordinate-based rather than station-based.
|
||||
//
|
||||
// Example output:
|
||||
//
|
||||
// OPENMETEO(38.62700,-90.19940)
|
||||
func SynthStationID(prefix string, lat, lon float64) string {
|
||||
return fmt.Sprintf("%s(%.5f,%.5f)", prefix, lat, lon)
|
||||
}
|
||||
|
||||
// SynthStationIDPtr is the pointer-friendly variant.
|
||||
// If either coordinate is missing, it returns "" (unknown).
|
||||
func SynthStationIDPtr(prefix string, lat, lon *float64) string {
|
||||
if lat == nil || lon == nil {
|
||||
return ""
|
||||
}
|
||||
return SynthStationID(prefix, *lat, *lon)
|
||||
}
|
||||
@@ -56,14 +56,11 @@ func roundValue(v reflect.Value, decimals int) reflect.Value {
|
||||
out.Set(elem)
|
||||
return out
|
||||
}
|
||||
if elem.IsValid() && elem.Type().AssignableTo(v.Type()) {
|
||||
out.Set(elem)
|
||||
return out
|
||||
}
|
||||
if elem.IsValid() && elem.Type().ConvertibleTo(v.Type()) {
|
||||
out.Set(elem.Convert(v.Type()))
|
||||
return out
|
||||
}
|
||||
|
||||
// If we can't sensibly re-wrap, just keep the original.
|
||||
return v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user