From: Jérôme Benoit Date: Sun, 2 May 2021 16:26:09 +0000 (+0200) Subject: Add standard deviation computation to time statistics X-Git-Tag: v1.0.1-0~45 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aeada1fa7a7ab2d443cb1af7585a4ec506bad6bd;p=e-mobility-charging-stations-simulator.git Add standard deviation computation to time statistics Signed-off-by: Jérôme Benoit --- diff --git a/src/types/CommandStatistics.ts b/src/types/CommandStatistics.ts index 84f2bdca..e4804f8a 100644 --- a/src/types/CommandStatistics.ts +++ b/src/types/CommandStatistics.ts @@ -20,6 +20,7 @@ export interface CommandStatisticsData { totalTimeMeasurement: number; avgTimeMeasurement: number; medTimeMeasurement: number; + stdDevTimeMeasurement: number; } export default interface CommandStatistics { diff --git a/src/utils/Statistics.ts b/src/utils/Statistics.ts index d194451a..65e3be5b 100644 --- a/src/utils/Statistics.ts +++ b/src/utils/Statistics.ts @@ -96,6 +96,20 @@ export default class Statistics { return (sortedDataSet[(middleIndex - 1)] + sortedDataSet[middleIndex]) / 2; } + private stdDeviation(dataSet: number[]): number { + let totalDataSet = 0; + for (const data of dataSet) { + totalDataSet += data; + } + const dataSetMean = totalDataSet / dataSet.length; + let totalGeometricDeviation = 0; + for (const data of dataSet) { + const deviation = data - dataSetMean; + totalGeometricDeviation += deviation * deviation; + } + return Math.sqrt(totalGeometricDeviation / dataSet.length); + } + private addPerformanceTimer(command: RequestCommand | IncomingRequestCommand, duration: number): void { // Map to proper command name const MAPCOMMAND = { @@ -119,6 +133,7 @@ export default class Statistics { this.commandsStatistics.commandsStatisticsData[command].avgTimeMeasurement = this.commandsStatistics.commandsStatisticsData[command].totalTimeMeasurement / this.commandsStatistics.commandsStatisticsData[command].countTimeMeasurement; Array.isArray(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries) ? this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries.push(duration) : this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries = [duration] as CircularArray; this.commandsStatistics.commandsStatisticsData[command].medTimeMeasurement = this.median(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries); + this.commandsStatistics.commandsStatisticsData[command].stdDevTimeMeasurement = this.stdDeviation(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries); } private logPrefix(): string {