Go to the documentation of this file. 1 #ifndef MOJA_MODULES_CBM_TIMESERIES_H_
2 #define MOJA_MODULES_CBM_TIMESERIES_H_
4 #include <moja/flint/itiming.h>
6 #include "moja/modules/cbm/_modules.cbm_exports.h"
8 #include <boost/optional.hpp>
77 TimeSeries(
int yr0,
int dataPerYr,
int nYrs,
bool subSame,
78 const std::vector<boost::optional<double>> raw,
94 void setTiming(
const flint::ITiming* timing);
103 void setTiming(DateTime start, DateTime end);
108 const std::vector<double>& series()
const;
114 double value()
const;
129 int dataPerYr()
const;
135 bool subSame()
const;
140 const std::vector<boost::optional<double>> raw()
const;
151 std::shared_ptr<TimeSeriesPrep>
_impl;
167 const std::vector<boost::optional<double>>& data,
171 _interpType(interpType), _extraptype(extraptype), _frequency(frequency),
172 _start(start), _multiplier(1.0), _series(data) {}
174 explicit TimeSeries2(
const std::vector<Observation>& observations,
178 _multiplier(1.0), _observations(observations) {}
181 const std::vector<boost::optional<double>>& data,
187 double multiplier()
const;
188 void setMultiplier(
double multiplier);
190 std::vector<Observation> observations()
const;
191 std::vector<double> series(DateTime start, DateTime end)
const;
192 double value()
const;
231 auto observationDate = DateTime(date.year() + 1, 1, 1).addMicroseconds(-1);
242 auto observationDate = DateTime(date.year(), date.month(), 1).addMonths(1).addMicroseconds(-1);
251 return std::vector<Observation>();
264 auto nYrs =
_series.size() / dataPerYr;
266 std::vector<double> result(
_series.size());
267 for (
auto c = 0; c < dataPerYr; ++c) {
271 for (
auto r = 0; r < nYrs; ++r) {
272 if (
_series[ix].is_initialized()) {
280 throw std::runtime_error(
"No data for timeseries column");
285 for (
auto r = 0; r < nYrs; ++r) {
291 return std::vector<double>();
322 #endif // MOJA_MODULES_CBM_TIMESERIES_H_
void setInterpType(InterpType interpType)
Definition: timeseries.h:310
std::vector< boost::optional< double > > _series
Definition: timeseries.h:208
Definition: timeseries.h:159
Definition: ageclasshelper.cpp:12
void setObservations(const std::vector< Observation > &observations)
Definition: timeseries.h:184
Frequency
Definition: timeseries.h:33
ExtrapType _extraptype
Definition: timeseries.h:204
DateOrigin
The date origin of the timeseries. Calendar allows yr0 to be specified as a year....
Definition: timeseries.h:27
boost::optional< double > value
Definition: timeseries.h:156
void addObservation(Observation observation)
Definition: timeseries.h:185
DateTime date
Definition: timeseries.h:155
InterpType _interpType
Definition: timeseries.h:203
Definition: timeseries.h:154
Encapsulates a timeseries of data. Normal usage allows modules to retrieve the most relevant data for...
Definition: timeseries.h:55
double _multiplier
Definition: timeseries.h:207
TimeSeries2()
Definition: timeseries.h:161
DateTime _start
Definition: timeseries.h:206
ExtrapType extrapType() const
Definition: timeseries.h:298
std::shared_ptr< TimeSeriesPrep > _impl
Definition: timeseries.h:150
double value() const
Definition: timeseries.h:294
std::vector< Observation > observations() const
Definition: timeseries.h:220
TimeSeries2(const std::vector< Observation > &observations, ExtrapType extraptype=ExtrapType::NearestYr, InterpType interpType=InterpType::Linear)
Definition: timeseries.h:174
Frequency _frequency
Definition: timeseries.h:205
Definition: timeseries.cpp:13
Frequency frequency() const
Definition: timeseries.h:314
SubSamplingMode
Definition: timeseries.h:45
std::vector< double > series(DateTime start, DateTime end) const
Definition: timeseries.h:254
void setExtrapType(ExtrapType extraptype)
Definition: timeseries.h:302
InterpType interpType() const
Definition: timeseries.h:306
InterpType
Definition: timeseries.h:40
ExtrapType
Definition: timeseries.h:15
void setMultiplier(double multiplier)
Definition: timeseries.h:216
void setData(DateTime start, const std::vector< boost::optional< double >> &data, Frequency frequency=Frequency::Monthly)
Definition: timeseries.h:180
std::vector< Observation > _observations
Definition: timeseries.h:209
Definition: ageclasshelper.cpp:10
double multiplier() const
Definition: timeseries.h:212
TimeSeries2(DateTime start, const std::vector< boost::optional< double >> &data, Frequency frequency=Frequency::Monthly, ExtrapType extraptype=ExtrapType::NearestYr, InterpType interpType=InterpType::ColAverage)
Definition: timeseries.h:166