refactor: factor out extractTimeSeriesValues() helper
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 7 Jul 2023 21:04:07 +0000 (23:04 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 7 Jul 2023 21:04:07 +0000 (23:04 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/performance/PerformanceStatistics.ts
src/utils/Utils.ts
src/utils/index.ts

index bd158ab80c8bcfe137d44ea213220a96dfec9077..b4dc60125c378e00031aca42a6a6fee4c9c8fedc 100644 (file)
@@ -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<TimestampedData>): number[] {
-    return timeSeries.map((timeSeriesItem) => timeSeriesItem.value);
-  }
-
   private logPrefix = (): string => {
     return logPrefix(` ${this.objName} | Performance statistics`);
   };
index f15224a855b7e08e53e75e4221bb1009a80f19cd..b253bfa222990656a565cbc744e6ac023a42e50c 100644 (file)
@@ -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<TimestampedData>): number[] => {
+  return timeSeries.map((timeSeriesItem) => timeSeriesItem.value);
+};
+
 export const isObject = (item: unknown): boolean => {
   return (
     isNullOrUndefined(item) === false && typeof item === 'object' && Array.isArray(item) === false
index 93eae31e58dea8f77ea542e2ce12fb1f0d81bb38..4d5a38acfe4c35ca977ab64b5139fd8602518028 100644 (file)
@@ -31,6 +31,7 @@ export {
   convertToFloat,
   convertToInt,
   exponentialDelay,
+  extractTimeSeriesValues,
   formatDurationMilliSeconds,
   formatDurationSeconds,
   generateUUID,