time_series_range.cpp

Example for RDM::TIME_SERIES template classes. This example needs a compiled schema, time_series_range.sdl.

This example shows usage of the RDM::TIME_SERIES template classes with a single chain. First, values are collected into ranges by the RDM::TIME_SERIES::collect class, then a number of ranges are averaged using the RDM::TIME_SERIES::geometric_mean class, and finally rows are inserted using the RDM::TIME_SERIES::insert_row class.

#include <math.h>
#include "rdmtimeseries.h"
#include "time_series_range_structs.h"
static RDM_RETCODE timeSeriesRange (RDM_DB db)
{
using namespace RDM_CPP::TIME_SERIES_RANGE;
using namespace RDM::TIME_SERIES;
const double tau = 6.283185307179586;
collect <16, MEASUREMENT_RANGE,
geometric_mean <16, MEASUREMENT_RANGE, double,
double factor = 1.0442737824;
double adjust = 1.0;
rc = ts_chain.init (db);
for (uint64_t time_stamp = 0; rc == sOKAY && time_stamp < 256; time_stamp++)
{
const double signal = adjust * (sin (tau * time_stamp / 16) * 0.1 + 1);
MEASUREMENT measurement = {time_stamp, signal};
rc = ts_chain.put_value (&measurement);
adjust *= factor;
}
return rc;
}