メインコンテンツまでスキップ

ReadHistoryProcessed (集約)

HistoryRead 集計モード。標準の集計関数と組み合わせて使用します。区間、集計関数、およびサブ区間の幅を指定すると、サーバーは各サブ区間の集計結果を返します。

前段 / 付属品
  • すべての原点を引っ張る際は、以下を使用してください ReadHistory (Raw).
  • 特定の時点における補間値については、以下をご利用ください ReadHistoryAtTime.
  • 集約関数 NodeId 定数については、 の を darra/opcua/history.hpp 参照のこと HistoryAggregate。

署名​

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);

標準的な積分関数 NodeId (ns=0)​

HistoryAggregate 定数(内 darra/opcua/history.hpp)、計 9 個:

定数NodeId意味
HistoryAggregate::Average"i=2342"区間内の値の算術平均
HistoryAggregate::Minimum"i=2346"区間内の最小値
HistoryAggregate::Maximum"i=2347"区間内の最大値
HistoryAggregate::Count"i=2352"指定範囲内の「Good」状態のデータポイントの数
HistoryAggregate::Total"i=2348"区間内の値の合計(代数和)
HistoryAggregate::StandardDeviationSample"i=11427"標本の標準偏差 (Sample)、分母は n-1
HistoryAggregate::TimeAverage"i=11285"時間加重平均(SamplingInterval に基づく割合)
HistoryAggregate::Range"i=2353"範囲内 (Max - Min)
HistoryAggregate::Delta"i=11286"区間の終わり − 区間の始まり

定数型は であり inline constexpr const char*、そのまま として aggregate_node_id 渡されます。

使用方法​

24時間の気温の毎時間の平均​

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);
// 24件が返されます DataValue。それぞれがその時間の平均値です。

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

一週間の各日の最高気温​

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

一時間の累計トラフィック​

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

性能上の利点​

  • 原点の送信とクライアント側での再計算を省略する
  • サーバー側で履歴データベースに対して直接集計を行う
  • 日またぎ/週またぎのレポートに関する標準的な手法

サーバー側の要件​

  • Historian はこの集計関数を実装する必要があります(サーバー側の ServerCapabilities/AggregateFunctions にサポートされているものが記載されています)。
  • サポートされていない集約戻り値がない: ReadHistoryProcessed 全体的に失敗した場合はすべてスローし darra::opcua::Exception、 を使用してコードを取得 ex.status() する(例: Status::BadHistoryOperationUnsupported)

次のステップ​