Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function safeQuantile(values: number[], q: number | number[]): any {
// Handle cases when `values` is empty gracefully
if (values.length > 0) {
return quantile(values, q as any)
} else if (typeof q === 'number') {
return 0
} else {
return q.map(() => 0)
}
}
function printSummary (arr) {
console.log(`mean: ${ss.mean(arr)}`)
console.log(`min: ${ss.min(arr)}`)
console.log(`max: ${ss.max(arr)}`)
console.log(`---`)
console.log(`25%: ${ss.quantile(arr, 0.25)}`)
console.log(`50%: ${ss.quantile(arr, 0.50)}`)
console.log(`75%: ${ss.quantile(arr, 0.75)}`)
console.log(`90%: ${ss.quantile(arr, 0.9)}`)
}
function printSummary (arr) {
console.log(`mean: ${ss.mean(arr)}`)
console.log(`min: ${ss.min(arr)}`)
console.log(`max: ${ss.max(arr)}`)
console.log(`---`)
console.log(`25%: ${ss.quantile(arr, 0.25)}`)
console.log(`50%: ${ss.quantile(arr, 0.50)}`)
console.log(`75%: ${ss.quantile(arr, 0.75)}`)
console.log(`90%: ${ss.quantile(arr, 0.9)}`)
}
function printSummary (arr) {
console.log(`mean: ${ss.mean(arr)}`)
console.log(`min: ${ss.min(arr)}`)
console.log(`max: ${ss.max(arr)}`)
console.log(`---`)
console.log(`25%: ${ss.quantile(arr, 0.25)}`)
console.log(`50%: ${ss.quantile(arr, 0.50)}`)
console.log(`75%: ${ss.quantile(arr, 0.75)}`)
console.log(`90%: ${ss.quantile(arr, 0.9)}`)
}
console.table([ 0.05, 0.25, 0.5, 0.75, 0.95, 1 ].map(percentile => {
return {
'Percentile': percentile * 100,
'Time (ms)': Math.round(stats.quantile(waitingPrepTable, percentile))
}
}))
}
function printSummary (arr) {
console.log(`mean: ${ss.mean(arr)}`)
console.log(`min: ${ss.min(arr)}`)
console.log(`max: ${ss.max(arr)}`)
console.log(`---`)
console.log(`25%: ${ss.quantile(arr, 0.25)}`)
console.log(`50%: ${ss.quantile(arr, 0.50)}`)
console.log(`75%: ${ss.quantile(arr, 0.75)}`)
console.log(`90%: ${ss.quantile(arr, 0.9)}`)
}
console.table([ 0.05, 0.25, 0.5, 0.75, 0.95, 1 ].map(percentile => {
return {
'Percentile': percentile * 100,
'Time (ms)': Math.round(stats.quantile(allResponseTimes, percentile))
}
}))
const dv = new DataSet.View().source(populationChina);
dv.transform({
type: 'map',
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)]);
});
const quantiles = pArray.map((p) => quantile(binningColumn, p));
resultRow[as] = quantiles;