From da55bd34b987cea87c4fd1e508f3a24cee6f5418 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 7 Jul 2023 23:04:07 +0200 Subject: [PATCH] refactor: factor out extractTimeSeriesValues() helper 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 | 15 ++++----------- src/utils/Utils.ts | 6 +++++- src/utils/index.ts | 1 + 3 files changed, 10 insertions(+), 12 deletions(-) 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, -- 2.34.1