Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}, function (err, result) {
process.stdout.write(' DONE!\n\n');
if (err) {
console.log(err);
process.exit(1);
}
console.log('Response Times:');
console.log('Min: ' + Math.floor(ss.min(result)) + 'ms');
console.log('Max: ' + Math.floor(ss.max(result)) + 'ms');
console.log('95th: ' + Math.floor(ss.quantile(result, 0.95)) + 'ms');
console.log('Std Dev: ' + Math.floor(ss.standardDeviation(result)) + 'ms');
console.log('\nRedis Cache:');
redisStats(api);
console.log('\nUser Cache:');
userStats(api);
process.exit(0); // TODO shutdown cleanly
api.client._client.shutdown();
});
}
function calculateStdDevIntervals (values, classification) {
if (!classification.stddev_intv) throw new Error('must supply a standard deviation interval')
const intv = classification.stddev_intv
if (intv !== 0.25 && intv !== 0.33 && intv !== 0.5 && intv !== 1) throw new Error('Unacceptable interval value: ' + intv)
const mean = ss.mean(values)
const stddev = ss.standardDeviation(values)
const breakCount = classification.breakCount
const intervals = []
// create interval around mean
const minMeanInt = Number((mean - (0.5 * stddev)).toFixed(6))
const maxMeanInt = Number((mean + (0.5 * stddev)).toFixed(6))
intervals.unshift(minMeanInt)
intervals.push(maxMeanInt)
// create positive & negative stddev intervals
let maxPosStd, minNegStd
for (let i = 1; i <= breakCount; i++) {
minNegStd = Number((minMeanInt - (i * stddev)).toFixed(6))
maxPosStd = Number((maxMeanInt + (i * stddev)).toFixed(6))
intervals.unshift(minNegStd)
intervals.push(maxPosStd)
callback(row) {
row.year = parseInt(row.year, 10);
return row;
},
});
const years = dv.getColumn('year');
expect(dv.max('year')).to.equal(max(years));
expect(dv.min('year')).to.equal(min(years));
expect(dv.mean('year')).to.equal(mean(years));
expect(dv.average('year')).to.equal(mean(years));
expect(dv.median('year')).to.equal(median(years));
expect(dv.mode('year')).to.equal(mode(years));
expect(dv.quantile('year', 0.5)).to.equal(quantile(years, 0.5));
expect(dv.quantiles('year', [0, 0.1, 0.5])).to.eql(map([0, 0.1, 0.5], (p) => quantile(years, p)));
expect(dv.quantilesByFraction('year', 4)).to.eql(map([0, 0.25, 0.5, 0.75, 1], (p) => quantile(years, p)));
expect(dv.standardDeviation('year')).to.equal(standardDeviation(years));
expect(dv.sum('year')).to.equal(sum(years));
expect(dv.variance('year')).to.equal(variance(years));
expect(dv.range('year')).to.eql([min(years), max(years)]);
});
data.push({
a: [i, i + 10, [-i, i * i, [-i * i, 1 / i]]],
});
}
const dv = new DataSet.View().source(data);
const values = flattenDeep(dv.getColumn('a'));
expect(dv.max('a')).to.equal(max(values));
expect(dv.min('a')).to.equal(min(values));
expect(dv.mean('a')).to.equal(mean(values));
expect(dv.average('a')).to.equal(mean(values));
expect(dv.median('a')).to.equal(median(values));
expect(dv.mode('a')).to.equal(mode(values));
expect(dv.quantile('a', 0.5)).to.equal(quantile(values, 0.5));
expect(dv.quantiles('a', [0, 0.1, 0.5])).to.eql(map([0, 0.1, 0.5], (p) => quantile(values, p)));
expect(dv.quantilesByFraction('a', 4)).to.eql(map([0, 0.25, 0.5, 0.75, 1], (p) => quantile(values, p)));
expect(dv.standardDeviation('a')).to.equal(standardDeviation(values));
expect(dv.sum('a')).to.equal(sum(values));
expect(dv.variance('a')).to.equal(variance(values));
expect(dv.range('a')).to.eql([min(values), max(values)]);
});
});
`${getChannelsByTopicCount +
getTransactionsByChannelIdCount +
persistTransactionCount} requests`,
);
console.log(`${getChannelsByTopicCount} getChannelsByTopic requests`);
console.log(`${getTransactionsByChannelIdCount} getTransactionsByChannelId requests`);
console.log(`${persistTransactionCount} persistTransaction requests`);
if (getChannelsByTopicCount > 0) {
console.log(`\ngetChannelsByTopic statistics`);
console.log(`average: ${simpleStatistics.mean(getChannelsByTopicTimes)}`);
console.log(`median: ${simpleStatistics.median(getChannelsByTopicTimes)}`);
console.log(`min: ${simpleStatistics.min(getChannelsByTopicTimes)}`);
console.log(`max: ${simpleStatistics.max(getChannelsByTopicTimes)}`);
console.log(
`standard deviation: ${simpleStatistics.standardDeviation(getChannelsByTopicTimes)}`,
);
}
if (getTransactionsByChannelIdCount > 0) {
console.log(`\ngetTransactionsByChannelId statistics`);
console.log(`average: ${simpleStatistics.mean(getTransactionsByChannelIdTimes)}`);
console.log(`median: ${simpleStatistics.median(getTransactionsByChannelIdTimes)}`);
console.log(`min: ${simpleStatistics.min(getTransactionsByChannelIdTimes)}`);
console.log(`max: ${simpleStatistics.max(getTransactionsByChannelIdTimes)}`);
console.log(
`standard deviation: ${simpleStatistics.standardDeviation(getTransactionsByChannelIdTimes)}`,
);
}
if (persistTransactionCount > 0) {
console.log(`\npersistTransaction statistics`);
console.log(`average: ${simpleStatistics.mean(persistTransactionTimes)}`);
console.log(`median: ${simpleStatistics.median(persistTransactionTimes)}`);
console.log(`average: ${simpleStatistics.mean(getTransactionsByChannelIdTimes)}`);
console.log(`median: ${simpleStatistics.median(getTransactionsByChannelIdTimes)}`);
console.log(`min: ${simpleStatistics.min(getTransactionsByChannelIdTimes)}`);
console.log(`max: ${simpleStatistics.max(getTransactionsByChannelIdTimes)}`);
console.log(
`standard deviation: ${simpleStatistics.standardDeviation(getTransactionsByChannelIdTimes)}`,
);
}
if (persistTransactionCount > 0) {
console.log(`\npersistTransaction statistics`);
console.log(`average: ${simpleStatistics.mean(persistTransactionTimes)}`);
console.log(`median: ${simpleStatistics.median(persistTransactionTimes)}`);
console.log(`min: ${simpleStatistics.min(persistTransactionTimes)}`);
console.log(`max: ${simpleStatistics.max(persistTransactionTimes)}`);
console.log(
`standard deviation: ${simpleStatistics.standardDeviation(persistTransactionTimes)}`,
);
}
});
releases.forEach((release) => {
release.hours = sumBy(release.builds, 'hours');
const rates = release.builds
.map(({ rate }) => rate)
.filter(rate => rate > 0);
const contentRates = release.builds
.map(({ contentRate }) => contentRate)
.filter(contentRate => contentRate > 0);
if (rates.length > 0) {
release.rate = geometricMean(rates) || 0;
release.contentRate = geometricMean(contentRates) || 0;
release.variance = standardDeviation(rates) || 0;
}
});
ctx.body = releases;
export function marginOfError(samples: Array): number {
const toPercent = 100;
const confidenceLevel = 0.95;
const sampleMean = mean(samples);
const standardError = standardDeviation(samples) / Math.sqrt(samples.length);
const degreesOfFreedom = samples.length - 1;
const interval = confidenceIntervalForT(
sampleMean,
standardError,
degreesOfFreedom,
confidenceLevel
);
return (((interval[1] - sampleMean) / sampleMean) * toPercent) || 0;
}
nrd(x) {
let s = standardDeviation(x);
const iqr = interquartileRange(x);
if (typeof iqr === 'number') {
s = Math.min(s, iqr / 1.34);
}
return 1.06 * s * Math.pow(x.length, -0.2);
}
};