module import { UAVariable } from "node-opcua-address-space" ; import { DataValue } from "node-opcua-data-value" ; import { StatusCode , StatusCodes } from "node-opcua-status-code" ; import { Variant } from "node-opcua-variant" ; import { getAggregateData } from "./common" ; import { AggregateConfigurationOptions , Interval , isGood } from "./interval" ; function calculateIntervalMinOrMaxValue ( interval , options , predicate ) { const indexStart = interval . index ; let selectedValue = null ; let counter = 0 ; let statusCode ; let isPartial = interval . isPartial ; let isRaw = false ; let hasBad = false ; for ( let i = indexStart ; i < indexStart + interval . count ; i ++ ) { const dataValue = interval . dataValues [ i ] ; if ( dataValue . statusCode === StatusCodes . BadNoData ) { isPartial = true ; continue ; } if ( ! isGood ( dataValue . statusCode ) ) { hasBad = true ; continue ; } if ( ! selectedValue ) { selectedValue = dataValue . value ; counter = 1 ; if ( i === indexStart && dataValue . sourceTimestamp ! . getTime ( ) === interval . startTime . getTime ( ) ) { isRaw = true ; } continue ; } const compare = predicate ( selectedValue , dataValue . value ) ; if ( compare === "equal" ) { counter = 1 ; continue ; } if ( compare === "select" ) { selectedValue = dataValue . value ; counter = 1 ; } } if ( ! selectedValue ) { return new DataValue ( { sourceTimestamp : interval . startTime , statusCode : StatusCodes . BadNoData } ) ; } if ( isRaw ) { if ( hasBad ) { statusCode = StatusCodes . UncertainDataSubNormal ; } else { statusCode = StatusCodes . Good ; } } else if ( hasBad ) { statusCode = StatusCode . makeStatusCode ( StatusCodes . UncertainDataSubNormal , "HistorianCalculated" ) ; } else { statusCode = StatusCode . makeStatusCode ( StatusCodes . Good , "HistorianCalculated" ) ; } if ( counter > 1 ) { statusCode = StatusCode . makeStatusCode ( statusCode , "HistorianMultiValue" ) ; } if ( isPartial || interval . isPartial ) { statusCode = StatusCode . makeStatusCode ( statusCode , "HistorianPartial" ) ; } return new DataValue ( { sourceTimestamp : interval . startTime , statusCode : statusCode as StatusCode , value : selectedValue ! } ) ; } export function calculateIntervalMinValue ( interval , options ) { return calculateIntervalMinOrMaxValue ( interval , options , ( a , b ) => a . value > b . value ? "select" : a . value === b . value ? "equal" : "reject" ) ; } export function calculateIntervalMaxValue ( interval , options ) { return calculateIntervalMinOrMaxValue ( interval , options , ( a , b ) => a . value < b . value ? "select" : a . value === b . value ? "equal" : "reject" ) ; } param node param processingInterval param startDate param endDate param callback export function getMinData ( node , processingInterval , startDate , endDate , callback ) { return getAggregateData ( node , processingInterval , startDate , endDate , calculateIntervalMinValue , callback ) ; } export function getMaxData ( node , processingInterval , startDate , endDate , callback ) { return getAggregateData ( node , processingInterval , startDate , endDate , calculateIntervalMaxValue , callback ) ; }