X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FMessageChannelUtils.ts;h=f9d1e14980017606a7c1f64ec0135eb47bf8e80b;hb=b8e3363a179fcf79d8bb66f47724b377d4d38a75;hp=36f797f5eb88feb3a9f5e0a4b6ea978b660a9f9b;hpb=09e5a7a8ed45886b6bf1434c4e49c945ded4c7d8;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/MessageChannelUtils.ts b/src/utils/MessageChannelUtils.ts index 36f797f5..f9d1e149 100644 --- a/src/utils/MessageChannelUtils.ts +++ b/src/utils/MessageChannelUtils.ts @@ -1,16 +1,19 @@ -import { - OutputFormat, - buildChargingStationAutomaticTransactionGeneratorConfiguration, - buildConnectorsStatus, - buildEvsesStatus -} from './ChargingStationConfigurationUtils.js' +import { CircularBuffer } from 'mnemonist' + import type { ChargingStation } from '../charging-station/index.js' import { type ChargingStationData, type ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents, - type Statistics + type Statistics, + type TimestampedData } from '../types/index.js' +import { + buildChargingStationAutomaticTransactionGeneratorConfiguration, + buildConnectorsStatus, + buildEvsesStatus, + OutputFormat +} from './ChargingStationConfigurationUtils.js' export const buildAddedMessage = ( chargingStation: ChargingStation @@ -60,15 +63,26 @@ export const buildUpdatedMessage = ( export const buildPerformanceStatisticsMessage = ( statistics: Statistics ): ChargingStationWorkerMessage => { + const statisticsData = [...statistics.statisticsData].map(([key, value]) => { + if (value.measurementTimeSeries instanceof CircularBuffer) { + value.measurementTimeSeries = value.measurementTimeSeries.toArray() as TimestampedData[] + } + return [key, value] + }) return { event: ChargingStationWorkerMessageEvents.performanceStatistics, - data: statistics + data: { + id: statistics.id, + name: statistics.name, + uri: statistics.uri, + createdAt: statistics.createdAt, + updatedAt: statistics.updatedAt, + statisticsData + } } } -export const buildChargingStationDataPayload = ( - chargingStation: ChargingStation -): ChargingStationData => { +const buildChargingStationDataPayload = (chargingStation: ChargingStation): ChargingStationData => { return { started: chargingStation.started, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion