Skip to main content

ReadHistoryProcessed (Aggregation)

HistoryRead Aggregation mode, combined with standard aggregation functions. Given an interval, an aggregation function, and a subinterval width, the server returns the aggregation results for each subinterval.

Preliminary / Supporting
  • To pull all original points, please use ReadHistory (Raw).
  • For interpolation at a specific point in time, please use ReadHistoryAtTime.
  • Aggregate functions and constants NodeId are described in darra/opcua/history.hpp HistoryAggregate.

Signature​

std::vector<DataValue> ReadHistoryProcessed(
std::string const& node_id,
int64_t start_ft, int64_t end_ft,
double processing_interval_ms,
std::string const& aggregate_node_id);

Standard Aggregation Function NodeId (ns=0)​

HistoryAggregate Constants (in darra/opcua/history.hpp), 9 in total:

ConstantsNodeIdMeaning
HistoryAggregate::Average"i=2342"Arithmetic Mean of Values in an Interval
HistoryAggregate::Minimum"i=2346"Minimum Value in the Interval
HistoryAggregate::Maximum"i=2347"Maximum value in the interval
HistoryAggregate::Count"i=2352"Number of data points with a "Good" status within the interval
HistoryAggregate::Total"i=2348"Sum of Values in an Interval (Algebraic Sum)
HistoryAggregate::StandardDeviationSample"i=11427"Sample standard deviation (Sample), denominator n-1
HistoryAggregate::TimeAverage"i=11285"Time-Weighted Average (Weighted by SamplingInterval)
HistoryAggregate::Range"i=2353"Within the range (Max - Min)
HistoryAggregate::Delta"i=11286"End of Interval − Start of Interval

The constant type is inline constexpr const char*, and it is passed aggregate_node_id directly as.

Usage​

Hourly average of the 24-hour temperature​

constexpr int64_t WIN_EPOCH_OFFSET = 116444736000000000LL;

auto now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
int64_t end_ft = WIN_EPOCH_OFFSET + now_ns / 100;
int64_t start_ft = end_ft - 24LL * 3600 * 10000000;

auto values = s.ReadHistoryProcessed(
"ns=2;s=Temperature",
start_ft, end_ft,
/*processing_interval_ms=*/3600000.0, // 1 hour
HistoryAggregate::Average);
// Returns 24 values DataValue, each representing the average for that hour

for (size_t i = 0; i < values.size(); ++i) {
std::cout << "hour " << i << " avg = " << values[i].Value().AsString() << "\n";
}

Highest Temperature Each Day of the Week​

auto maxes = s.ReadHistoryProcessed("ns=2;s=Temperature",
start_ft, end_ft,
/*processing_interval_ms=*/86400000.0, // 1 day
HistoryAggregate::Maximum);

Total traffic in one hour​

auto totals = s.ReadHistoryProcessed("ns=2;s=FlowRate",
start_ft, end_ft,
/*processing_interval_ms=*/3600000.0,
HistoryAggregate::Total);

Performance Advantages​

  • Eliminate the transmission of the origin and the client's secondary calculations
  • The server performs aggregations directly on the history database
  • Standard Solutions for Cross-Day and Cross-Week Reports

Server Requirements​

  • Historian must implement this aggregate function (the supported functions are listed in the ServerCapabilities/AggregateFunctions column on the server).
  • Unsupported AggregationsDoes not return a value: If the entire ReadHistoryProcessed test fails darra::opcua::Exception, discard it; use ex.status() to retrieve the code (e.g., Status::BadHistoryOperationUnsupported)

Next Step​