openweather: refactored the OpenWeather source files to relocate normalization logic to internal/normalizers.

This commit is contained in:
2026-01-14 11:59:17 -06:00
parent 0ba2602bcc
commit 759fa31762
5 changed files with 469 additions and 330 deletions

View File

@@ -0,0 +1,98 @@
// FILE: ./internal/normalizers/openweather/wmo_map.go
package openweather
import "gitea.maximumdirect.net/ejr/weatherfeeder/internal/model"
// mapOpenWeatherToWMO maps OpenWeather weather condition IDs into weatherfeeder's
// canonical WMO code vocabulary.
//
// This is an approximate semantic mapping between two different code systems.
// We map conservatively into the subset currently represented in standards.WMODescriptions.
func mapOpenWeatherToWMO(owmID int) model.WMOCode {
switch {
// 2xx Thunderstorm
case owmID >= 200 && owmID <= 232:
return 95
// 3xx Drizzle
case owmID >= 300 && owmID <= 321:
if owmID == 300 {
return 51
}
if owmID == 302 {
return 55
}
return 53
// 5xx Rain
case owmID >= 500 && owmID <= 531:
// 511 is "freezing rain"
if owmID == 511 {
return 67
}
// showers bucket (520-531)
if owmID >= 520 && owmID <= 531 {
if owmID == 520 {
return 80
}
if owmID == 522 {
return 82
}
return 81
}
// normal rain intensity
if owmID == 500 {
return 61
}
if owmID == 501 {
return 63
}
if owmID >= 502 && owmID <= 504 {
return 65
}
return 63
// 6xx Snow
case owmID >= 600 && owmID <= 622:
if owmID == 600 {
return 71
}
if owmID == 601 {
return 73
}
if owmID == 602 {
return 75
}
// Snow showers bucket (620-622)
if owmID == 620 {
return 85
}
if owmID == 621 || owmID == 622 {
return 86
}
return 73
// 7xx Atmosphere (mist/smoke/haze/dust/fog/etc.)
case owmID >= 701 && owmID <= 781:
return 45
// 800 Clear
case owmID == 800:
return 0
// 80x Clouds
case owmID == 801:
return 1
case owmID == 802:
return 2
case owmID == 803 || owmID == 804:
return 3
default:
return model.WMOUnknown
}
}