Strict null check fixes
[e-mobility-charging-stations-simulator.git] / src / performance / PerformanceStatistics.ts
index 49ebc79b30df23e6bea0c06818d3ad1481c0e6f7..6ac54aa42c451813f22c8d2cd1fe1d6e73979064 100644 (file)
@@ -21,9 +21,9 @@ export default class PerformanceStatistics {
 
   private readonly objId: string;
   private readonly objName: string;
-  private performanceObserver: PerformanceObserver;
+  private performanceObserver!: PerformanceObserver;
   private readonly statistics: Statistics;
-  private displayInterval: NodeJS.Timeout;
+  private displayInterval!: NodeJS.Timeout;
 
   private constructor(objId: string, objName: string, uri: URL) {
     this.objId = objId;
@@ -168,7 +168,7 @@ export default class PerformanceStatistics {
       );
     } else {
       logger.info(
-        `${this.logPrefix()} log interval is set to ${Configuration.getLogStatisticsInterval().toString()}. Not logging statistics`
+        `${this.logPrefix()} log interval is set to ${Configuration.getLogStatisticsInterval()?.toString()}. Not logging statistics`
       );
     }
   }
@@ -253,10 +253,10 @@ export default class PerformanceStatistics {
     this.statistics.statisticsData.get(entryName).avgTimeMeasurement =
       this.statistics.statisticsData.get(entryName).totalTimeMeasurement /
       this.statistics.statisticsData.get(entryName).countTimeMeasurement;
-    Array.isArray(this.statistics.statisticsData.get(entryName).timeMeasurementSeries) === true
+    Array.isArray(this.statistics.statisticsData.get(entryName)?.timeMeasurementSeries) === true
       ? this.statistics.statisticsData
           .get(entryName)
-          .timeMeasurementSeries.push({ timestamp: entry.startTime, value: entry.duration })
+          ?.timeMeasurementSeries?.push({ timestamp: entry.startTime, value: entry.duration })
       : (this.statistics.statisticsData.get(entryName).timeMeasurementSeries =
           new CircularArray<TimeSeries>(DEFAULT_CIRCULAR_ARRAY_SIZE, {
             timestamp: entry.startTime,
@@ -280,7 +280,7 @@ export default class PerformanceStatistics {
       )
     );
     if (Configuration.getPerformanceStorage().enabled) {
-      parentPort.postMessage(
+      parentPort?.postMessage(
         MessageChannelUtils.buildPerformanceStatisticsMessage(this.statistics)
       );
     }