refactor(simulator): add more default values to ATG
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 24 May 2023 21:08:59 +0000 (23:08 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 24 May 2023 21:08:59 +0000 (23:08 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/utils/Constants.ts

index 32c8a3bf96f88c9892e9f31d8bc9d68ac0e59714..1499f8fb09e1936848738854c732b9aae2285009 100644 (file)
@@ -225,9 +225,11 @@ export class AutomaticTransactionGenerator extends AsyncResource {
       const wait =
         Utils.getRandomInteger(
           this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
-            .maxDelayBetweenTwoTransactions,
+            .maxDelayBetweenTwoTransactions ??
+            Constants.DEFAULT_ATG_MAX_DELAY_BETWEEN_TWO_TRANSACTIONS,
           this.chargingStation.getAutomaticTransactionGeneratorConfiguration()
-            .minDelayBetweenTwoTransactions
+            .minDelayBetweenTwoTransactions ??
+            Constants.DEFAULT_ATG_MIN_DELAY_BETWEEN_TWO_TRANSACTIONS
         ) * 1000;
       logger.info(
         `${this.logPrefix(connectorId)} waiting for ${Utils.formatDurationMilliSeconds(wait)}`
@@ -245,8 +247,10 @@ export class AutomaticTransactionGenerator extends AsyncResource {
           // Wait until end of transaction
           const waitTrxEnd =
             Utils.getRandomInteger(
-              this.chargingStation.getAutomaticTransactionGeneratorConfiguration().maxDuration,
-              this.chargingStation.getAutomaticTransactionGeneratorConfiguration().minDuration
+              this.chargingStation.getAutomaticTransactionGeneratorConfiguration().maxDuration ??
+                Constants.DEFAULT_ATG_MAX_DURATION,
+              this.chargingStation.getAutomaticTransactionGeneratorConfiguration().minDuration ??
+                Constants.DEFAULT_ATG_MIN_DURATION
             ) * 1000;
           logger.info(
             `${this.logPrefix(connectorId)} transaction started with id ${this.chargingStation
index df1c879b7376ef41928c1e5921f077ddb0875adc..6d2a6bf05b269a5da031268819705d88eab584ec 100644 (file)
@@ -8,14 +8,18 @@ export class Constants {
   static readonly CHARGING_STATION_DEFAULT_RESET_TIME = 60000; // Ms
   static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000; // Ms
 
+  static readonly DEFAULT_ATG_MIN_DURATION = 60;
+  static readonly DEFAULT_ATG_MAX_DURATION = 120;
+  static readonly DEFAULT_ATG_MIN_DELAY_BETWEEN_TWO_TRANSACTIONS = 15;
+  static readonly DEFAULT_ATG_MAX_DELAY_BETWEEN_TWO_TRANSACTIONS = 30;
   static readonly DEFAULT_ATG_STOP_AFTER_HOURS = 0.25; // Hours
   static readonly DEFAULT_ATG_CONFIGURATION: AutomaticTransactionGeneratorConfiguration =
     Object.freeze({
       enable: false,
-      minDuration: 60,
-      maxDuration: 120,
-      minDelayBetweenTwoTransactions: 15,
-      maxDelayBetweenTwoTransactions: 30,
+      minDuration: Constants.DEFAULT_ATG_MIN_DURATION,
+      maxDuration: Constants.DEFAULT_ATG_MAX_DURATION,
+      minDelayBetweenTwoTransactions: Constants.DEFAULT_ATG_MIN_DELAY_BETWEEN_TWO_TRANSACTIONS,
+      maxDelayBetweenTwoTransactions: Constants.DEFAULT_ATG_MAX_DELAY_BETWEEN_TWO_TRANSACTIONS,
       probabilityOfStart: 1,
       stopAfterHours: Constants.DEFAULT_ATG_STOP_AFTER_HOURS,
       stopOnConnectionFailure: true,