README.md: spell fix
[e-mobility-charging-stations-simulator.git] / src / utils / PerformanceStatistics.ts
index d7a4388edf3f95c7d6776c193e980064ba3c7e9d..0c68fa73027b1169886394abc191a7fc2e73723f 100644 (file)
@@ -1,7 +1,7 @@
+import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from './CircularArray';
 import CommandStatistics, { CommandStatisticsData, PerfEntry } from '../types/CommandStatistics';
 import { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests';
 
-import CircularArray from './CircularArray';
 import Configuration from './Configuration';
 import { MessageType } from '../types/ocpp/MessageType';
 import { PerformanceEntry } from 'perf_hooks';
@@ -59,11 +59,12 @@ export default class PerformanceStatistics {
 
   public logPerformance(entry: PerformanceEntry, className: string): void {
     this.addPerformanceTimer(entry.name as RequestCommand | IncomingRequestCommand, entry.duration);
-    const perfEntry: PerfEntry = {} as PerfEntry;
-    perfEntry.name = entry.name;
-    perfEntry.entryType = entry.entryType;
-    perfEntry.startTime = entry.startTime;
-    perfEntry.duration = entry.duration;
+    const perfEntry: PerfEntry = {
+      name: entry.name,
+      entryType: entry.entryType,
+      startTime: entry.startTime,
+      duration: entry.duration
+    } ;
     logger.info(`${this.logPrefix()} ${className} method(s) entry: %j`, perfEntry);
   }
 
@@ -112,13 +113,13 @@ export default class PerformanceStatistics {
 
   private addPerformanceTimer(command: RequestCommand | IncomingRequestCommand, duration: number): void {
     // Map to proper command name
-    const MAPCOMMAND = {
-      sendMeterValues: 'MeterValues',
-      startTransaction: 'StartTransaction',
-      stopTransaction: 'StopTransaction',
+    const MAP_COMMAND = {
+      sendMeterValues: RequestCommand.METER_VALUES,
+      startTransaction: RequestCommand.START_TRANSACTION,
+      stopTransaction: RequestCommand.STOP_TRANSACTION,
     };
-    if (MAPCOMMAND[command]) {
-      command = MAPCOMMAND[command] as RequestCommand | IncomingRequestCommand;
+    if (MAP_COMMAND[command]) {
+      command = MAP_COMMAND[command] as RequestCommand | IncomingRequestCommand;
     }
     // Initialize command statistics
     if (!this.commandsStatistics.commandsStatisticsData[command]) {
@@ -131,7 +132,7 @@ export default class PerformanceStatistics {
     this.commandsStatistics.commandsStatisticsData[command].maxTimeMeasurement = this.commandsStatistics.commandsStatisticsData[command].maxTimeMeasurement ? (this.commandsStatistics.commandsStatisticsData[command].maxTimeMeasurement < duration ? duration : this.commandsStatistics.commandsStatisticsData[command].maxTimeMeasurement) : duration;
     this.commandsStatistics.commandsStatisticsData[command].totalTimeMeasurement = this.commandsStatistics.commandsStatisticsData[command].totalTimeMeasurement ? this.commandsStatistics.commandsStatisticsData[command].totalTimeMeasurement + duration : duration;
     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>;
+    Array.isArray(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries) ? this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries.push(duration) : this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries = new CircularArray<number>(DEFAULT_CIRCULAR_ARRAY_SIZE, duration);
     this.commandsStatistics.commandsStatisticsData[command].medTimeMeasurement = this.median(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries);
     this.commandsStatistics.commandsStatisticsData[command].stdDevTimeMeasurement = this.stdDeviation(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries);
   }