add sample size

This commit is contained in:
Scott Bell 2024-10-09 10:24:08 +02:00
parent 395436a361
commit 3f92deb896
3 changed files with 23 additions and 2 deletions

View File

@ -60,7 +60,8 @@ export default class CompsManager extends EventEmitter {
valueToUse,
testValue: 0,
timeMetaData,
accumulateValues: false
accumulateValues: false,
sampleSize: null
});
this.emit('parameterAdded', this.#domainObject);
}

View File

@ -83,6 +83,14 @@ function calculate(dataFrame, parameters, expression) {
accumulatedData[referenceParameter.name].push(referenceValue);
referenceValue = accumulatedData[referenceParameter.name];
}
if (referenceParameter.sampleSize) {
// 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 (referenceValue.length < referenceParameter.sampleSize) {
return;
}
referenceValue = referenceValue.slice(-referenceParameter.sampleSize);
}
const scope = {
[referenceParameter.name]: referenceValue

View File

@ -102,6 +102,7 @@
]"
>
<label v-if="isEditing" class="c-toggle-switch">
<span class="c-toggle-switch__label">Accumulate Values</span>
<input
v-model="parameter.accumulateValues"
type="checkbox"
@ -111,8 +112,19 @@
class="c-toggle-switch__slider"
aria-label="Toggle Parameter Accumulation"
></span>
<span class="c-toggle-switch__label">Accumulate Values</span>
</label>
<span v-if="isEditing && parameter.accumulateValues" class="c-test-datum__string"
>Sample Size</span
>
<input
v-if="isEditing && parameter.accumulateValues"
v-model="parameter.sampleSize"
:aria-label="`Sample Size for ${parameter.name}`"
type="text"
class="c-input--md"
@change="updateParameters"
/>
</div>
</span>