ATG: fix start transaction requests counting
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 4 Sep 2022 19:53:09 +0000 (21:53 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 4 Sep 2022 19:53:09 +0000 (21:53 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ocpp/OCPPRequestService.ts

index 83bedaab3f52c6073d28195ad80a6df8bee54fbe..d552d8a50b3aed420a68f2d8bdd837b65be9c11c 100644 (file)
@@ -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<StartTransactionResponse | AuthorizeResponse> {
+  ): Promise<StartTransactionResponse | undefined> {
     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++;
index 6993e1ecabdbefbdd8ebe244063e4aa594ee430f..e78ca0c6dfa4d8fcec3049d05b67a11d62df82de 100644 (file)
@@ -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