-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherCodes.js
225 lines (217 loc) · 8.08 KB
/
weatherCodes.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
export function getWeatherImage(code) {
const weatherImages = {
"0": "https://openweathermap.org/img/wn/[email protected]",
"1": "https://openweathermap.org/img/wn/[email protected]",
"2": "https://openweathermap.org/img/wn/[email protected]",
"3": "https://openweathermap.org/img/wn/[email protected]",
"45": "https://openweathermap.org/img/wn/[email protected]",
"48": "https://openweathermap.org/img/wn/[email protected]",
"51": "https://openweathermap.org/img/wn/[email protected]",
"53": "https://openweathermap.org/img/wn/[email protected]",
"55": "https://openweathermap.org/img/wn/[email protected]",
"56": "https://openweathermap.org/img/wn/[email protected]",
"57": "https://openweathermap.org/img/wn/[email protected]",
"61": "https://openweathermap.org/img/wn/[email protected]",
"63": "https://openweathermap.org/img/wn/[email protected]",
"65": "https://openweathermap.org/img/wn/[email protected]",
"66": "https://openweathermap.org/img/wn/[email protected]",
"67": "https://openweathermap.org/img/wn/[email protected]",
"71": "https://openweathermap.org/img/wn/[email protected]",
"73": "https://openweathermap.org/img/wn/[email protected]",
"75": "https://openweathermap.org/img/wn/[email protected]",
"77": "https://openweathermap.org/img/wn/[email protected]",
"80": "https://openweathermap.org/img/wn/[email protected]",
"81": "https://openweathermap.org/img/wn/[email protected]",
"82": "https://openweathermap.org/img/wn/[email protected]",
"85": "https://openweathermap.org/img/wn/[email protected]",
"86": "https://openweathermap.org/img/wn/[email protected]",
"95": "https://openweathermap.org/img/wn/[email protected]",
"96": "https://openweathermap.org/img/wn/[email protected]",
"99": "https://openweathermap.org/img/wn/[email protected]"
};
return weatherImages[code] || "Unknown weather code";
}
export function getWeatherDescription(code) {
const weatherDescriptions = {
0: "Clear sky",
1: "Mainly clear",
2: "Partly cloudy",
3: "Overcast",
45: "Fog",
48: "Depositing rime fog",
51: "Light drizzle",
53: "Moderate drizzle",
55: "Dense drizzle",
56: "Light freezing drizzle",
57: "Dense freezing drizzle",
61: "Slight rain",
63: "Moderate rain",
65: "Heavy rain",
66: "Light freezing rain",
67: "Heavy freezing rain",
71: "Slight snowfall",
73: "Moderate snowfall",
75: "Heavy snowfall",
77: "Snow grains",
80: "Slight rain showers",
81: "Moderate rain showers",
82: "Violent rain showers",
85: "Slight snow showers",
86: "Heavy snow showers",
95: "Slight thunderstorm",
96: "Thunderstorm with slight hail",
99: "Thunderstorm with heavy hail"
};
return weatherDescriptions[code] || "Unknown weather code";
}
export function createWeatherTemplate(filter, data, isDaily = true) {
const container = document.createElement('div');
let text;
if (isDaily) {
switch (filter) {
case "weather_code":
text = `Weather Description: ${data || 'N/A'}`;
break;
case "temperature_2m_max":
text = `Max Temperature: ${data || 'N/A'}`;
break;
case "temperature_2m_min":
text = `Min Temperature: ${data || 'N/A'}°C`;
break;
case "apparent_temperature_max":
text = `Max Apparent Temperature: ${data || 'N/A'}°C`;
break;
case "apparent_temperature_min":
text = `Min Apparent Temperature: ${data || 'N/A'}°C`;
break;
case "sunrise":
text = `Sunrise: ${data || 'N/A'}`;
break;
case "sunset":
text = `Sunset: ${data || 'N/A'}`;
break;
case "daylight_duration":
text = `Daylight Duration: ${data || 'N/A'} hours`;
break;
case "uv_index_max":
text = `UV Index: ${data || 'N/A'}`;
break;
case "uv_index_clear_sky_max":
text = `UV Index Clear Sky: ${data || 'N/A'}`;
break;
case "precipitation_sum":
text = `Precipitation Sum: ${data || 'N/A'} mm`;
break;
case "rain_sum":
text = `Rain Sum: ${data || 'N/A'} mm`;
break;
case "showers_sum":
text = `Showers Sum: ${data || 'N/A'} mm`;
break;
case "snowfall_sum":
text = `Snowfall Sum: ${data || 'N/A'} mm`;
break;
case "precipitation_hours":
text = `Precipitation Hours: ${data || 'N/A'} hours`;
break;
case "precipitation_probability_max":
text = `Precipitation Probability Max: ${data || 'N/A'}%`;
break;
case "wind_speed_10m_max":
text = `Maximum Wind Speed: ${data || 'N/A'} km/h`;
break;
case "wind_gusts_10m_max":
text = `Maximum Wind Gusts: ${data || 'N/A'} km/h`;
break;
case "wind_direction_10m_dominant":
text = `Dominant Wind Direction: ${data || 'N/A'}`;
break;
default:
text = `${weatherParameterNames[filter] || 'Unknown'}: ${data || 'N/A'}`;
break;
}
} else {
switch (filter) {
case "temperature_2m":
text = `Temperature: ${data || 'N/A'}°C`;
break;
case "relative_humidity_2m":
text = `Relative Humidity: ${data || 'N/A'}%`;
break;
case "apparent_temperature":
text = `Apparent Temperature: ${data || 'N/A'}°C`;
break;
case "is_day":
text = `Is Day or Night: ${data ? 'Day' : 'Night'}`;
break;
case "precipitation":
text = `Precipitation: ${data || 'N/A'} mm`;
break;
case "rain":
text = `Rain: ${data || 'N/A'} mm`;
break;
case "showers":
text = `Showers: ${data || 'N/A'} mm`;
break;
case "snowfall":
text = `Snowfall: ${data || 'N/A'} mm`;
break;
case "weather_code":
text = `Weather Description: ${data || 'N/A'}`;
break;
case "cloud_cover":
text = `Cloud Cover Total: ${data || 'N/A'}%`;
break;
case "wind_speed_10m":
text = `Wind Speed: ${data || 'N/A'} km/h`;
break;
case "wind_direction_10m":
text = `Wind Direction: ${data || 'N/A'}`;
break;
case "wind_gusts_10m":
text = `Wind Gusts: ${data || 'N/A'} km/h`;
break;
default:
text = `${weatherParameterNames[filter] || 'Unknown'}: ${data || 'N/A'}`;
break;
}
}
container.innerText = text;
return container;
}
export const weatherParameterNames = {
// Daily Weather Predictions
"weather_code": "Weather Description",
"temperature_2m_max": "Max Temperature",
"temperature_2m_min": "Min Temperature",
"apparent_temperature_max": "Max Apparent Temp.",
"apparent_temperature_min": "Min Apparent Temp.",
"sunrise": "Sunrise",
"sunset": "Sunset",
"daylight_duration": "Daylight Duration",
"uv_index_max": "UV Index",
"uv_index_clear_sky_max": "UV Index Clear Sky",
"precipitation_sum": "Precipitation Sum",
"rain_sum": "Rain Sum",
"showers_sum": "Showers Sum",
"snowfall_sum": "Snowfall Sum",
"precipitation_hours": "Precipitation Hours",
"precipitation_probability_max": "Precipitation Prob Max",
"wind_speed_10m_max": "Maximum Wind Speed",
"wind_gusts_10m_max": "Maximum Wind Gusts",
"wind_direction_10m_dominant": "Dominant Wind Direction",
// Current Weather
"temperature_2m": "Temperature",
"relative_humidity_2m": "Relative Humidity",
"apparent_temperature": "Apparent Temperature",
"is_day": "Is Day or Night",
"precipitation": "Precipitation",
"rain": "Rain",
"showers": "Showers",
"snowfall": "Snowfall",
"weather_code": "Weather Description",
"cloud_cover": "Cloud Cover Total",
"wind_speed_10m": "Wind Speed",
"wind_direction_10m": "Wind Direction",
"wind_gusts_10m": "Wind Gusts"
};