From f6778d744cf0bb0c9d352a7960b44c78d896f822 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 6 Jul 2023 01:25:41 +0200 Subject: [PATCH] refactor: cleanup performance statistics variables namespace MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/performance/PerformanceStatistics.ts | 18 +++++++++--------- src/types/Statistics.ts | 10 +++++----- src/types/index.ts | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 2733fd74..bd158ab8 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -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(Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY, { + ?.measurementTimeSeries?.push({ timestamp: entry.startTime, value: entry.duration }) + : (this.statistics.statisticsData.get(entryName).measurementTimeSeries = + new CircularArray(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): number[] { + private extractTimeSeriesValues(timeSeries: CircularArray): number[] { return timeSeries.map((timeSeriesItem) => timeSeriesItem.value); } diff --git a/src/types/Statistics.ts b/src/types/Statistics.ts index 59d13108..ab2e826a 100644 --- a/src/types/Statistics.ts +++ b/src/types/Statistics.ts @@ -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; + measurementTimeSeries: CircularArray; 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>; + statisticsData: Map; } & WorkerData; diff --git a/src/types/index.ts b/src/types/index.ts index f9a42d4a..05828944 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -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, -- 2.34.1