-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
239 lines (234 loc) · 9.36 KB
/
index.html
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Weather forecast accuracy in Bangalore</title>
<link rel="stylesheet" type="text/css" href="./index.css" />
</head>
<body>
<header>
Weather forecast accuracy in Bangalore
</header>
<div id="right_now">
<noscript>No javascript :(</noscript>
</div>
<div id="forecasts_header">
Forecasts for this moment:
</div>
<div id="forecast_3hr">
</div>
<div id="forecast_6hr">
</div>
<div id="forecast_12hr">
</div>
<div id="forecast_1day">
</div>
<div id="forecast_3day">
</div>
<div id="forecast_5day">
</div>
<div id="prediction_match">
Calculating...
</div>
<footer>
Made by perryizgr8.
<br />
<a href="https://github.com/perryizgr8/forecast-accuracy">Github</a>
</footer>
<script>
function Get(theUrl) {
var Httpreq = new XMLHttpRequest();
Httpreq.open("GET", theUrl, false);
Httpreq.send(null);
return Httpreq.responseText;
}
var url = "http://35.224.104.7/now.json"
var json_obj = JSON.parse(Get(url));
function weather_id_to_word(id) {
if ((id >= 200) && (id < 300)) {
return "thunderstormy";
} else if ((id >= 300) && (id < 400)) {
return "drizzling";
} else if ((id >= 500) && (id < 600)) {
return "raining";
} else if ((id >= 600) && (id < 700)) {
return "snowing";
} else if ((id >= 700) && (id < 800)) {
switch (id) {
case 701:
return "misty";
break;
case 711:
return "smoky";
break;
case 721:
return "hazy";
break;
case 731:
return "sandy";
break;
case 741:
return "foggy";
break;
case 751:
return "sandy";
break;
case 761:
return "dusty";
break;
case 762:
return "volcanic";
break;
case 771:
return "squally";
break;
case 781:
return "a tornado";
break;
default:
return "atmospheric";
break;
}
} else if ((id >= 800) && (id < 900)) {
switch (id) {
case 800:
return "clear";
break;
case 801:
return "slightly cloudy";
break;
case 804:
return "overcast";
break;
default:
return "cloudy";
break;
}
} else if ((id >= 900) && (id < 1000)) {
switch (id) {
case 900:
return "a tornado";
break;
case 901:
return "stormy";
break;
case 902:
return "a hurricane";
break;
case 903:
return "cold";
break;
case 904:
return "hot";
break;
case 905:
return "windy";
break;
case 906:
return "a halestorm";
break;
case 951:
return "calm";
break;
case 952:
case 953:
return "slightly breezy";
break;
case 954:
return "breezy";
break;
case 955:
case 956:
return "quite breezy";
break;
case 957:
case 958:
case 959:
return "a gale";
break;
case 960:
case 961:
return "stormy";
break;
case 962:
return "a hurricane";
break;
default:
return "somewhat unusual";
break;
}
} else {
return "unfathomably mysterious";
}
}
json_obj_inner = json_obj[json_obj.constructor.keys(json_obj)[0]]
var data_timestamp = json_obj.constructor.keys(json_obj)[0];
var now_timestamp = Math.floor((new Date()).getTime() / 1000);
if ((now_timestamp - data_timestamp) > 3 * 60 * 60) {
console.log("Warning! Data is more than 3 hours old : " + (now_timestamp - data_timestamp));
}
console.log(json_obj);
console.log("current id = " + json_obj_inner.current.id + " " + weather_id_to_word(json_obj_inner.current.id));
console.log("3 hours id = " + json_obj_inner.hr3.id + " " + weather_id_to_word(json_obj_inner.hr3.id));
console.log("6 hours id = " + json_obj_inner.hr6.id + " " + weather_id_to_word(json_obj_inner.hr6.id));
console.log("12 hours id = " + json_obj_inner.hr12.id + " " + weather_id_to_word(json_obj_inner.hr12.id));
console.log("1 day id = " + json_obj_inner.day1.id + " " + weather_id_to_word(json_obj_inner.day1.id));
console.log("3 days id = " + json_obj_inner.day3.id + " " + weather_id_to_word(json_obj_inner.day3.id));
console.log("5 days id = " + json_obj_inner.day5.id + " " + weather_id_to_word(json_obj_inner.day5.id));
var right_now_div = document.getElementById('right_now');
right_now_div.textContent = "Right now, it is " + weather_id_to_word(json_obj_inner.current.id) + ".";
var hr3_div = document.getElementById('forecast_3hr');
hr3_div.textContent = "...3 hours ago: " + weather_id_to_word(json_obj_inner.hr3.id) + ".";
var pred_matches = 0;
if (weather_id_to_word(json_obj_inner.hr3.id) == weather_id_to_word(json_obj_inner.current.id)) {
hr3_div.style.color = "green";
pred_matches = pred_matches + 1;
} else {
hr3_div.style.color = "red";
}
var hr6_div = document.getElementById('forecast_6hr');
hr6_div.textContent = "...6 hours ago: " + weather_id_to_word(json_obj_inner.hr6.id) + ".";
if (weather_id_to_word(json_obj_inner.hr6.id) == weather_id_to_word(json_obj_inner.current.id)) {
hr6_div.style.color = "green";
pred_matches = pred_matches + 1;
} else {
hr6_div.style.color = "red";
}
var hr12_div = document.getElementById('forecast_12hr');
hr12_div.textContent = "...12 hours ago: " + weather_id_to_word(json_obj_inner.hr12.id) + ".";
if (weather_id_to_word(json_obj_inner.hr12.id) == weather_id_to_word(json_obj_inner.current.id)) {
hr12_div.style.color = "green";
pred_matches = pred_matches + 1;
} else {
hr12_div.style.color = "red";
}
var day1_div = document.getElementById('forecast_1day');
day1_div.textContent = "...1 day ago: " + weather_id_to_word(json_obj_inner.day1.id) + ".";
if (weather_id_to_word(json_obj_inner.day1.id) == weather_id_to_word(json_obj_inner.current.id)) {
day1_div.style.color = "green";
pred_matches = pred_matches + 1;
} else {
day1_div.style.color = "red";
}
var day3_div = document.getElementById('forecast_3day');
day3_div.textContent = "...3 days ago: " + weather_id_to_word(json_obj_inner.day3.id) + ".";
if (weather_id_to_word(json_obj_inner.day3.id) == weather_id_to_word(json_obj_inner.current.id)) {
day3_div.style.color = "green";
pred_matches = pred_matches + 1;
} else {
day3_div.style.color = "red";
}
var day5_div = document.getElementById('forecast_5day');
day5_div.textContent = "...5 days ago: " + weather_id_to_word(json_obj_inner.day5.id) + ".";
if (weather_id_to_word(json_obj_inner.day5.id) == weather_id_to_word(json_obj_inner.current.id)) {
day5_div.style.color = "green";
pred_matches = pred_matches + 1;
} else {
day5_div.style.color = "red";
}
console.log(pred_matches + " out of 6 matches");
var pred_div = document.getElementById('prediction_match');
pred_div.textContent = Math.floor(pred_matches * 100 / 6) + "% accuracy";
</script>
</body>
</html>