X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FMessageChannelUtils.ts;h=f9d1e14980017606a7c1f64ec0135eb47bf8e80b;hb=8bfa4d2be3f3817654791f166f4aab1b02485005;hp=1af746daafe67840e536c95a8ef719171b37de4a;hpb=276e05aec38f4e8b4a8d5ebd8cbbcb30592b414d;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/MessageChannelUtils.ts b/src/utils/MessageChannelUtils.ts index 1af746da..f9d1e149 100644 --- a/src/utils/MessageChannelUtils.ts +++ b/src/utils/MessageChannelUtils.ts @@ -1,9 +1,12 @@ +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, @@ -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