Add more ATG internal states tracking
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 26 Sep 2021 10:47:45 +0000 (12:47 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 26 Sep 2021 10:47:45 +0000 (12:47 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/AutomaticTransactionGenerator.ts
src/types/AutomaticTransactionGenerator.ts
src/utils/Constants.ts

index 7645e27e77d96e491a5c916becc7cbca2950c93e..a2854507d98b452d3ea92389e877ed49f6039978 100644 (file)
@@ -95,14 +95,16 @@ 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');
-          await Utils.sleep(Constants.CHARGING_STATION_ATG_WAIT_TIME);
+          this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++;
         } else {
           // Wait until end of transaction
           const waitTrxEnd = Utils.getRandomInteger(this.chargingStation.stationInfo.AutomaticTransactionGenerator.maxDuration,
             this.chargingStation.stationInfo.AutomaticTransactionGenerator.minDuration) * 1000;
           logger.info(this.logPrefix(connectorId) + ' transaction ' + this.chargingStation.getConnector(connectorId).transactionId.toString() + ' started and will stop in ' + Utils.formatDurationMilliSeconds(waitTrxEnd));
+          this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests++;
           await Utils.sleep(waitTrxEnd);
           // Stop transaction
           logger.info(this.logPrefix(connectorId) + ' stop transaction ' + this.chargingStation.getConnector(connectorId).transactionId.toString());
@@ -133,8 +135,15 @@ export default class AutomaticTransactionGenerator {
   }
 
   private initStartConnectorStatus(connectorId: number): void {
+    this.connectorsStatus.get(connectorId).authorizeRequests = this?.connectorsStatus.get(connectorId)?.authorizeRequests ?? 0;
+    this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests = this?.connectorsStatus.get(connectorId)?.acceptedAuthorizeRequests ?? 0;
+    this.connectorsStatus.get(connectorId).rejectedAuthorizeRequests = this?.connectorsStatus.get(connectorId)?.rejectedAuthorizeRequests ?? 0;
+    this.connectorsStatus.get(connectorId).startTransactionRequests = this?.connectorsStatus.get(connectorId)?.startTransactionRequests ?? 0;
+    this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests = this?.connectorsStatus.get(connectorId)?.acceptedStartTransactionRequests ?? 0;
+    this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests = this?.connectorsStatus.get(connectorId)?.rejectedStartTransactionRequests ?? 0;
+    this.connectorsStatus.get(connectorId).stopTransactionRequests = this?.connectorsStatus.get(connectorId)?.stopTransactionRequests ?? 0;
     this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions = 0;
-    this.connectorsStatus.get(connectorId).skippedTransactions = 0;
+    this.connectorsStatus.get(connectorId).skippedTransactions = this?.connectorsStatus.get(connectorId)?.skippedTransactions ?? 0;
     const previousRunDuration = (this?.connectorsStatus.get(connectorId)?.startDate && this?.connectorsStatus.get(connectorId)?.lastRunDate)
       ? (this.connectorsStatus.get(connectorId).lastRunDate.getTime() - this.connectorsStatus.get(connectorId).startDate.getTime())
       : 0;
@@ -154,13 +163,16 @@ export default class AutomaticTransactionGenerator {
       if (this.chargingStation.getAutomaticTransactionGeneratorRequireAuthorize()) {
         // Authorize idTag
         const authorizeResponse = await this.chargingStation.ocppRequestService.sendAuthorize(connectorId, idTag);
+        this.connectorsStatus.get(connectorId).authorizeRequests++;
         if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
+          this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++;
           logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
           // Start transaction
           startResponse = await this.chargingStation.ocppRequestService.sendStartTransaction(connectorId, idTag);
           PerformanceStatistics.endMeasure(measureId, beginId);
           return startResponse;
         }
+        this.connectorsStatus.get(connectorId).rejectedAuthorizeRequests++;
         PerformanceStatistics.endMeasure(measureId, beginId);
         return authorizeResponse;
       }
@@ -187,6 +199,7 @@ export default class AutomaticTransactionGenerator {
         this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
         this.chargingStation.getTransactionIdTag(transactionId),
         reason);
+      this.connectorsStatus.get(connectorId).stopTransactionRequests++;
     } else {
       logger.warn(`${this.logPrefix(connectorId)} trying to stop a not started transaction${transactionId ? ' ' + transactionId.toString() : ''}`);
     }
index e7fe178fba29940b5646c748100adcf29472e484..940a5d75b7115bf212928223e514f01109e8b112 100644 (file)
@@ -4,6 +4,13 @@ export interface Status {
   lastRunDate?: Date;
   stopDate?: Date;
   stoppedDate?: Date;
+  authorizeRequests?: number;
+  acceptedAuthorizeRequests?: number;
+  rejectedAuthorizeRequests?: number;
+  startTransactionRequests?: number;
+  acceptedStartTransactionRequests?: number;
+  rejectedStartTransactionRequests?: number;
+  stopTransactionRequests?: number;
   skippedConsecutiveTransactions?: number;
   skippedTransactions?: number;
 }
index e6c28221d711b6620989d5735354a8d8388cbfa5..2852d8f634a481198e4340c96f3dd08e859445cc 100644 (file)
@@ -30,7 +30,6 @@ export default class Constants {
   static readonly OCPP_TRIGGER_MESSAGE_DELAY = 2000; // Ms
 
   static readonly CHARGING_STATION_DEFAULT_RESET_TIME = 60000; // Ms
-  static readonly CHARGING_STATION_ATG_WAIT_TIME = 2000; // Ms
   static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000; // Ms
   static readonly CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS = 0.25; // Hours