TimeSeriesData.cxx
Go to the documentation of this file.
1 // C++ includes
2 #include <algorithm>
3 #include <ctime>
4 #include <iomanip>
5 #include <iostream>
6 #include <string>
7 #include <map>
8 #include <vector>
9 
10 // NOvASoft includes
11 #include "TimeSeriesData.h"
12 
13 namespace nl {
14 
15 ///////////////////////////////////////////////////////////////////////////
16 TimeSeriesData::TimeSeriesData(std::vector<std::time_t> t, std::vector<double> x)
17 {
18  // Check that the two inputs are the same size
19  if (t.size() != x.size()) {
20  std::cerr << "ERROR. Vectors provided are different sizes. Initializing this object's properties to 0." << std::endl;
21  this->T = {0};
22  this->X = {0};
23  } else {
24  this->T = t;
25  this->X = x;
26  }
27 }
28 
29 ///////////////////////////////////////////////////////////////////////////
31 
32 
33 ///////////////////////////////////////////////////////////////////////////
34 unsigned int TimeSeriesData::N() const
35 {
36  return this->T.size();
37 }
38 
39 ///////////////////////////////////////////////////////////////////////////
40 std::time_t TimeSeriesData::MinTime() const
41 {
42  return *std::min_element(this->T.begin(), this->T.end());
43 }
44 
45 ///////////////////////////////////////////////////////////////////////////
46 std::time_t TimeSeriesData::MaxTime() const
47 {
48  return *std::max_element(this->T.begin(), this->T.end());
49 }
50 
51 ///////////////////////////////////////////////////////////////////////////
53 {
54  time_t t1 = this->MinTime();
55  time_t t2 = this->MaxTime();
56 
57  return t2-t1;
58 }
59 
60 ///////////////////////////////////////////////////////////////////////////
62 {
63  return *std::min_element(this->X.begin(), this->X.end());
64 }
65 
66 ///////////////////////////////////////////////////////////////////////////
68 {
69  return *std::max_element(this->X.begin(), this->X.end());
70 }
71 
72 ///////////////////////////////////////////////////////////////////////////
74 {
75  auto meanLambda = [&](double a, double b){return a + b / this->X.size();};
76  return std::accumulate(this->X.begin(), this->X.end(), 0.0, meanLambda);
77 }
78 
79 ///////////////////////////////////////////////////////////////////////////
81 {
82  double x1 = this->MinValue();
83  double x2 = this->MaxValue();
84 
85  return x2-x1;
86 }
87 
88 ///////////////////////////////////////////////////////////////////////////
89 std::ostream& operator<< (std::ostream& out, const TimeSeriesData& ts)
90 {
91  out << std::setiosflags(std::ios::fixed) << std::setprecision(2);
92  out << "Time series data at " << ts << " contains " << ts.N() << " entries.";
93  out << "Time span: " << ts.MinTime() << " -- " << ts.MaxTime();
94  out << "Values: MIN=" << ts.MinValue() << ", MAX=" << ts.MaxValue() << ", MEAN=" << ts.MeanValue();
95 
96  return out;
97 }
98 
99 } //end namespace nl
double MaxValue() const
Largest value in data.
friend std::ostream & operator<<(std::ostream &out, const TimeSeriesData &ts)
Float_t x1[n_points_granero]
Definition: compare.C:5
OStream cerr
Definition: OStream.cxx:7
double MinValue() const
Smallest value in data.
double MeanValue() const
Mean value of data.
std::time_t MinTime() const
Earliest time in data.
double RangeValue() const
Range spanned by data.
const double a
double t2
std::vector< double > X
TimeSeriesData(std::vector< std::time_t > t, std::vector< double > x)
std::time_t MaxTime() const
Latest time in data.
unsigned int N() const
Number of entries in data.
int RangeTime() const
Time spanned by data.
const hit & b
Definition: hits.cxx:21
std::vector< std::time_t > T
A container for time series data typically used in Nearline plotmaking.