From: Jérôme Benoit Date: Fri, 7 Jul 2023 21:04:07 +0000 (+0200) Subject: refactor: factor out extractTimeSeriesValues() helper X-Git-Tag: v1.2.18~66 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=da55bd34b987cea87c4fd1e508f3a24cee6f5418;p=e-mobility-charging-stations-simulator.git refactor: factor out extractTimeSeriesValues() helper Signed-off-by: Jérôme Benoit --- diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index bd158ab8..b4dc6012 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -17,6 +17,7 @@ import { Constants, JSONStringifyWithMapSupport, buildPerformanceStatisticsMessage, + extractTimeSeriesValues, formatDurationSeconds, generateUUID, logPrefix, @@ -230,31 +231,23 @@ export class PerformanceStatistics { value: entry.duration, })); this.statistics.statisticsData.get(entryName).medTimeMeasurement = median( - this.extractTimeSeriesValues( - this.statistics.statisticsData.get(entryName).measurementTimeSeries - ) + extractTimeSeriesValues(this.statistics.statisticsData.get(entryName).measurementTimeSeries) ); this.statistics.statisticsData.get(entryName).ninetyFiveThPercentileTimeMeasurement = nthPercentile( - this.extractTimeSeriesValues( + extractTimeSeriesValues( this.statistics.statisticsData.get(entryName).measurementTimeSeries ), 95 ); this.statistics.statisticsData.get(entryName).stdDevTimeMeasurement = stdDeviation( - this.extractTimeSeriesValues( - this.statistics.statisticsData.get(entryName).measurementTimeSeries - ) + extractTimeSeriesValues(this.statistics.statisticsData.get(entryName).measurementTimeSeries) ); if (Configuration.getPerformanceStorage().enabled) { parentPort?.postMessage(buildPerformanceStatisticsMessage(this.statistics)); } } - private extractTimeSeriesValues(timeSeries: CircularArray): number[] { - return timeSeries.map((timeSeriesItem) => timeSeriesItem.value); - } - private logPrefix = (): string => { return logPrefix(` ${this.objName} | Performance statistics`); }; diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index f15224a8..b253bfa2 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -4,7 +4,7 @@ import { inspect } from 'node:util'; import clone from 'just-clone'; import { Constants } from './Constants'; -import { WebSocketCloseEventStatusString } from '../types'; +import { type TimestampedData, WebSocketCloseEventStatusString } from '../types'; export const logPrefix = (prefixString = ''): string => { return `${new Date().toLocaleString()}${prefixString}`; @@ -173,6 +173,10 @@ export const getRandomFloatFluctuatedRounded = ( ); }; +export const extractTimeSeriesValues = (timeSeries: Array): number[] => { + return timeSeries.map((timeSeriesItem) => timeSeriesItem.value); +}; + export const isObject = (item: unknown): boolean => { return ( isNullOrUndefined(item) === false && typeof item === 'object' && Array.isArray(item) === false diff --git a/src/utils/index.ts b/src/utils/index.ts index 93eae31e..4d5a38ac 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -31,6 +31,7 @@ export { convertToFloat, convertToInt, exponentialDelay, + extractTimeSeriesValues, formatDurationMilliSeconds, formatDurationSeconds, generateUUID,