refactor: use ramdba helper for builtin types
[e-mobility-charging-stations-simulator.git] / src / performance / PerformanceStatistics.ts
index bf333dfd4c9c1449334bd979933b7d868d0e0c02..265cb6c963918b1a3970a95e5822742f3202c0d4 100644 (file)
@@ -5,12 +5,14 @@ import type { URL } from 'node:url'
 import { parentPort } from 'node:worker_threads'
 
 import { secondsToMilliseconds } from 'date-fns'
+import { is, mean, median } from 'rambda'
 
 import { BaseError } from '../exception/index.js'
 import {
   ConfigurationSection,
   type IncomingRequestCommand,
   type LogConfiguration,
+  MapStringifyFormat,
   MessageType,
   type RequestCommand,
   type Statistics,
@@ -19,7 +21,6 @@ import {
   type TimestampedData
 } from '../types/index.js'
 import {
-  average,
   buildPerformanceStatisticsMessage,
   CircularArray,
   Configuration,
@@ -27,11 +28,10 @@ import {
   extractTimeSeriesValues,
   formatDurationSeconds,
   generateUUID,
-  JSONStringifyWithMapSupport,
+  JSONStringify,
   logger,
   logPrefix,
   max,
-  median,
   min,
   nthPercentile,
   stdDeviation
@@ -107,7 +107,7 @@ export class PerformanceStatistics {
     try {
       performance.measure(name, markId)
     } catch (error) {
-      if (error instanceof Error && error.message.includes('performance mark has not been set')) {
+      if (is(Error, error) && error.message.includes('performance mark has not been set')) {
         /* Ignore */
       } else {
         throw error
@@ -214,7 +214,7 @@ export class PerformanceStatistics {
     logger.info(this.logPrefix(), {
       ...this.statistics,
       statisticsData: JSON.parse(
-        JSONStringifyWithMapSupport(this.statistics.statisticsData)
+        JSONStringify(this.statistics.statisticsData, undefined, MapStringifyFormat.object)
       ) as Map<string | RequestCommand | IncomingRequestCommand, StatisticsData>
     })
   }
@@ -292,8 +292,7 @@ export class PerformanceStatistics {
       this.statistics.statisticsData.get(entry.name)!.measurementTimeSeries!
     )
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    this.statistics.statisticsData.get(entry.name)!.avgTimeMeasurement =
-      average(timeMeasurementValues)
+    this.statistics.statisticsData.get(entry.name)!.avgTimeMeasurement = mean(timeMeasurementValues)
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     this.statistics.statisticsData.get(entry.name)!.medTimeMeasurement =
       median(timeMeasurementValues)