time_series_custom.cpp

Example for the RDM::TIME_SERIES::custom template class. This example needs a compiled schema, time_series_custom.sdl.

This example also uses the RDM::TIME_SERIES::stat and RDM::TIME_SERIES::insert_row classes. If you are interesed in how to use those classes we suggest that you instead look at the time_series_stat.cpp example.

Here we use a scema with a table that have some of the required columns for a stat result set as produced by the RDM::TIME_SERIES::stat class stripped away. We therefor explicitly declate the needed type for the RDM::TIME_SERIES::stat class and use an extension of the RDM::TIME_SERIES::custom class that can do the convert. This convert class has only one method. We have crafted it as a template methode making it slightly more general. However, in our case here, it would have been sufficient to use a normal method.

#include "time_series_custom_structs.h"
#include <math.h>
typedef struct
{
uint64_t time_stamp_first;
uint64_t time_stamp_last;
uint64_t n;
double value_sum;
double value_sum2;
} MEASUREMENT_STATS;
using namespace RDM_CPP::TIME_SERIES_CUSTOM;
using namespace RDM::TIME_SERIES;
using namespace RDM::DB;
template <class NEXT>
class strip : public RDM::TIME_SERIES::custom<NEXT>
{
public:
template <class SOURCE_STATS_T>
RDM_RETCODE put_stats (SOURCE_STATS_T *source_stats,
)
{
MEASUREMENT_STATS_CUSTOM custom_stats =
{source_stats->time_stamp_last,
source_stats->n,
source_stats->value_sum};
RDM_RETCODE rc = custom<NEXT>::put_stats (&custom_stats, transactional);
return rc;
}
};
static RDM_RETCODE timeSeriesCustom (RDM_DB db)
{
stats <32, MEASUREMENT_STATS,
strip <insert_row <TABLE_MEASUREMENT_STATS_CUSTOM>>>
ts_chain;
RDM_RETCODE rc = ts_chain.init (db);
for (uint64_t time_stamp = 0; rc == sOKAY && time_stamp < 128; time_stamp++)
{
const double tau = 6.283185307179586;
const double signal = sin (tau * time_stamp / 50);
MEASUREMENT measurement = {time_stamp, signal};
rc = ts_chain.put_value (&measurement);
}
return rc;
}
Template Class for doing custom operations.
Definition: rdm_time_series_custom.h:55
The RDM Time Series Namespace.
Definition: rdm_time_series.h:32
Time series for stats template class.
@ sOKAY
Definition: rdmretcodetypes.h:96
@ NOT_TRANSACTIONAL
Definition: rdm_db_transaction.h:37
The RDM Database Namespace.
Definition: rdm_db.h:29
Time series for custom template class.
Template Class for doing statistics.
Definition: rdm_time_series_stats.h:63
TRANSACTIONAL_T
Whether the operation is required to be transactional.
Definition: rdm_db_transaction.h:35
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:303
RDM_RETCODE init(RDM_DB db)
Initialize this object.
Definition: rdm_time_series_stats.h:164
Time series for insert_row template class.
RDM_RETCODE
RDM status and error return codes.
Definition: rdmretcodetypes.h:44