Update submodule
[e-mobility-charging-stations-simulator.git] / src / utils / Statistics.ts
index 3fa4c78321ddafe219ba750aa11b78c971f83b63..a7dfaaa7e4e2e0cd612bd643a3d7101345564a2e 100644 (file)
@@ -1,5 +1,6 @@
 import CommandStatistics, { CommandStatisticsData, PerfEntry } from '../types/CommandStatistics';
 
+import CircularArray from './CircularArray';
 import Configuration from './Configuration';
 import Constants from './Constants';
 import { PerformanceEntry } from 'perf_hooks';
@@ -73,14 +74,18 @@ export default class Statistics {
     perfEntry.entryType = entry.entryType;
     perfEntry.startTime = entry.startTime;
     perfEntry.duration = entry.duration;
-    logger.info(`${this._logPrefix()} object ${className} method performance entry: %j`, perfEntry);
+    logger.info(`${this._logPrefix()} object ${className} method(s) performance entry: %j`, perfEntry);
   }
 
-  _display(): void {
+  start(): void {
+    this._displayInterval();
+  }
+
+  private _display(): void {
     logger.info(this._logPrefix() + ' %j', this._commandsStatistics);
   }
 
-  _displayInterval(): void {
+  private _displayInterval(): void {
     if (Configuration.getStatisticsDisplayInterval() > 0) {
       setInterval(() => {
         this._display();
@@ -89,10 +94,6 @@ export default class Statistics {
     }
   }
 
-  start(): void {
-    this._displayInterval();
-  }
-
   private median(dataSet: number[]): number {
     if (Array.isArray(dataSet) && dataSet.length === 1) {
       return dataSet[0];
@@ -126,7 +127,7 @@ export default class Statistics {
     this._commandsStatistics[command].maxTimeMeasurement = this._commandsStatistics[command].maxTimeMeasurement ? (this._commandsStatistics[command].maxTimeMeasurement < duration ? duration : this._commandsStatistics[command].maxTimeMeasurement) : duration;
     this._commandsStatistics[command].totalTimeMeasurement = this._commandsStatistics[command].totalTimeMeasurement ? this._commandsStatistics[command].totalTimeMeasurement + duration : duration;
     this._commandsStatistics[command].avgTimeMeasurement = this._commandsStatistics[command].totalTimeMeasurement / this._commandsStatistics[command].countTimeMeasurement;
-    Array.isArray(this._commandsStatistics[command].timeMeasurementSeries) ? this._commandsStatistics[command].timeMeasurementSeries.push(duration) : this._commandsStatistics[command].timeMeasurementSeries = [duration];
+    Array.isArray(this._commandsStatistics[command].timeMeasurementSeries) ? this._commandsStatistics[command].timeMeasurementSeries.push(duration) : this._commandsStatistics[command].timeMeasurementSeries = [duration] as CircularArray<number>;
     this._commandsStatistics[command].medTimeMeasurement = this.median(this._commandsStatistics[command].timeMeasurementSeries);
   }