-
Notifications
You must be signed in to change notification settings - Fork 0
/
Observation.cpp
executable file
·403 lines (350 loc) · 8.89 KB
/
Observation.cpp
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/**
* @file Observation.cpp
* @author Josep Dols ([email protected])
* @brief Observation Class
* @version 1.0.0
* @date 2018-10-06
*
* @copyright Copyright (c) 2019
*
* The observation object is intended to store all the information related to
* a specific measurement made by the Hideki physical device. This is the basic
* object in the application.
*/
#include "Observation.h"
#include <ctime>
#include <iostream>
#include <list>
#include <math.h>
using namespace std;
/**
* @brief Construct a new Observation object
*
* Creates a new Observation object, with all the values initialized to 0,
* except the pressure, initialized to 1013(STD) and the timestamp, wich is
* established as the current UNIX timestamp.
*/
Observation::Observation() {
timestamp = std::time(nullptr);
pressure = 1013;
rainfall = 0;
temperature[0] = 0.0; temperature[1] = 0.0; temperature[2] = 0.0;
humidity[0] = 0.0; humidity[1] = 0.0; humidity[2] = 0.0;
wind_chill = 0.0;
wind_gust = 0.0;
wind_dir = 0;
}
/**
* @brief Construct a new Observation object
*
* Creates a new Observation object, with all the values initialized to 0,
* except the pressure, initialized to 1013(STD) and the timestamp, which is
* indicated in a parameter.
*
* @param newTimestamp Timestamp to assign to the Observation.
*/
Observation::Observation(unsigned int newTimestamp){
timestamp = newTimestamp;
pressure = 1013;
rainfall = 0;
temperature[0] = 0.0; temperature[1] = 0.0; temperature[2] = 0.0;
humidity[0] = 0.0; humidity[1] = 0.0; humidity[2] = 0.0;
wind_chill = 0.0;
wind_gust = 0.0;
wind_dir = 0;
}
/**
* @brief Get the value of the timestamp attribute
*
* @return unsigned int Current timestamp of the Observation
*/
unsigned int Observation::getTimestamp() {
return timestamp;
}
/**
* @brief Set the value of the timestamp attribute
*
* @param newTimestamp New timestamp to assign to the Observation
*/
void Observation::setTimestamp(unsigned int newTimestamp) {
timestamp = newTimestamp;
}
/**
* @brief Get the value of a temperature attribute
*
* @param pos Identifier of the temperature to obtain
* @return float Value of the temperature selected
*/
float Observation::getTemperature(int pos) {
return temperature[pos];
}
/**
* @brief Set the value of a temperature attribute
*
* @param newTemperature New value of the selected temperature
* @param pos Identifier of the temperature to modify
*/
void Observation::setTemperature(float newTemperature, int pos) {
temperature[pos] = newTemperature;
}
/**
* @brief Get the value of a humidity attribute
*
* @param pos Identifier of the humidity to obtain
* @return float Value of the humidity selected
*/
float Observation::getHumidity(int pos) {
return humidity[pos];
}
/**
* @brief Set the value of a humidity attribute
*
* @param newHumidity New value of the selected humidity
* @param pos Identifier of the temperature to modify
*/
void Observation::setHumidity(float newHumidity, int pos) {
humidity[pos] = newHumidity;
}
/**
* @brief Get the value of the pressure attribute
*
* @return float Value of the pressure
*/
float Observation::getPressure() {
return pressure;
}
/**
* @brief Set the value of the pressure attribute
*
* @param newPressure New value of the pressure
*/
void Observation::setPressure(float newPressure) {
pressure = newPressure;
}
/**
* @brief Get the value of the wind chill attribute
*
* @return float Value of the wind chill
*/
float Observation::getWindChill()
{
return wind_chill;
}
/**
* @brief Set the value of the wind chill attribute
*
* @param newWindChill New value of the wind chill
*/
void Observation::setWindChill(float newWindChill)
{
wind_chill = newWindChill;
}
/**
* @brief Get the value of the wind gust attribute
*
* @return float Value of the wind gust
*/
float Observation::getWindGust() {
return wind_gust;
}
/**
* @brief Set the value of the wind gust attribute
*
* @param newWindGust New value of the wind gust
*/
void Observation::setWindGust(float newWindGust) {
wind_gust = newWindGust;
}
/**
* @brief Get the value of the wind speed attribute
*
* @return float Value of the wind speed
*/
float Observation::getWindSpeed()
{
return wind_speed;
}
/**
* @brief Set the value of the wind speed attribute
*
* @param newWindSpeed New value of the wind speed
*/
void Observation::setWindSpeed(float newWindSpeed)
{
wind_speed = newWindSpeed;
}
/**
* @brief Get the value of the wind direction attribute
*
* @return float Value of the wind direction
*/
float Observation::getWindDir() {
return wind_dir;
}
/**
* @brief Set the value of the wind direction attribute
*
* @param newWindDir New value of the wind direction
*/
void Observation::setWindDir(float newWindDir) {
wind_dir = newWindDir;
}
/**
* @brief Get the value of the rainfall attribute
*
* @return float Value of the rainfall
*/
float Observation::getRainfall() {
return rainfall;
}
/**
* @brief Set the value of the rainfall attribute
*
* @param newRainfall New value of the rainfall
*/
void Observation::setRainfall(float newRainfall) {
rainfall = newRainfall;
}
/**
* @brief Get the value of the dew point attribute
*
* @return float Value of the dew point
*/
float Observation::getDewPoint()
{
return dew_point;
}
/**
* @brief Set the value of the dew point attribute
*
* @param newDewPoint New value of the dew point
*/
void Observation::setDewPoint(float newDewPoint)
{
dew_point = newDewPoint;
}
/**
* @brief Get the value of the RealFeel attribute
*
* @return float Value of the RealFeel
*/
float Observation::getRealFeel()
{
return real_feel;
}
/**
* @brief Set the value of the RealFeel attribute
*
* @param newRealFeel New value of the RealFeel
*/
void Observation::setRealFeel(float newRealFeel)
{
real_feel = newRealFeel;
}
/**
* @brief Calculation of the dew point
*
* From the current temperature and humidity attributes already present in the
* Observation, the associated dew point is calculated.
*
* @return short int If the calculated value is valid.
*/
short int Observation::calculateDewPoint()
{
float f_dew_point;
if (humidity[1] == 0.0 & temperature[1] == 0.0)
return -1;
f_dew_point = pow(humidity[1]/100, 0.125);
f_dew_point *= (112 + (0.9*temperature[1]));
f_dew_point -= 112;
dew_point = f_dew_point;
return 0;
}
/**
* @brief Calculation of the RealFeel value
*
* From the different attributes of an Observation, and following the original
* patent function, calculates the RealFeel value associate to an Observation
*
* Note: currently the Rain Index (RI1 & RI2) are 0.
*
* TODO: Introduce an external UV value to the formulae.
*
* @param uv_index UV index externally calculated
* @return short int
*/
short int Observation::calculateRealFeel(int uv_index)
{
float temp1_f;
float wind_speed_mph;
float dew_point1_f;
float MFT;
if (humidity[1] == 0.0 & temperature[1] == 0.0)
return -1;
calculateDewPoint();
// Initial conversions
temp1_f = ((temperature[1]*9) / 5) + 32;
wind_speed_mph = wind_speed / 1,609;
dew_point1_f = ((dew_point*9) / 5) + 32;
// Step 205. Separate ways depending on T1.
if (temp1_f > 65)
{
// Step 210. Calculation of WSP2
float WSP2, SI2, H2, P2;
float w_a;
if (wind_speed_mph < 4)
{
w_a = wind_speed_mph/2 + 2;
}
else if (wind_speed_mph > 56)
{
w_a = 56.0;
}
else
{
w_a = wind_speed_mph;
}
WSP2 = (80 - temp1_f) * (0.566 + 0.25*sqrt(w_a) - 0.0166 * w_a) * (sqrt(pressure/10)/10);
// Step 220. Calculation of SI2
SI2 = uv_index;
// Step 230. Calculation of H2
float d_a;
if (dew_point1_f >= (55+sqrt(wind_speed_mph)))
{
d_a = dew_point1_f;
}
else
{
d_a = 55 + sqrt(wind_speed_mph);
}
H2 = pow((d_a - 55 - sqrt(wind_speed_mph)), 2) / 30;
// Step 240. Calculation of P2
P2 = 0;
// Step 250. Calculation of MFT
MFT = 80 - WSP2 + SI2 + H2 - P2;
}
else
{
// Step 215. Calculation of WSP1
float WSP1, SI1, H1, P1;
WSP1 = sqrt(wind_speed_mph) * (sqrt(pressure/10)/10);
// Step 225. Calculation of SI1
SI1 = uv_index;
// Step 235. Calculation of H1
float d_a;
if (dew_point1_f >= (55+sqrt(wind_speed_mph)))
{
d_a = dew_point1_f;
}
else
{
d_a = 55 + sqrt(wind_speed_mph);
}
H1 = pow((d_a - 55 - sqrt(wind_speed_mph)), 2) / 30;
// Step 245. Calculation of P1
P1 = 0;
// Step 255. Calculation of MFT
MFT = temp1_f - WSP1 + SI1 + H1 - P1;
}
real_feel = ((MFT - 32) * 5) / 9;
}