time_series_restore_aggregate.cpp

Example for the RDM::TIME_SERIES::restore_aggregate template classe. This example needs a compiled schema, time_series_restore_aggregate.sdl.

This example also uses the RDM::TIME_SERIES::split, RDM::TIME_SERIES::stats, and RDM::DB::insert_row classes. If you are interesed in how to use those classes we suggest that you instead take a look at the time_series_stats.cpp example.

This example code is meant to be called several time to demonstrate how to handle a system crash or other senarios where this code need to be restarted. The RDM::TIME_SERIES::restore_aggregate is able to restore the state of the stat class for aggregation to continue with the left over data from when it was last run. Please see the detailed description of RDM::TIME_SERIES::restore_aggregate for how this works.

#include "time_series_restore_aggregate_structs.h"
#include <math.h>
static RDM_RETCODE timeSeriesRestoreAggregate (RDM_DB db, uint32_t next_time_stamp)
{
using namespace RDM_CPP::TIME_SERIES_STATS;
using namespace RDM::TIME_SERIES;
using namespace RDM::DB;
RDM_CPP::TIME_SERIES_STATS::KEY_MEASUREMENT_TIME_STAMP_CURRENT,
RDM_CPP::TIME_SERIES_STATS::KEY_MEASUREMENT_STATS1_TIME_STAMP_LAST,
stats <32, RDM_CPP::TIME_SERIES_STATS::MEASUREMENT_STATS1,
RDM_RETCODE rc = ts_chain.init (db);
for (uint64_t time_stamp = next_time_stamp; rc == sOKAY && time_stamp < next_time_stamp + 100; time_stamp++)
{
const double tau = 6.283185307179586;
const double signal = sin (tau * time_stamp / 50);
RDM_CPP::TIME_SERIES_STATS::MEASUREMENT measurement = {time_stamp, signal};
rc = ts_chain.put_value (&measurement);
}
return rc;
}
RDM_RETCODE init(RDM_DB db)
Initialize this object.
Definition: rdm_db_insert_row.h:121
Time series for split template classes.
Time series for restore_aggregate template class.
The RDM Time Series Namespace.
Definition: rdm_time_series.h:32
Time series for stats template class.
@ sOKAY
Definition: rdmretcodetypes.h:97
The RDM Database Namespace.
Definition: rdm_db.h:29
Template Class for inserting a row.
Definition: rdm_db_insert_row.h:39
Template Class for doing statistics.
Definition: rdm_time_series_stats.h:63
Template Class for doing a split.
Definition: rdm_time_series_split.h:42
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:305
Template class for restoring an aggregate classe.
Definition: rdm_time_series_restore_aggregate.h:109
Time series for insert_row template class.
RDM_RETCODE
RDM status and error return codes.
Definition: rdmretcodetypes.h:43