1 #ifndef FAIF_TS_TRANSFORMATIONS 2 #define FAIF_TS_TRANSFORMATIONS 8 #include <boost/bind.hpp> 10 #include <boost/lambda/lambda.hpp> 11 #include <boost/lambda/bind.hpp> 12 #include <boost/lambda/construct.hpp> 14 #include "TimeSeries.hpp" 17 namespace timeseries {
24 : present_(present), delta_(delta) {}
26 : present_(t.present_), delta_(t.delta_) {}
30 present_ = t.present_;
42 return RealTime( present_ + delta_ * d);
58 if(delta_.total_seconds() != 0) {
60 long delta_2 = delta_.total_seconds() / 2;
61 RealDuration dur = boost::posix_time::time_period(present_, r).length();
62 long duration_sec = dur.total_seconds() + delta_2;
63 int correction_for_minus = ( (duration_sec >= 0) ? 0 : 1 );
64 long out = (duration_sec + correction_for_minus) / delta_.total_seconds() - correction_for_minus;
68 long delta_2 =
static_cast<long>( delta_.total_milliseconds() / 2 );
69 RealDuration dur = boost::posix_time::time_period(present_, r).length();
70 long duration_sec =
static_cast<long>(dur.total_milliseconds() + delta_2);
71 int correction_for_minus = ( (duration_sec >= 0) ? 0 : 1 );
72 long out = (duration_sec + correction_for_minus) / static_cast<long>(delta_.total_milliseconds() ) - correction_for_minus;
93 for(
DigitTime t = start_time + 1; t < end_time; ++t ) {
97 DigitTime proportion_weight = end_time - start_time;
99 Value v = (start_value * proportion_A + end_value * proportion_B) / proportion_weight;
100 Quality q = (start_quality * proportion_A + end_quality * proportion_B) / proportion_weight;
108 struct CountedTimeValue {
121 const DigitTime& getTime()
const {
return time_; }
133 class LinearResampler : boost::noncopyable {
137 current_(trans_.toDigit(first.
getTime()), first ) {}
138 ~LinearResampler() {}
144 if(act_time == current_.getTime() )
149 if(act_time > current_.getTime() + 1) {
152 linearApproximate( last_tv.
getTime(), act_time,
157 current_ = CountedTimeValue( act_time, tv );
162 void finish() { addCurrentValue(); }
167 void addCurrentValue() { ts_.push_back( current_.get() ); }
169 CountedTimeValue current_;
182 TimeSeriesReal::const_iterator it = in.begin();
184 LinearResampler resampler(transformation, *it);
186 std::for_each( it, in.end(), boost::bind(&LinearResampler::addTimeValue, boost::ref(resampler), _1 ) );
188 return resampler.getTimeSeries();
195 std::transform( in.begin(), in.end(), back_inserter(out),
196 boost::lambda::bind( boost::lambda::constructor<TimeValueReal>(),
208 #endif //FAIF_TS_TRANSFORMATIONS timeseries - time hold as RealTime
Definition: TimeSeries.hpp:76
TimeSeriesDigit create(const TimeSeriesReal &in, const Transformation &transformation)
Definition: Transformations.hpp:179
double Quality
quality - real 0..1
Definition: TimeSeries.hpp:51
const Value & getValue() const
Definition: TimeSeries.hpp:140
int DigitTime
digit time type. DigitTime < 0 past, DigitTime >= 0 future, DigitTime == 0 now.
Definition: TimeSeries.hpp:47
double Value
value - real number
Definition: TimeSeries.hpp:49
const RealTime & getTime() const
Definition: TimeSeries.hpp:61
const DigitTime & getTime() const
Definition: TimeSeries.hpp:138
const Quality & getQuality() const
Definition: TimeSeries.hpp:65
const Quality & getQuality() const
Definition: TimeSeries.hpp:142
timeseries value, single value in given real time. Plain old data
Definition: TimeSeries.hpp:54
Definition: TimeSeries.hpp:151
Definition: TimeSeries.hpp:131
const Value & getValue() const
Definition: TimeSeries.hpp:63
boost::posix_time::time_duration RealDuration
the real time duration
Definition: TimeSeries.hpp:37
boost::posix_time::ptime RealTime
the real time type
Definition: TimeSeries.hpp:35