summaryrefslogtreecommitdiffstats
path: root/weather_mapper.go
diff options
context:
space:
mode:
Diffstat (limited to 'weather_mapper.go')
-rw-r--r--weather_mapper.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/weather_mapper.go b/weather_mapper.go
new file mode 100644
index 0000000..7f01217
--- /dev/null
+++ b/weather_mapper.go
@@ -0,0 +1,63 @@
+// weather_mapper.go - Maps FMI weather symbols to OWM format
+package main
+
+import "time"
+
+// WeatherMapper handles weather symbol mapping
+type WeatherMapper struct {
+ symbolMap map[int]Weather
+}
+
+// NewWeatherMapper creates a new weather mapper
+func NewWeatherMapper() *WeatherMapper {
+ return &WeatherMapper{
+ symbolMap: map[int]Weather{
+ 1: {800, "Clear", "clear sky", "01"},
+ 2: {801, "Clouds", "few clouds", "02"},
+ 3: {802, "Clouds", "scattered clouds", "03"},
+ 4: {803, "Clouds", "broken clouds", "04"},
+ 5: {804, "Clouds", "overcast clouds", "04"},
+ 6: {701, "Mist", "mist", "50"},
+ 7: {701, "Mist", "mist", "50"},
+ 8: {741, "Fog", "fog", "50"},
+ 9: {741, "Fog", "fog", "50"},
+ 10: {741, "Fog", "fog", "50"},
+ 11: {300, "Drizzle", "light intensity drizzle", "09"},
+ 12: {301, "Drizzle", "drizzle", "09"},
+ 13: {302, "Drizzle", "heavy intensity drizzle", "09"},
+ 21: {520, "Rain", "light intensity shower rain", "09"},
+ 22: {521, "Rain", "shower rain", "09"},
+ 23: {522, "Rain", "heavy intensity shower rain", "09"},
+ 24: {511, "Rain", "freezing rain", "13"},
+ 25: {500, "Rain", "light rain", "10"},
+ 26: {501, "Rain", "moderate rain", "10"},
+ 27: {502, "Rain", "heavy intensity rain", "10"},
+ 30: {500, "Rain", "light rain", "10"},
+ 31: {501, "Rain", "moderate rain", "10"},
+ 32: {502, "Rain", "heavy intensity rain", "10"},
+ 40: {600, "Snow", "light snow", "13"},
+ 41: {600, "Snow", "light snow", "13"},
+ 42: {601, "Snow", "snow", "13"},
+ 43: {602, "Snow", "heavy snow", "13"},
+ 91: {200, "Thunderstorm", "thunderstorm with light rain", "11"},
+ },
+ }
+}
+
+// Map converts FMI weather symbol to OWM weather with day/night icon
+func (wm *WeatherMapper) Map(symbol int, forecastTime, sunrise, sunset time.Time) Weather {
+ weather, ok := wm.symbolMap[symbol]
+ if !ok {
+ weather = Weather{800, "Clear", "clear sky", "01"}
+ }
+
+ // Determine day/night
+ isDay := forecastTime.After(sunrise) && forecastTime.Before(sunset)
+ if isDay {
+ weather.Icon += "d"
+ } else {
+ weather.Icon += "n"
+ }
+
+ return weather
+}