Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// find the first non-Bad Raw value before the timestamp;
// find previous good value
const before = interval.beforeStartDataValue(bTreatUncertainAsBad);
if (isBad(before.dataValue.statusCode)) {
return new DataValue({
sourceTimestamp: interval.startTime,
statusCode: StatusCodes.BadNoData
});
}
if (options.stepped) {
if (before.index + 1 === interval.index) {
return new DataValue({
sourceTimestamp: interval.startTime,
statusCode: StatusCode.makeStatusCode(before.dataValue.statusCode, "HistorianInterpolated"),
value: before.dataValue.value
});
}
return steppedValue(before.dataValue);
}
// find the first non-Bad Raw value after the timestamp;
const next = interval.nextStartDataValue(bTreatUncertainAsBad);
// draw a line between before value and after value;
// use point where the line crosses the timestamp as an estimate of the bounding value.
// The calculation can be expressed with the following formula:
// V bound = (T bound – T before)x( V after – V before)/( T after – T before) + V before
// where V
// x is a value at ‘x’ and Tx is the timestamp associated with Vx.
const interpolatedDataValue = interpolateValue(before.dataValue, next.dataValue, interval.startTime);
function setSemanticChangeBit(notification: any) {
if (notification && notification.hasOwnProperty("value")) {
notification.value.statusCode =
StatusCode.makeStatusCode(notification.value.statusCode, "SemanticChanged");
}
}
private _setOverflowBit(notification: any) {
if (notification.hasOwnProperty("value")) {
assert(notification.value.statusCode.equals(StatusCodes.Good));
notification.value.statusCode =
StatusCode.makeStatusCode(notification.value.statusCode, "Overflow | InfoTypeDataValue");
assert(_.isEqual(notification.value.statusCode, StatusCodes.GoodWithOverflowBit));
assert(notification.value.statusCode.hasOverflowBit);
}
if (this.$subscription && this.$subscription.subcriptionDiagnosticInfo) {
this.$subscription.subcriptionDiagnosticInfo.monitoringQueueOverflowCount++;
}
}
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!
});
}
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!
});
}
});
}
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!
});
}