e7b485c0a2
#820: SqlServer + QuestDB now serve Part 13 DurationGood / DurationBad from the same Good / Bad region totals TimeWeightedAggregator already computes for PercentGood / PercentBad — reported in milliseconds (OPC UA Duration, the SDK's unit), Uncertain time in neither (Mantis 0006166), same BadNoData / status / Partial rules. AggregateFamilies.Served grows 17 -> 19, so i=11201 and the up-front refusal follow automatically; Gateway still refuses both (explicit served set, unchanged). Client.Shared AggregateType / mapper / CLI gain both. The #796 oracle answers DurationGood through the Good-only subclass as well. QualityMix conformance asserts both directly (Q and QP, hand values, ms, and = PercentGood x interval), replaces the "refused up front" test, and adds Duration* to the forward/reverse/truncated oracle comparisons. #821 (facts only, no decision): SdkAggregateParityTests pins an Uncertain-first late-start interval (QP over [0,20), both directions) against ours (Part 13 Total 163.96, TimeAverage 10.93), the frozen 1.5.378.182 calculators (188.96, 9.448), SDK 2.0.1's stock calculators (188.96, 9.448) and a Good-first control (all 163.96); LiveAggregateLateStartFactsTests pins the same through the booted server's runtime AggregateManager (live AggregateFilter) incl. DurationGood 15000 / PercentGood 75 there vs 8000 / 40 in HistoryRead (#809). QualityMix adds the reverse late-start variant (reverse TW pin + reverse oracle windows). Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
2.9 KiB
C#
55 lines
2.9 KiB
C#
using System.Collections.Frozen;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Sql.Common;
|
|
|
|
/// <summary>The query shape that serves an aggregate. One query per family.</summary>
|
|
public enum AggregateFamily
|
|
{
|
|
/// <summary>Average / Minimum / Maximum / Count / Range: one GROUP BY.</summary>
|
|
Simple,
|
|
|
|
/// <summary>Start / End / Delta: first + last usable sample per bucket.</summary>
|
|
StartEnd,
|
|
|
|
/// <summary>MinimumActualTime / MaximumActualTime: extreme usable sample per bucket, ties ⇒ earliest.</summary>
|
|
ActualTime,
|
|
|
|
/// <summary>
|
|
/// TimeAverage / TimeAverage2 / Total / Total2 / Interpolative, and the duration-based DurationGood / DurationBad /
|
|
/// PercentGood / PercentBad:
|
|
/// Part 13 time-weighted, with bounding values.
|
|
/// The backend streams the window's samples plus the bounding rows and <see cref="TimeWeightedAggregator"/>
|
|
/// evaluates them (identically for every backend).
|
|
/// </summary>
|
|
TimeWeighted,
|
|
}
|
|
|
|
/// <summary>Which aggregates the SQL historian backends serve, and by which family.</summary>
|
|
public static class AggregateFamilies
|
|
{
|
|
/// <summary>The family that serves <paramref name="aggregate"/>, or null when the backends do not.</summary>
|
|
/// <param name="aggregate">Requested aggregate.</param>
|
|
/// <returns>The family, or null for an unsupported aggregate.</returns>
|
|
public static AggregateFamily? FamilyOf(HistoryAggregateType aggregate) => aggregate switch
|
|
{
|
|
HistoryAggregateType.Average or HistoryAggregateType.Minimum or HistoryAggregateType.Maximum
|
|
or HistoryAggregateType.Count or HistoryAggregateType.Range => AggregateFamily.Simple,
|
|
HistoryAggregateType.Start or HistoryAggregateType.End or HistoryAggregateType.Delta => AggregateFamily.StartEnd,
|
|
HistoryAggregateType.MinimumActualTime or HistoryAggregateType.MaximumActualTime => AggregateFamily.ActualTime,
|
|
HistoryAggregateType.TimeAverage or HistoryAggregateType.TimeAverage2 or HistoryAggregateType.Total
|
|
or HistoryAggregateType.Total2 or HistoryAggregateType.Interpolative
|
|
or HistoryAggregateType.PercentGood or HistoryAggregateType.PercentBad
|
|
or HistoryAggregateType.DurationGood or HistoryAggregateType.DurationBad => AggregateFamily.TimeWeighted,
|
|
_ => null,
|
|
};
|
|
|
|
/// <summary>
|
|
/// The nineteen aggregates the SQL backends serve — every member <see cref="FamilyOf"/> assigns a family, derived
|
|
/// from it so the set and the dispatch can never disagree. Both <c>SqlServerHistorianDataSource</c> and
|
|
/// <c>QuestDbHistorianDataSource</c> return it as <see cref="IHistorianDataSource.SupportedAggregates"/>.
|
|
/// </summary>
|
|
public static readonly IReadOnlySet<HistoryAggregateType> Served =
|
|
Enum.GetValues<HistoryAggregateType>().Where(a => FamilyOf(a) is not null).ToFrozenSet();
|
|
}
|