forked from nanderoo/open-hamclock-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrap_reader.cpp
More file actions
88 lines (66 loc) · 1.99 KB
/
Copy pathdrap_reader.cpp
File metadata and controls
88 lines (66 loc) · 1.99 KB
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstring>
static const int DRAPDATA_NPTS = 440; // bins
static const int DRAPDATA_PERIOD = 24 * 3600; // 24 hours window
struct DrapCache {
float x[DRAPDATA_NPTS]; // hours ago
float y[DRAPDATA_NPTS]; // max value seen
};
int main(int argc, char* argv[])
{
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " stats.txt\n";
return 1;
}
std::ifstream infile(argv[1]);
if (!infile.is_open()) {
std::cerr << "Cannot open file\n";
return 1;
}
DrapCache drap_cache;
std::memset(&drap_cache, 0, sizeof(drap_cache));
time_t t_now = std::time(nullptr);
std::string line;
int n_lines = 0;
int accepted = 0;
while (std::getline(infile, line)) {
n_lines++;
long utime;
float min, max, mean;
if (std::sscanf(line.c_str(), "%ld : %f %f %f",
&utime, &min, &max, &mean) != 4) {
std::cerr << "Garbled: " << line << "\n";
continue;
}
int age = t_now - utime;
int xi = DRAPDATA_NPTS *
(DRAPDATA_PERIOD - age) /
DRAPDATA_PERIOD;
if (xi < 0 || xi >= DRAPDATA_NPTS)
continue;
drap_cache.x[xi] = age / (-3600.0f);
if (max > drap_cache.y[xi])
drap_cache.y[xi] = max;
accepted++;
}
infile.close();
// Diagnostics
int populated = 0;
for (int i = 0; i < DRAPDATA_NPTS; i++)
if (drap_cache.y[i] > 0)
populated++;
std::cout << "Lines read: " << n_lines << "\n";
std::cout << "Lines accepted: " << accepted << "\n";
std::cout << "Bins populated: " << populated
<< " / " << DRAPDATA_NPTS << "\n";
if (populated < DRAPDATA_NPTS / 2)
std::cout << "Data likely too sparse\n";
else
std::cout << "Data density acceptable\n";
return 0;
}