From: Jérôme Benoit Date: Sun, 4 Sep 2022 19:53:09 +0000 (+0200) Subject: ATG: fix start transaction requests counting X-Git-Tag: v1.1.70~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0afed85fd7e6cb8f4b5ea0d18800a8d7b3bd78a7;p=e-mobility-charging-stations-simulator.git ATG: fix start transaction requests counting Signed-off-by: Jérôme Benoit --- 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