-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeatherData.h
141 lines (116 loc) · 3.98 KB
/
WeatherData.h
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
/**
* @author Travis E. Brown
* @version 1.0
*
* WeatherData is the data aggregator. Sources put data into the structure
* using setValue, and sinks pull it out using getValue. Sources don't need
* to set all the properties, and in fact, shouldn't set some of them. The
* setValue will complain if this happens.
*/
#ifndef __WEATHER_DATA_H__
#define __WEATHER_DATA_H__
#include "Wind.h"
#include "Rain.h"
#include "Database.h"
#include "Now.h"
#include "Config.h"
#include "Hysteresis.h"
#include <map>
#include <vector>
#include "Barometer.h"
#include <vector>
#include "Almanac.h"
#define NO_VALUE (0xffffffff)
class WeatherData
{
public:
enum PROPERTY { insideTemp, insideHumidity, outsideTemp, outsideHumidity,
windSpeed, windDirection, averageWindDirection, averageWindSpeed,
windGust, windGustDir, dailyRain, rainRate, dailyET, UV,
solarRadiation, solarPercent, stationPressure, SLP, altimeter,
dewPoint, heatIndex, humidex, windChill, apparentTemp,
cloudHeight, rain24Hour, instantRain, END };
public:
/**
* Default constructor for Weather Data.
*
* @param cfg Configuration item
*/
WeatherData( Config cfg );
/**
* Default constructor for Weather Data.
*/
~WeatherData();
/**
* Sets a weather property to the specified value. This should be used
* by sources to add new data
*
* @param property weather property
* @param value value to set the property to
* @return bool TRUE on succes, FALSE on failure
*/
bool setValue( PROPERTY property, double value );
bool hasData( PROPERTY property );
double getValue( PROPERTY property, time_t howLongAgo,
time_t *actualTime = NULL );
double getHigh( PROPERTY property, time_t howLongAgo,
time_t *actualTime );
double getLow( PROPERTY property, time_t howLongAgo, time_t
*actualTime );
double getTrend( PROPERTY property );
bool newData();
const char *propertyToString( PROPERTY property );
public: // public data members
Now *now;
private: // types
enum DBTable { HOURLY, DAILY };
enum MINMAX { MIN, MAX };
enum SUMMARYTYPE { DAILYSUMMARY = 0, DAYTIMESUMMARY = 1,
NIGHTTIMESUMMARY =2 };
private: // helper functions
// Copy data from temporary set structure to actual structure
void copyData( void );
double getSolarMax();
double getDewPoint();
double getWindChill();
double getHumidex();
double getHeatIndex();
double getApparentTemp();
double getCloudHeight();
void updateDB();
void updateSummary( DBTable table, SUMMARYTYPE type = DAILYSUMMARY );
void doMaintenance();
double computeTrend( PROPERTY property, int duration /* hours */ );
double getCurrent( PROPERTY property );
double getFromObs( PROPERTY property, time_t howLongAgo, time_t
*actualTime );
double getFromHourly( PROPERTY property, time_t howLongAgo, time_t
*actualTime );
double getFromDaily( PROPERTY property, time_t howLongAgo, time_t
*actualTime );
void computeTrends();
double refreshSolarMax();
double getStationPressure();
double getStationVaporPressure( double );
double getActualVaporPressure( double, double );
double humidityCorrection( double, double, double );
void refreshAlmanacs();
private: // data members
Config cfg;
Database db;
double currentSolarMax;
Wind wind;
Rain rain;
std::map< PROPERTY, double > setValues;
std::map< PROPERTY, Hysteresis > inst;
std::map< PROPERTY, double > trend;
std::map< PROPERTY, bool > dataAvailable;
Debug dbg;
Barometer baro;
pthread_rwlock_t rwLock;
Almanac almanacYesterday;
Almanac almanacToday;
Almanac almanacTomorrow;
bool dayTime;
};
#endif // __WEATHER_DATA_H__