Add logs rotation.
[e-mobility-charging-stations-simulator.git] / src / utils / Statistics.ts
index f2bfee4ffc53208a9cf531ab7bb3be892403b01b..0f0674d1a08240e0343d57ea74c848957ea79882 100644 (file)
@@ -67,28 +67,6 @@ export default class Statistics {
     }
   }
 
-  addPerformanceTimer(command: string, duration: number): void {
-    // Map to proper command name
-    const MAPCOMMAND = {
-      sendMeterValues: 'MeterValues',
-      startTransaction: 'StartTransaction',
-      stopTransaction: 'StopTransaction',
-    };
-    if (MAPCOMMAND[command]) {
-      command = MAPCOMMAND[command] as string;
-    }
-    // Initialize command statistics
-    if (!this._commandsStatistics[command]) {
-      this._commandsStatistics[command] = {} as CommandStatisticsData;
-    }
-    // Update current statistics timers
-    this._commandsStatistics[command].countTime = this._commandsStatistics[command].countTime ? this._commandsStatistics[command].countTime + 1 : 1;
-    this._commandsStatistics[command].minTime = this._commandsStatistics[command].minTime ? (this._commandsStatistics[command].minTime > duration ? duration : this._commandsStatistics[command].minTime) : duration;
-    this._commandsStatistics[command].maxTime = this._commandsStatistics[command].maxTime ? (this._commandsStatistics[command].maxTime < duration ? duration : this._commandsStatistics[command].maxTime) : duration;
-    this._commandsStatistics[command].totalTime = this._commandsStatistics[command].totalTime ? this._commandsStatistics[command].totalTime + duration : duration;
-    this._commandsStatistics[command].avgTime = this._commandsStatistics[command].totalTime / this._commandsStatistics[command].countTime;
-  }
-
   logPerformance(entry: PerformanceEntry, className: string): void {
     this.addPerformanceTimer(entry.name, entry.duration);
     logger.info(`${this._logPrefix()} class->${className}, method->${entry.name}, duration->${entry.duration}`);
@@ -103,7 +81,7 @@ export default class Statistics {
       setInterval(() => {
         this._display();
       }, Configuration.getStatisticsDisplayInterval() * 1000);
-      logger.info(this._logPrefix() + ' displayed every ' + Configuration.getStatisticsDisplayInterval().toString() + 's');
+      logger.info(this._logPrefix() + ' displayed every ' + Utils.secondsToHHMMSS(Configuration.getStatisticsDisplayInterval()));
     }
   }
 
@@ -111,6 +89,28 @@ export default class Statistics {
     this._displayInterval();
   }
 
+  private addPerformanceTimer(command: string, duration: number): void {
+    // Map to proper command name
+    const MAPCOMMAND = {
+      sendMeterValues: 'MeterValues',
+      startTransaction: 'StartTransaction',
+      stopTransaction: 'StopTransaction',
+    };
+    if (MAPCOMMAND[command]) {
+      command = MAPCOMMAND[command] as string;
+    }
+    // Initialize command statistics
+    if (!this._commandsStatistics[command]) {
+      this._commandsStatistics[command] = {} as CommandStatisticsData;
+    }
+    // Update current statistics timers
+    this._commandsStatistics[command].countTime = this._commandsStatistics[command].countTime ? this._commandsStatistics[command].countTime + 1 : 1;
+    this._commandsStatistics[command].minTime = this._commandsStatistics[command].minTime ? (this._commandsStatistics[command].minTime > duration ? duration : this._commandsStatistics[command].minTime) : duration;
+    this._commandsStatistics[command].maxTime = this._commandsStatistics[command].maxTime ? (this._commandsStatistics[command].maxTime < duration ? duration : this._commandsStatistics[command].maxTime) : duration;
+    this._commandsStatistics[command].totalTime = this._commandsStatistics[command].totalTime ? this._commandsStatistics[command].totalTime + duration : duration;
+    this._commandsStatistics[command].avgTime = this._commandsStatistics[command].totalTime / this._commandsStatistics[command].countTime;
+  }
+
   private _logPrefix(): string {
     return Utils.logPrefix(` ${this._objName} Statistics:`);
   }