-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.js
50 lines (47 loc) · 1.44 KB
/
weather.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
/*
* Returns a list of times it is not raining in the next 36 hours.
*
* Limitation: Only works in Boston, MA right now.
*
*/
function nonRainingWindows(parsed_json)
{
/* information for the next 36 hours */
console.log("in nonRainingWindows");
var hourly_forecast = parsed_json['hourly_forecast'];
var times = new Array();
var possible_time = {
"hour":[],
"duration":[]
};
var end_of_window = true;
var duration = 0;
var inchesRain;
var time;
/* makes list of windows */
for(var i = 0; i < hourly_forecast.length; i++) {
time = parseFloat(hourly_forecast[i]['FCTTIME']['hour']);
inchesRain = parseFloat(hourly_forecast[i]['qpf'].english);
duration++;
if(end_of_window == true && inchesRain == 0) {
end_of_window = false; /* beginning of new window */
possible_time.hour = time;
}
if(end_of_window == false && inchesRain > 0) { /* end of a window */
end_of_window = true;
possible_time.duration = duration;
times.push(possible_time);
/* re-initilizes variables */
duration = 0;
possible_time = {
"hour":[],
"duration":[]
};
}
}
if(duration > 0 && inchesRain == 0) {
possible_time.duration = duration;
times.push(possible_time);
}
return times;
}