Skip to content

Commit

Permalink
Fix statistics calculation edge cases (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 20, 2024
1 parent 48267bf commit acf12ca
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/hub/controllers/StatisticsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,22 @@ export default class StatisticsController implements TabController {
});

// Get statistics
let samplesNonNegative = samples.filter((x) => x >= 0);
let samplesPositive = samples.filter((x) => x > 0);
let statistics: StatisticsRendererCommand_Stats = {
count: samples.length,
min: samples.length === 0 ? NaN : stats.minSorted(samples),
max: samples.length === 0 ? NaN : stats.maxSorted(samples),
mean: samples.length === 0 ? NaN : stats.mean(samples),
median: samples.length === 0 ? NaN : stats.medianSorted(samples),
mode: samples.length === 0 ? NaN : stats.modeSorted(samples),
geometricMean: samples.length === 0 ? NaN : logAverage(samples.filter((x) => x >= 0)),
harmonicMean: samples.length === 0 ? NaN : stats.harmonicMean(samples.filter((x) => x > 0)),
geometricMean: samplesNonNegative.length === 0 ? NaN : logAverage(samplesNonNegative),
harmonicMean: samplesPositive.length === 0 ? NaN : stats.harmonicMean(samplesPositive),
quadraticMean: samples.length === 0 ? NaN : stats.rootMeanSquare(samples),
standardDeviation: samples.length === 0 ? NaN : stats.sampleStandardDeviation(samples),
standardDeviation: samples.length < 2 ? NaN : stats.sampleStandardDeviation(samples),
medianAbsoluteDeviation: samples.length === 0 ? NaN : stats.medianAbsoluteDeviation(samples),
interquartileRange: samples.length === 0 ? NaN : stats.interquartileRange(samples),
skewness: samples.length === 0 ? NaN : stats.sampleSkewness(samples),
skewness: samples.length < 3 ? NaN : stats.sampleSkewness(samples),
percentile01: samples.length === 0 ? NaN : stats.quantileSorted(samples, 0.01),
percentile05: samples.length === 0 ? NaN : stats.quantileSorted(samples, 0.05),
percentile10: samples.length === 0 ? NaN : stats.quantileSorted(samples, 0.1),
Expand Down

0 comments on commit acf12ca

Please sign in to comment.