-
Notifications
You must be signed in to change notification settings - Fork 1
/
hourinfo.cpp~
80 lines (69 loc) · 1.45 KB
/
hourinfo.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
#include "hourinfo.h"
#include <string>
#include <map>
#include <list>
#include <climits>
SensorValues::SensorValues(): nkeys(7){
std::string keys [] = {
"temperature",
"humidity",
"light",
"soilmoisture",
"x",
"y",
"z"
};
for (int i = 0; i < nkeys; i++){
m[keys[i]] = 0.0;
}
}
float SensorValues::get(std::string key){
return m[key];
}
void SensorValues::setvalues(float value){
}
HourInfo::HourInfo(){
clear();
}
void HourInfo::clear(){
nvalues = 0;
mean.setvalues(0.0);
acc.setvalues(0.0);
max.setvalues(-9999999);
min.setvalues(9999999);
dominant_colour = 'n';
//samples_per_hour = (30/NORMAL_MODE_TIME);
}
void HourInfo::update(SensorValues v, char last_colour){
update_max(v);
update_min(v);
update_mean(v);
}
void HourInfo::update_max(SensorValues v){
for(auto it ){
if(max.m.find(v_pair.first) != max.m.end()){
if(max.m[v_pair.first] < v_pair.second){
max.m[v_pair.first] = v_pair.second;
}
}
}
}
void HourInfo::update_min(SensorValues v){
for(const std::pair<std::string, float> v_pair: v){
if(min.m.find(v_pair.first) != std::map::end){
if(min.m[v_pair.first] > v_pair.second){
min.m[v_pair.first] = v_pair.second;
}
}
}
}
void HourInfo::update_mean(SensorValues v){
nvalues++;
for(const auto v_pair: v){
if(mean.m.find(v_pair.first) != std::map::end){
acc.m[v_pair.first] += v_pair.second;
mean.m[v_pair.first] = acc.m[v_pair.first]/nvalues;
}
}
}
HourInfo hour_info;