ensure we have a reference value before we slice

This commit is contained in:
Scott Bell 2024-10-09 12:16:02 +02:00
parent 8e7bfd080d
commit 2de628adac

View File

@ -13,6 +13,7 @@ onconnect = function (e) {
try { try {
if (type === 'calculateRequest') { if (type === 'calculateRequest') {
responseType = 'calculationRequestResult'; responseType = 'calculationRequestResult';
console.debug(`📫 Received new calculation request with callback ID ${callbackID}`);
result = calculateRequest(telemetryForComps, parameters, expression); result = calculateRequest(telemetryForComps, parameters, expression);
} else if (type === 'calculateSubscription') { } else if (type === 'calculateSubscription') {
responseType = 'calculationSubscriptionResult'; responseType = 'calculationSubscriptionResult';
@ -86,7 +87,7 @@ function calculate(dataFrame, parameters, expression) {
if (referenceParameter.sampleSize && referenceParameter.sampleSize > 0) { if (referenceParameter.sampleSize && referenceParameter.sampleSize > 0) {
// enforce sample size by ensuring referenceValue has the latest n elements // enforce sample size by ensuring referenceValue has the latest n elements
// if we don't have at least the sample size, skip this iteration // if we don't have at least the sample size, skip this iteration
if (referenceValue.length < referenceParameter.sampleSize) { if (!referenceValue.length || referenceValue.length < referenceParameter.sampleSize) {
return; return;
} }
referenceValue = referenceValue.slice(-referenceParameter.sampleSize); referenceValue = referenceValue.slice(-referenceParameter.sampleSize);