-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.cpp
More file actions
39 lines (35 loc) · 853 Bytes
/
statistics.cpp
File metadata and controls
39 lines (35 loc) · 853 Bytes
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
#include "task.h"
void Distribution::add(double val)
{
++count;
sum += val;
sum2 += val * val;
++values[int(val)];
}
void Distribution::toStream(std::ostream& o) const
{
double mean = sum/count;
double mean2 = sum2/count;
o
<< "count: " << count << "\n"
<< "mean: " << mean << "\n"
<< "deviation: " << std::sqrt(mean2 - mean*mean) << "\n"
<< "distribution:\n";
for (const auto& e: values)
o << e.first << " " << e.second << "\n";
o << std::endl;
}
void TimedDistribution::add(int ts, double val)
{
distribution.add(val);
dependency[ts].value += val;
++ dependency[ts].count;
}
void TimedDistribution::toStream(std::ostream& o) const
{
distribution.toStream(o);
o << "dependency:\n";
for (const auto& d : dependency)
o << d.first << " " << d.second.mean() << "\n";
o << std::endl;
}