From: Jérôme Benoit Date: Sat, 18 Sep 2021 12:12:41 +0000 (+0200) Subject: Keep track of ATG running time X-Git-Tag: v1.1.4~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=58fad7497e7a15b06ce06d1be297f704ef4b869b;p=e-mobility-charging-stations-simulator.git Keep track of ATG running time Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 5526339f..6f77199a 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -12,6 +12,7 @@ export default class AutomaticTransactionGenerator { public timeToStop: boolean; private startDate!: Date; private stopDate!: Date; + private runningDuration!: number; private chargingStation: ChargingStation; constructor(chargingStation: ChargingStation) { @@ -21,7 +22,9 @@ export default class AutomaticTransactionGenerator { public start(): void { this.startDate = new Date(); - this.stopDate = new Date(this.startDate.getTime() + (this.chargingStation.stationInfo?.AutomaticTransactionGenerator?.stopAfterHours ?? Constants.CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS) * 3600 * 1000); + this.stopDate = new Date(this.startDate.getTime() + + (this.chargingStation.stationInfo?.AutomaticTransactionGenerator?.stopAfterHours ?? Constants.CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS) * 3600 * 1000 + - (this.runningDuration ?? 0)); this.timeToStop = false; for (const connector in this.chargingStation.connectors) { if (Utils.convertToInt(connector) > 0) { @@ -35,7 +38,7 @@ export default class AutomaticTransactionGenerator { } public async stop(reason: StopTransactionReason = StopTransactionReason.NONE): Promise { - logger.info(this.logPrefix() + ' over. Stopping all transactions'); + logger.info(`${this.logPrefix()} over and lasted for ${Utils.formatDurationMilliSeconds(this.runningDuration ?? 0)}. Stopping all transactions`); for (const connector in this.chargingStation.connectors) { const transactionId = this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionId; if (this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionStarted) { @@ -104,6 +107,7 @@ export default class AutomaticTransactionGenerator { totalTransactionSkip++; logger.info(this.logPrefix(connectorId) + ' skipped transaction ' + transactionSkip.toString() + '/' + totalTransactionSkip.toString()); } + this.runningDuration = (new Date()).getTime() - this.startDate.getTime(); } logger.info(this.logPrefix(connectorId) + ' stopped on connector'); } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 9cb5e066..ff7ce6cd 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -8,7 +8,7 @@ import { ConnectorPhaseRotation, StandardParametersKey, SupportedFeatureProfiles import Connectors, { Connector, SampledValueTemplate } from '../types/Connectors'; import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues'; import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket'; -import WebSocket, { ClientOptions, Data } from 'ws'; +import WebSocket, { ClientOptions, Data, OPEN } from 'ws'; import AutomaticTransactionGenerator from './AutomaticTransactionGenerator'; import { ChargePointStatus } from '../types/ocpp/ChargePointStatus'; @@ -111,7 +111,7 @@ export default class ChargingStation { } public isWebSocketConnectionOpened(): boolean { - return this.wsConnection?.readyState === WebSocket.OPEN; + return this.wsConnection?.readyState === OPEN; } public isRegistered(): boolean {