From 0afed85fd7e6cb8f4b5ea0d18800a8d7b3bd78a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 4 Sep 2022 21:53:09 +0200 Subject: [PATCH] ATG: fix start transaction requests counting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 20 ++++++++++--------- .../ocpp/OCPPRequestService.ts | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 83bedaab..d552d8a5 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -186,11 +186,7 @@ export default class AutomaticTransactionGenerator { this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions = 0; // Start transaction const startResponse = await this.startTransaction(connectorId); - this.connectorsStatus.get(connectorId).startTransactionRequests++; - if (startResponse?.idTagInfo?.status !== AuthorizationStatus.ACCEPTED) { - logger.warn(this.logPrefix(connectorId) + ' start transaction rejected'); - this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++; - } else { + if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { // Wait until end of transaction const waitTrxEnd = Utils.getRandomInteger(this.configuration.maxDuration, this.configuration.minDuration) * @@ -202,7 +198,6 @@ export default class AutomaticTransactionGenerator { ' started and will stop in ' + Utils.formatDurationMilliSeconds(waitTrxEnd) ); - this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests++; await Utils.sleep(waitTrxEnd); // Stop transaction logger.info( @@ -283,7 +278,7 @@ export default class AutomaticTransactionGenerator { private async startTransaction( connectorId: number - ): Promise { + ): Promise { const measureId = 'StartTransaction with ATG'; const beginId = PerformanceStatistics.beginMeasure(measureId); let startResponse: StartTransactionResponse; @@ -314,12 +309,19 @@ export default class AutomaticTransactionGenerator { connectorId, idTag, }); + this.connectorsStatus.get(connectorId).startTransactionRequests++; + if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { + this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests++; + } else { + logger.warn(this.logPrefix(connectorId) + ' start transaction rejected'); + this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++; + } PerformanceStatistics.endMeasure(measureId, beginId); return startResponse; } this.connectorsStatus.get(connectorId).rejectedAuthorizeRequests++; PerformanceStatistics.endMeasure(measureId, beginId); - return authorizeResponse; + return startResponse; } logger.info(startTransactionLogMsg); // Start transaction @@ -352,7 +354,7 @@ export default class AutomaticTransactionGenerator { if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) { stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason); this.connectorsStatus.get(connectorId).stopTransactionRequests++; - if (stopResponse.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { + if (stopResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { this.connectorsStatus.get(connectorId).acceptedStopTransactionRequests++; } else { this.connectorsStatus.get(connectorId).rejectedStopTransactionRequests++; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 6993e1ec..e78ca0c6 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -261,7 +261,7 @@ export default abstract class OCPPRequestService { * @param requestStatistic */ function errorCallback(error: OCPPError, requestStatistic = true): void { - if (requestStatistic && chargingStation.getEnableStatistics()) { + if (requestStatistic === true && chargingStation.getEnableStatistics() === true) { chargingStation.performanceStatistics.addRequestStatistic( commandName, MessageType.CALL_ERROR_MESSAGE -- 2.34.1