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::stats and RDM::DB::insert_row classes. If you are interesed in how to use those classes we suggest that you instead look at the time_series_stats.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::stats class stripped away. We therefor explicitly declate the needed type for the RDM::TIME_SERIES::stats 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);
RDM_CPP::TIME_SERIES_CUSTOM::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
@ NOT_TRANSACTIONAL
Definition: rdm_db_transaction.h:36
The RDM Time Series Namespace.
Definition: rdm_time_series.h:32
Time series for stats template class.
@ sOKAY
Definition: rdmretcodetypes.h:100
enum RDM_RETCODE_E RDM_RETCODE
RaimaDB status and error return codes.
The RDM Database Namespace.
Definition: rdm_db.h:31
TRANSACTIONAL_T
Whether the operation is required to be transactional.
Definition: rdm_db_transaction.h:34
Time series for custom template class.
RDM_RETCODE init(RDM_DB p_db)
Initialize this object.
Definition: rdm_time_series_stats.h:217
Template Class for doing statistics.
Definition: rdm_time_series_stats.h:65
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:346
Time series for insert_row template class.