ATG: fix start transaction counting (again)
[e-mobility-charging-stations-simulator.git] / src / charging-station / AutomaticTransactionGenerator.ts
index d552d8a50b3aed420a68f2d8bdd837b65be9c11c..54b409ed39b7837cc7d988de8719e18512ee4add 100644 (file)
@@ -309,13 +309,7 @@ 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++;
-          }
+          this.handleStartTransactionResponse(connectorId, startResponse);
           PerformanceStatistics.endMeasure(measureId, beginId);
           return startResponse;
         }
@@ -332,6 +326,7 @@ export default class AutomaticTransactionGenerator {
         connectorId,
         idTag,
       });
+      this.handleStartTransactionResponse(connectorId, startResponse);
       PerformanceStatistics.endMeasure(measureId, beginId);
       return startResponse;
     }
@@ -340,6 +335,7 @@ export default class AutomaticTransactionGenerator {
       StartTransactionRequest,
       StartTransactionResponse
     >(this.chargingStation, RequestCommand.START_TRANSACTION, { connectorId });
+    this.handleStartTransactionResponse(connectorId, startResponse);
     PerformanceStatistics.endMeasure(measureId, beginId);
     return startResponse;
   }
@@ -382,4 +378,17 @@ export default class AutomaticTransactionGenerator {
       }:`
     );
   }
+
+  private handleStartTransactionResponse(
+    connectorId: number,
+    startResponse: StartTransactionResponse
+  ): void {
+    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++;
+    }
+  }
 }