From 58fad7497e7a15b06ce06d1be297f704ef4b869b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 18 Sep 2021 14:12:41 +0200 Subject: [PATCH] Keep track of ATG running time MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/AutomaticTransactionGenerator.ts | 8 ++++++-- src/charging-station/ChargingStation.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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 { -- 2.34.1