refactor: cleanup performance statistics variables namespace
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 5 Jul 2023 23:25:41 +0000 (01:25 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 5 Jul 2023 23:25:41 +0000 (01:25 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/performance/PerformanceStatistics.ts
src/types/Statistics.ts
src/types/index.ts

index 2733fd7430140a16a95166f1c40efae7287dcc97..bd158ab80c8bcfe137d44ea213220a96dfec9077 100644 (file)
@@ -9,7 +9,7 @@ import {
   MessageType,
   type RequestCommand,
   type Statistics,
-  type TimeSeries,
+  type TimestampedData,
 } from '../types';
 import {
   CircularArray,
@@ -220,30 +220,30 @@ export class PerformanceStatistics {
     this.statistics.statisticsData.get(entryName).avgTimeMeasurement =
       this.statistics.statisticsData.get(entryName).totalTimeMeasurement /
       this.statistics.statisticsData.get(entryName).countTimeMeasurement;
-    this.statistics.statisticsData.get(entryName)?.timeMeasurementSeries instanceof CircularArray
+    this.statistics.statisticsData.get(entryName)?.measurementTimeSeries instanceof CircularArray
       ? this.statistics.statisticsData
           .get(entryName)
-          ?.timeMeasurementSeries?.push({ timestamp: entry.startTime, value: entry.duration })
-      : (this.statistics.statisticsData.get(entryName).timeMeasurementSeries =
-          new CircularArray<TimeSeries>(Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY, {
+          ?.measurementTimeSeries?.push({ timestamp: entry.startTime, value: entry.duration })
+      : (this.statistics.statisticsData.get(entryName).measurementTimeSeries =
+          new CircularArray<TimestampedData>(Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY, {
             timestamp: entry.startTime,
             value: entry.duration,
           }));
     this.statistics.statisticsData.get(entryName).medTimeMeasurement = median(
       this.extractTimeSeriesValues(
-        this.statistics.statisticsData.get(entryName).timeMeasurementSeries
+        this.statistics.statisticsData.get(entryName).measurementTimeSeries
       )
     );
     this.statistics.statisticsData.get(entryName).ninetyFiveThPercentileTimeMeasurement =
       nthPercentile(
         this.extractTimeSeriesValues(
-          this.statistics.statisticsData.get(entryName).timeMeasurementSeries
+          this.statistics.statisticsData.get(entryName).measurementTimeSeries
         ),
         95
       );
     this.statistics.statisticsData.get(entryName).stdDevTimeMeasurement = stdDeviation(
       this.extractTimeSeriesValues(
-        this.statistics.statisticsData.get(entryName).timeMeasurementSeries
+        this.statistics.statisticsData.get(entryName).measurementTimeSeries
       )
     );
     if (Configuration.getPerformanceStorage().enabled) {
@@ -251,7 +251,7 @@ export class PerformanceStatistics {
     }
   }
 
-  private extractTimeSeriesValues(timeSeries: CircularArray<TimeSeries>): number[] {
+  private extractTimeSeriesValues(timeSeries: CircularArray<TimestampedData>): number[] {
     return timeSeries.map((timeSeriesItem) => timeSeriesItem.value);
   }
 
index 59d13108d08e9425fc474e0aa4fd9b87c289e02f..ab2e826ae147039d96ae37b1ad5813ec589ddb89 100644 (file)
@@ -2,17 +2,17 @@ import type { IncomingRequestCommand, RequestCommand } from './ocpp/Requests';
 import type { CircularArray } from '../utils';
 import type { WorkerData } from '../worker';
 
-export type TimeSeries = {
+export type TimestampedData = {
   timestamp: number;
   value: number;
 };
 
-type StatisticsData = {
+type StatisticsData = Partial<{
   countRequest: number;
   countResponse: number;
   countError: number;
   countTimeMeasurement: number;
-  timeMeasurementSeries: CircularArray<TimeSeries>;
+  measurementTimeSeries: CircularArray<TimestampedData>;
   currentTimeMeasurement: number;
   minTimeMeasurement: number;
   maxTimeMeasurement: number;
@@ -21,7 +21,7 @@ type StatisticsData = {
   medTimeMeasurement: number;
   ninetyFiveThPercentileTimeMeasurement: number;
   stdDevTimeMeasurement: number;
-};
+}>;
 
 export type Statistics = {
   id: string;
@@ -29,5 +29,5 @@ export type Statistics = {
   uri: string;
   createdAt: Date;
   updatedAt?: Date;
-  statisticsData: Map<string | RequestCommand | IncomingRequestCommand, Partial<StatisticsData>>;
+  statisticsData: Map<string | RequestCommand | IncomingRequestCommand, StatisticsData>;
 } & WorkerData;
index f9a42d4aae07d4f9c5d18e9adf964cbc5431522e..05828944e90cd87b1517c78a1889c3195cfbdc8d 100644 (file)
@@ -249,7 +249,7 @@ export { OCPP20OptionalVariableName } from './ocpp/2.0/Variables';
 export { OCPPVersion } from './ocpp/OCPPVersion';
 export { PerformanceData } from './orm/entities/PerformanceData';
 export { PerformanceRecord } from './orm/entities/PerformanceRecord';
-export type { Statistics, TimeSeries } from './Statistics';
+export type { Statistics, TimestampedData } from './Statistics';
 export {
   type WSError,
   WebSocketCloseEventStatusCode,