// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks';
-import { URL } from 'url';
+import type { URL } from 'url';
import { parentPort } from 'worker_threads';
-import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker';
+import { MessageChannelUtils } from '../charging-station/MessageChannelUtils';
import { MessageType } from '../types/ocpp/MessageType';
-import { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests';
-import Statistics, { StatisticsData, TimeSeries } from '../types/Statistics';
+import type { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests';
+import type { Statistics, StatisticsData, TimeSeries } from '../types/Statistics';
import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../utils/CircularArray';
import Configuration from '../utils/Configuration';
import logger from '../utils/Logger';
}
private median(dataSet: number[]): number {
- if (Array.isArray(dataSet) && dataSet.length === 1) {
+ if (Array.isArray(dataSet) === true && dataSet.length === 1) {
return dataSet[0];
}
const sortedDataSet = dataSet.slice().sort((a, b) => a - b);
}
private addPerformanceEntryToStatistics(entry: PerformanceEntry): void {
- let entryName = entry.name;
- // Rename entry name
- const MAP_NAME: Record<string, string> = {};
- if (MAP_NAME[entryName]) {
- entryName = MAP_NAME[entryName];
- }
+ const entryName = entry.name;
// Initialize command statistics
if (!this.statistics.statisticsData.has(entryName)) {
this.statistics.statisticsData.set(entryName, {});
this.statistics.statisticsData.get(entryName).avgTimeMeasurement =
this.statistics.statisticsData.get(entryName).totalTimeMeasurement /
this.statistics.statisticsData.get(entryName).countTimeMeasurement;
- Array.isArray(this.statistics.statisticsData.get(entryName).timeMeasurementSeries)
+ Array.isArray(this.statistics.statisticsData.get(entryName).timeMeasurementSeries) === true
? this.statistics.statisticsData
.get(entryName)
.timeMeasurementSeries.push({ timestamp: entry.startTime, value: entry.duration })
)
);
if (Configuration.getPerformanceStorage().enabled) {
- parentPort.postMessage({
- id: ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS,
- data: this.statistics,
- });
+ parentPort.postMessage(
+ MessageChannelUtils.buildPerformanceStatisticsMessage(this.statistics)
+ );
}
}