Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async handle(spreadStat) {
const newData = spreadStat.bestCase.profitPercentAgainstNotional;
// add new data to mean
this.profitPercentMean = ss.addToMean(this.profitPercentMean, this.sampleSize, newData);
// add new data to variance
this.profitPercentVariance = ss.combineVariances(
this.profitPercentVariance,
this.profitPercentMean,
this.sampleSize,
0,
newData,
1
);
this.sampleSize++;
// set μ + σ to minTargetProfitPercent
const n = this.sampleSize;
const mean = this.profitPercentMean;
const standardDeviation = Math.sqrt(this.profitPercentVariance * n/(n-1));
const meanStream = miss.through.obj((newValue, _, callback) => {
mean = stats.addToMean(mean, n++, newValue);
callback(null, mean);
});
inputs.$order[0].pipe(meanStream).pipe(outputs.$order[0]);
for (var k = 0; k < 7; k++) {
if (data.weekDays[k].length === 0) {
districtData.meanWeekDays[k] = 0;
}
else if (data.weekDays[k].length === 1) {
districtData.meanWeekDays[k] = data.weekDays[k][0];
}
else {
districtData.meanWeekDays[k] = ss.mean(data.weekDays[k]);
}
if (output.districts.length === 0) {
output.meanWeekDays[k] = districtData.meanWeekDays[k];
}
else {
output.meanWeekDays[k] = ss.addToMean(output.meanWeekDays[k],
output.districts.length,
districtData.meanWeekDays[k]);
}
}
districtData.meanDays = ss.mean(data.days);
output.districts.push(districtData);
callback();
}
);