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 ReadRaw.
- For interpolation at a specific point in time, please use ReadAtTime.
- Standard Aggregation NodeId Constants in
HistoryAggregateClass.
Signature
public List<OpcUaDataValue> readHistoryProcessed(
String nodeId,
Instant start,
Instant end,
double processingIntervalMs,
String aggregateNodeId);
HistoryAggregate Standard Aggregation Constants
| Constants | NodeId | Meaning |
|---|---|---|
| HistoryAggregate.AVERAGE | i=2342 | Arithmetic Mean |
| HistoryAggregate.MINIMUM | i=2346 | Minimum Value |
| HistoryAggregate.MAXIMUM | i=2347 | Maximum value |
| HistoryAggregate.COUNT | i=2352 | Good Status Points |
| HistoryAggregate.TOTAL | i=2348 | Cumulative Total |
| HistoryAggregate.STANDARD_DEVIATION_SAMPLE | i=11427 | Sample standard deviation |
| HistoryAggregate.TIME_AVERAGE | i=11285 | Time-Weighted Average |
| HistoryAggregate.RANGE | i=2353 | Max − Min |
| HistoryAggregate.DELTA | i=11286 | End of Interval − Start of Interval |
For a complete list, see the OPC UA Aggregate Functions Standard (Part 13 §5.4).
Usage
Hourly average of the 24-hour temperature
import java.time.Instant;
import java.time.Duration;
List<OpcUaDataValue> values = ua.readHistoryProcessed(
"ns=2;s=Temperature",
Instant.now().minus(Duration.ofDays(1)),
Instant.now(),
3_600_000.0, /* 1 hour */
HistoryAggregate.AVERAGE);
// Returns 24 values OpcUaDataValue, each representing the average for that hour
try {
for (OpcUaDataValue dv : values) {
if (dv != null) System.out.println(dv.variant());
}
} finally {
for (OpcUaDataValue dv : values) if (dv != null) dv.close();
}
Highest Temperature Each Day of the Week
List<OpcUaDataValue> maxes = ua.readHistoryProcessed(
"ns=2;s=Temperature",
today.minus(Duration.ofDays(7)),
today,
86_400_000.0, /* 1 day */
HistoryAggregate.MAXIMUM);
Total traffic in one hour
List<OpcUaDataValue> totals = ua.readHistoryProcessed(
"ns=2;s=FlowRate",
Instant.now().minus(Duration.ofHours(1)),
Instant.now(),
3_600_000.0,
HistoryAggregate.TOTAL);
Performance Advantages
- Eliminate the transmission of the origin and the client's secondary calculations
- The server performs aggregations directly on the historical database, eliminating the need to transfer raw data.
- Standard Practices for Cross-Day/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 aggregations typically return
BadHistoryOperationUnsupportedorBadNotSupported; Aggregation-specific status codes are not currently available.