Configuration,
Constants,
JSONStringifyWithMapSupport,
+ average,
buildPerformanceStatisticsMessage,
extractTimeSeriesValues,
formatDurationSeconds,
);
this.statistics.statisticsData.get(entryName)!.totalTimeMeasurement =
(this.statistics.statisticsData.get(entryName)?.totalTimeMeasurement ?? 0) + entry.duration;
- this.statistics.statisticsData.get(entryName)!.avgTimeMeasurement =
- this.statistics.statisticsData.get(entryName)!.totalTimeMeasurement! /
- this.statistics.statisticsData.get(entryName)!.timeMeasurementCount!;
this.statistics.statisticsData.get(entryName)?.measurementTimeSeries instanceof CircularArray
? this.statistics.statisticsData
.get(entryName)
timestamp: entry.startTime,
value: entry.duration,
}));
+ this.statistics.statisticsData.get(entryName)!.avgTimeMeasurement = average(
+ extractTimeSeriesValues(
+ this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!,
+ ),
+ );
this.statistics.statisticsData.get(entryName)!.medTimeMeasurement = median(
extractTimeSeriesValues(
- this.statistics.statisticsData.get(entryName)!.measurementTimeSeries as TimestampedData[],
+ this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!,
),
);
this.statistics.statisticsData.get(entryName)!.ninetyFiveThPercentileTimeMeasurement =
nthPercentile(
extractTimeSeriesValues(
- this.statistics.statisticsData.get(entryName)!.measurementTimeSeries as TimestampedData[],
+ this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!,
),
95,
);
this.statistics.statisticsData.get(entryName)!.stdDevTimeMeasurement = stdDeviation(
extractTimeSeriesValues(
- this.statistics.statisticsData.get(entryName)!.measurementTimeSeries as TimestampedData[],
+ this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!,
),
+ this.statistics.statisticsData.get(entryName)!.avgTimeMeasurement,
);
if (
Configuration.getConfigurationSection<StorageConfiguration>(
// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-const DEFAULT_CIRCULAR_ARRAY_SIZE = 1024;
+export const DEFAULT_CIRCULAR_ARRAY_SIZE = 1024;
/**
* Array with a maximum length and shifting items when full.
static readonly SEMVER_PATTERN =
'^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$';
- static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 1024;
+ static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 4096;
static readonly DEFAULT_HASH_ALGORITHM = 'sha384';
import { isEmptyArray, isNullOrUndefined } from './Utils';
+/**
+ * Computes the average of the given data set.
+ *
+ * @param dataSet - Data set.
+ * @returns The average of the given data set.
+ * @internal
+ */
+export const average = (dataSet: number[]): number => {
+ if (Array.isArray(dataSet) && dataSet.length === 0) {
+ return 0;
+ }
+ if (Array.isArray(dataSet) && dataSet.length === 1) {
+ return dataSet[0];
+ }
+ return dataSet.reduce((accumulator, nb) => accumulator + nb, 0) / dataSet.length;
+};
+
+/**
+ * Computes the median of the given data set.
+ *
+ * @param dataSet - Data set.
+ * @returns The median of the given data set.
+ * @internal
+ */
export const median = (dataSet: number[]): number => {
if (isEmptyArray(dataSet)) {
return 0;
return sortedDataSet[percentileIndexInteger];
};
-export const stdDeviation = (dataSet: number[]): number => {
- let totalDataSet = 0;
- for (const data of dataSet) {
- totalDataSet += data;
- }
- const dataSetMean = totalDataSet / dataSet.length;
- let totalGeometricDeviation = 0;
- for (const data of dataSet) {
- const deviation = data - dataSetMean;
- totalGeometricDeviation += deviation * deviation;
- }
- return Math.sqrt(totalGeometricDeviation / dataSet.length);
+export const stdDeviation = (dataSet: number[], dataSetAverage?: number): number => {
+ dataSetAverage = dataSetAverage ?? average(dataSet);
+ const geometricDeviation = dataSet.reduce((accumulator, nb) => {
+ const deviation = nb - dataSetAverage!;
+ return accumulator + deviation * deviation;
+ }, 0);
+ return Math.sqrt(geometricDeviation / dataSet.length);
};
sleep,
validateUUID,
} from './Utils';
-export { median, nthPercentile, stdDeviation } from './StatisticUtils';
+export { average, median, nthPercentile, stdDeviation } from './StatisticUtils';
export { logger } from './Logger';
import { expect } from 'expect';
-import { CircularArray } from '../../src/utils/CircularArray';
+import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../../src/utils/CircularArray';
describe('CircularArray test suite', () => {
it('Verify that circular array can be instantiated', () => {
it('Verify circular array default size at instance creation', () => {
const circularArray = new CircularArray();
- expect(circularArray.size).toBe(1024);
+ expect(circularArray.size).toBe(DEFAULT_CIRCULAR_ARRAY_SIZE);
});
it('Verify that circular array size can be set at instance creation', () => {
import { expect } from 'expect';
-import { median, nthPercentile, stdDeviation } from '../../src/utils/StatisticUtils';
+import { average, median, nthPercentile, stdDeviation } from '../../src/utils/StatisticUtils';
describe('StatisticUtils test suite', () => {
+ it('Verify average()', () => {
+ expect(average([])).toBe(0);
+ expect(average([0.08])).toBe(0.08);
+ expect(average([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(3.1642857142857146);
+ expect(average([0.25, 4.75, 3.05, 6.04, 1.01, 2.02])).toBe(2.8533333333333335);
+ });
+
it('Verify median()', () => {
expect(median([])).toBe(0);
expect(median([0.08])).toBe(0.08);