Add standard deviation computation to time statistics
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 May 2021 16:26:09 +0000 (18:26 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 May 2021 16:26:09 +0000 (18:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/types/CommandStatistics.ts
src/utils/Statistics.ts

index 84f2bdcae5634204f22e483f6ff4e1ffa9260a38..e4804f8a1fff05d6661920a563e19ddf46aa1216 100644 (file)
@@ -20,6 +20,7 @@ export interface CommandStatisticsData {
   totalTimeMeasurement: number;
   avgTimeMeasurement: number;
   medTimeMeasurement: number;
+  stdDevTimeMeasurement: number;
 }
 
 export default interface CommandStatistics {
index d194451a031e5b2a3078f2107f8211ffa8f76de9..65e3be5b516c747050e2a38156e01c7b5807343d 100644 (file)
@@ -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<number>;
     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 {