X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FMessageChannelUtils.ts;h=f9d1e14980017606a7c1f64ec0135eb47bf8e80b;hb=b8e3363a179fcf79d8bb66f47724b377d4d38a75;hp=4164c36bf11c96f18b8250cfd47be98bdeb897d5;hpb=90dc299a5f5c9990aa52911b2d8fdc401776972f;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/MessageChannelUtils.ts b/src/utils/MessageChannelUtils.ts index 4164c36b..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,9 +63,22 @@ 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 + } } }