From: Jérôme Benoit Date: Sat, 6 May 2023 17:55:36 +0000 (+0200) Subject: fix: fix median and percentile calculation X-Git-Tag: v1.2.12~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=6a349d8417f160c06ede76a0f36c4dbe60a585bd;p=e-mobility-charging-stations-simulator.git fix: fix median and percentile calculation Signed-off-by: Jérôme Benoit --- diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index a4dfd0b3..ecd6b3ab 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -191,7 +191,7 @@ export class PerformanceStatistics { const sortedDataSet = dataSet.slice().sort((a, b) => a - b); const middleIndex = Math.floor(sortedDataSet.length / 2); if (sortedDataSet.length % 2 === 0) { - return sortedDataSet[middleIndex / 2]; + return sortedDataSet[middleIndex]; } return (sortedDataSet[middleIndex - 1] + sortedDataSet[middleIndex]) / 2; } @@ -215,7 +215,7 @@ export class PerformanceStatistics { if (Number.isInteger(percentileIndex)) { return (sortedDataSet[percentileIndex] + sortedDataSet[percentileIndex + 1]) / 2; } - return sortedDataSet[Math.round(percentileIndex)]; + return sortedDataSet[Math.floor(percentileIndex)]; } private stdDeviation(dataSet: number[]): number {