farm-ng-core
farm_ng::TimeSeries< TValueWithStamp > Class Template Reference

TimeSeries is a container of StampedValue that are sorted by their timestamp. More...

#include <time_series.h>

Classes

struct  Bounds
 

Public Types

using ValueWithStamp = TValueWithStamp
 
using Container = std::deque< ValueWithStamp >
 
using ConstIterator = typename Container::const_iterator
 

Public Member Functions

bool empty () const
 Returns true if there are no Values in series. More...
 
void insert (ValueWithStamp const &value)
 Adds ValueWithStamp to series. More...
 
size_t size () const
 Number of values in series. More...
 
ValueWithStamp const & operator[] (size_t idx) const
 access ValueWithStamp by index More...
 
Expected< ValueWithStampfindNearest (double query_stamp) const
 Find nearest value given stamp. More...
 
Expected< BoundsfindBounds (double query_stamp) const
 
Expected< ValueWithStampfindNearestWithin (double stamp, double threshold) const
 Find nearest value given stamp within search radius threshold. More...
 
bool testIsSortedInvariant () const
 Just for unit testing. More...
 
std::enable_if_t< time_series::InterpolativeValue< TValueWithStamp >, Expected< TValueWithStamp > > interpolatedValue (double query_stamp, time_series::MaxGap maximal_time_gap=time_series::MaxGap(1.0), time_series::NearnessThreshold nearness_threshold=time_series::NearnessThreshold(1e-5)) const
 Returns interpolated value from time series at query_stamp. More...
 
ValueWithStamp const & front () const
 
ValueWithStamp const & back () const
 
void clear ()
 
void pop_front ()
 
void pop_back ()
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
ConstIterator end () const
 
ConstIterator cend () const
 

Detailed Description

template<time_series::StampedValue TValueWithStamp>
class farm_ng::TimeSeries< TValueWithStamp >

TimeSeries is a container of StampedValue that are sorted by their timestamp.

Invariant: time_ordered_series_ is sorted by time_series::getStamp.

Consequence: The invariant implies that we have a strict weak ordering relation on the time stamps. Hence, it is not allowed to add NAN timestamps to the time series.

TODO: Add std::ranges support to the API once we fully move to c++20.

Member Typedef Documentation

◆ ConstIterator

template<time_series::StampedValue TValueWithStamp>
using farm_ng::TimeSeries< TValueWithStamp >::ConstIterator = typename Container::const_iterator

◆ Container

template<time_series::StampedValue TValueWithStamp>
using farm_ng::TimeSeries< TValueWithStamp >::Container = std::deque<ValueWithStamp>

◆ ValueWithStamp

template<time_series::StampedValue TValueWithStamp>
using farm_ng::TimeSeries< TValueWithStamp >::ValueWithStamp = TValueWithStamp

Member Function Documentation

◆ back()

template<time_series::StampedValue TValueWithStamp>
ValueWithStamp const& farm_ng::TimeSeries< TValueWithStamp >::back ( ) const
inline

◆ begin()

template<time_series::StampedValue TValueWithStamp>
ConstIterator farm_ng::TimeSeries< TValueWithStamp >::begin ( ) const
inline

◆ cbegin()

template<time_series::StampedValue TValueWithStamp>
ConstIterator farm_ng::TimeSeries< TValueWithStamp >::cbegin ( ) const
inline

◆ cend()

template<time_series::StampedValue TValueWithStamp>
ConstIterator farm_ng::TimeSeries< TValueWithStamp >::cend ( ) const
inline

◆ clear()

template<time_series::StampedValue TValueWithStamp>
void farm_ng::TimeSeries< TValueWithStamp >::clear ( )
inline

◆ empty()

template<time_series::StampedValue TValueWithStamp>
bool farm_ng::TimeSeries< TValueWithStamp >::empty ( ) const
inline

Returns true if there are no Values in series.

◆ end()

template<time_series::StampedValue TValueWithStamp>
ConstIterator farm_ng::TimeSeries< TValueWithStamp >::end ( ) const
inline

◆ findBounds()

template<time_series::StampedValue TValueWithStamp>
Expected<Bounds> farm_ng::TimeSeries< TValueWithStamp >::findBounds ( double  query_stamp) const
inline

◆ findNearest()

template<time_series::StampedValue TValueWithStamp>
Expected<ValueWithStamp> farm_ng::TimeSeries< TValueWithStamp >::findNearest ( double  query_stamp) const
inline

Find nearest value given stamp.

Precondition: stamp is not NAN.

Returns error if times series is empty.

◆ findNearestWithin()

template<time_series::StampedValue TValueWithStamp>
Expected<ValueWithStamp> farm_ng::TimeSeries< TValueWithStamp >::findNearestWithin ( double  stamp,
double  threshold 
) const
inline

Find nearest value given stamp within search radius threshold.

Precondition: stamp is not NAN.

Returns error if |value.stamp - stamp| > threshold.

◆ front()

template<time_series::StampedValue TValueWithStamp>
ValueWithStamp const& farm_ng::TimeSeries< TValueWithStamp >::front ( ) const
inline

◆ insert()

template<time_series::StampedValue TValueWithStamp>
void farm_ng::TimeSeries< TValueWithStamp >::insert ( ValueWithStamp const &  value)
inline

Adds ValueWithStamp to series.

Precondition: stamp is not NAN.

◆ interpolatedValue()

template<time_series::StampedValue TValueWithStamp>
std::enable_if_t< time_series::InterpolativeValue<TValueWithStamp>, Expected<TValueWithStamp> > farm_ng::TimeSeries< TValueWithStamp >::interpolatedValue ( double  query_stamp,
time_series::MaxGap  maximal_time_gap = time_series::MaxGap(1.0),
time_series::NearnessThreshold  nearness_threshold = time_series::NearnessThreshold(1e-5) 
) const
inline

Returns interpolated value from time series at query_stamp.

Note: Only available if TValueWithStamp meets time_series::InterpolativeValue concept.

The following strategy is used:

  1. If query_stamp is close to an existing value in the series, using the nearness_threshold, that exiting value is return directly.
  2. Otherwise, an upper bound value and a lower bound value is found for the query_stamp, and linearly interpolated result between the two values is return, but only if |upper.t - lower.t| <= maximal_time_gap.
  3. If there is no upper or lower bound, or if the |upper.t - lower.t| > maximal_time_gap and error is return.

◆ operator[]()

template<time_series::StampedValue TValueWithStamp>
ValueWithStamp const& farm_ng::TimeSeries< TValueWithStamp >::operator[] ( size_t  idx) const
inline

access ValueWithStamp by index

Precondition: idx < size()

◆ pop_back()

template<time_series::StampedValue TValueWithStamp>
void farm_ng::TimeSeries< TValueWithStamp >::pop_back ( )
inline

◆ pop_front()

template<time_series::StampedValue TValueWithStamp>
void farm_ng::TimeSeries< TValueWithStamp >::pop_front ( )
inline

◆ size()

template<time_series::StampedValue TValueWithStamp>
size_t farm_ng::TimeSeries< TValueWithStamp >::size ( ) const
inline

Number of values in series.

◆ testIsSortedInvariant()

template<time_series::StampedValue TValueWithStamp>
bool farm_ng::TimeSeries< TValueWithStamp >::testIsSortedInvariant ( ) const
inline

Just for unit testing.

Must return always true.


The documentation for this class was generated from the following file: