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
|
#include <vdr/plugin.h>
#include <string>
#include <sstream>
#include <jansson.h>
#include "../tools/jsonhelpers.h"
#include "forecast.h"
using namespace std;
cForecast::cForecast(void) {
type = ftUnknownForecast;
forecastTime = 0;
summary = "";
icon = "";
sunriseTime = 0;
sunsetTime = 0;
moonPhase = 0.0;
precipIntensity = 0.0;
precipProbability = 0.0;
percipType = "";
temperature = 0.0;
apparentTemperature = 0.0;
temperatureMin = 0.0;
temperatureMinTime = 0;
temperatureMax = 0.0;
temperatureMaxTime = 0;
humidity = 0.0;
windSpeed = 0.0;
windBearing = 0;
visibility = 0.0;
cloudCover = 0.0;
pressure = 0.0;
ozone = 0.0;
}
cForecast::~cForecast() {
}
void cForecast::SetForecast(json_t *forecast) {
forecastTime = JsonGetInteger(forecast, "time");
summary = JsonGetString(forecast, "summary");
icon = JsonGetString(forecast, "icon");
sunriseTime = JsonGetInteger(forecast, "sunriseTime");
sunsetTime = JsonGetInteger(forecast, "sunsetTime");
moonPhase = JsonGetFloat(forecast, "moonPhase");
precipIntensity = JsonGetFloat(forecast, "precipIntensity");
precipProbability = JsonGetFloat(forecast, "precipProbability");
percipType = JsonGetString(forecast, "percipType");
temperature = JsonGetFloat(forecast, "temperature");
apparentTemperature = JsonGetFloat(forecast, "apparentTemperature");
temperatureMin = JsonGetFloat(forecast, "temperatureMin");
temperatureMinTime = JsonGetInteger(forecast, "temperatureMinTime");
temperatureMax = JsonGetFloat(forecast, "temperatureMax");
temperatureMaxTime = JsonGetInteger(forecast, "temperatureMaxTime");
humidity = JsonGetFloat(forecast, "humidity");
windSpeed = JsonGetFloat(forecast, "windSpeed");
windBearing = JsonGetInteger(forecast, "windBearing");
visibility = JsonGetFloat(forecast, "visibility");
cloudCover = JsonGetFloat(forecast, "cloudCover");
pressure = JsonGetFloat(forecast, "pressure");
ozone = JsonGetFloat(forecast, "ozone");
}
bool cForecast::TimeMatch(time_t compare) {
//forecast is valid if time of forecast is between 30mins before or after compare time
int difference = abs(compare - forecastTime);
if (difference <= 1800)
return true;
return false;
}
bool cForecast::DayMatch(time_t compare) {
int difference = compare - forecastTime;
if (difference >= 0 && difference <= 86400)
return true;
return false;
}
string cForecast::GetDate(time_t myTime) {
struct tm *ts;
ts = localtime(&myTime);
return *cString::sprintf("%d.%02d", ts->tm_mday, ts->tm_mon+1);
}
string cForecast::GetTime(time_t myTime) {
struct tm *ts;
ts = localtime(&myTime);
return *cString::sprintf("%02d:%02d", ts->tm_hour, ts->tm_min);
}
string cForecast::GetDateTime(time_t myTime) {
struct tm *ts;
ts = localtime(&myTime);
return *cString::sprintf("%d.%02d %02d:%02d", ts->tm_mday, ts->tm_mon+1, ts->tm_hour, ts->tm_min);
}
string cForecast::GetWindBearingString(void) {
string sBearing = "";
if (windBearing >= 349 || windBearing <= 11) {
sBearing = "N";
} else if (windBearing > 11 && windBearing <= 34) {
sBearing = "NNE";
} else if (windBearing > 34 && windBearing <= 56) {
sBearing = "NE";
} else if (windBearing > 56 && windBearing <= 79) {
sBearing = "ENE";
} else if (windBearing > 79 && windBearing <= 101) {
sBearing = "E";
} else if (windBearing > 101 && windBearing <= 123) {
sBearing = "ESE";
} else if (windBearing > 123 && windBearing <= 145) {
sBearing = "SE";
} else if (windBearing > 145 && windBearing <= 168) {
sBearing = "SSE";
} else if (windBearing > 168 && windBearing <= 191) {
sBearing = "S";
} else if (windBearing > 191 && windBearing <= 213) {
sBearing = "SSW";
} else if (windBearing > 213 && windBearing <= 235) {
sBearing = "SW";
} else if (windBearing > 235 && windBearing <= 258) {
sBearing = "WSW";
} else if (windBearing > 258 && windBearing <= 281) {
sBearing = "W";
} else if (windBearing > 281 && windBearing <= 303) {
sBearing = "WNW";
} else if (windBearing > 303 && windBearing <= 325) {
sBearing = "NW";
} else if (windBearing > 325 && windBearing <= 348) {
sBearing = "NNW";
}
return sBearing;
}
void cForecast::Debug(bool verbose) {
if (type == ftCurrent) {
dsyslog("weatherforecast: current weather for %s at %s, summary: \"%s\", icon: \"%s\"", GetDate(forecastTime).c_str(), GetTime(forecastTime).c_str(), summary.c_str(), icon.c_str());
} else if (type == ftHourly) {
dsyslog("weatherforecast: hourly weather for %s on %s, summary: \"%s\", icon: \"%s\"", GetDate(forecastTime).c_str(), GetTime(forecastTime).c_str(), summary.c_str(), icon.c_str());
} else if (type == ftDaily) {
dsyslog("weatherforecast: daily weather for %s, summary: \"%s\", icon: \"%s\"", GetDate(forecastTime).c_str(), summary.c_str(), icon.c_str());
}
if (!verbose)
return;
dsyslog("weatherforecast: sunrise time %ld, sunset time: %ld, moon phase %f", sunriseTime, sunsetTime, moonPhase);
dsyslog("weatherforecast: min temp %f at %ld, max temp %f at %ld", temperatureMin, temperatureMinTime, temperatureMax, temperatureMaxTime);
dsyslog("weatherforecast: precipInt %f, precipProp: %f, type %s", precipIntensity, precipProbability, percipType.c_str());
dsyslog("weatherforecast: temperature %f °C, apparentTemp %f °C, humidity: %f", temperature, apparentTemperature, humidity);
dsyslog("weatherforecast: windSpeed %f, windBearing: %d, visibility %f, cloudCover: %f, pressure %f, ozone: %f", windSpeed, windBearing, visibility, cloudCover, pressure, ozone);
}
|