From 6170d8cd4877c852985c90a38441da35ec026b85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 24 May 2023 23:08:59 +0200 Subject: [PATCH] refactor(simulator): add more default values to ATG MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 12 ++++++++---- src/utils/Constants.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 32c8a3bf..1499f8fb 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -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 diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index df1c879b..6d2a6bf0 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -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, -- 2.34.1