1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// weather_mapper.go - Fixed with exported map
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: FmiToOwm,
}
}
// 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
}
// FmiToOwm is the global FMI to OpenWeatherMap mapping
var FmiToOwm = 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"},
}
|