From: Jérôme Benoit Date: Wed, 24 May 2023 21:21:27 +0000 (+0200) Subject: refactor(simulator): simplify ATG default configuration usage X-Git-Tag: v1.2.14~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=86b46b496311fcb6ee26c0d639b6f3c642042c2b;p=e-mobility-charging-stations-simulator.git refactor(simulator): simplify ATG default configuration usage Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 1499f8fb..c5076adc 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -225,11 +225,9 @@ export class AutomaticTransactionGenerator extends AsyncResource { const wait = Utils.getRandomInteger( this.chargingStation.getAutomaticTransactionGeneratorConfiguration() - .maxDelayBetweenTwoTransactions ?? - Constants.DEFAULT_ATG_MAX_DELAY_BETWEEN_TWO_TRANSACTIONS, + .maxDelayBetweenTwoTransactions, this.chargingStation.getAutomaticTransactionGeneratorConfiguration() - .minDelayBetweenTwoTransactions ?? - Constants.DEFAULT_ATG_MIN_DELAY_BETWEEN_TWO_TRANSACTIONS + .minDelayBetweenTwoTransactions ) * 1000; logger.info( `${this.logPrefix(connectorId)} waiting for ${Utils.formatDurationMilliSeconds(wait)}` @@ -247,10 +245,8 @@ export class AutomaticTransactionGenerator extends AsyncResource { // Wait until end of transaction const waitTrxEnd = Utils.getRandomInteger( - this.chargingStation.getAutomaticTransactionGeneratorConfiguration().maxDuration ?? - Constants.DEFAULT_ATG_MAX_DURATION, - this.chargingStation.getAutomaticTransactionGeneratorConfiguration().minDuration ?? - Constants.DEFAULT_ATG_MIN_DURATION + this.chargingStation.getAutomaticTransactionGeneratorConfiguration().maxDuration, + this.chargingStation.getAutomaticTransactionGeneratorConfiguration().minDuration ) * 1000; logger.info( `${this.logPrefix(connectorId)} transaction started with id ${this.chargingStation @@ -307,8 +303,7 @@ export class AutomaticTransactionGenerator extends AsyncResource { this.connectorsStatus.get(connectorId).startDate = new Date(); this.connectorsStatus.get(connectorId).stopDate = new Date( this.connectorsStatus.get(connectorId).startDate.getTime() + - (this.chargingStation.getAutomaticTransactionGeneratorConfiguration().stopAfterHours ?? - Constants.DEFAULT_ATG_STOP_AFTER_HOURS) * + this.chargingStation.getAutomaticTransactionGeneratorConfiguration().stopAfterHours * 3600 * 1000 - previousRunDuration diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index a8d96e13..9a0d0f86 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -818,12 +818,22 @@ export class ChargingStation { public getAutomaticTransactionGeneratorConfiguration(): | AutomaticTransactionGeneratorConfiguration | undefined { + let automaticTransactionGeneratorConfiguration: + | AutomaticTransactionGeneratorConfiguration + | undefined; const automaticTransactionGeneratorConfigurationFromFile = this.getConfigurationFromFile()?.automaticTransactionGenerator; if (automaticTransactionGeneratorConfigurationFromFile) { - return automaticTransactionGeneratorConfigurationFromFile; + automaticTransactionGeneratorConfiguration = + automaticTransactionGeneratorConfigurationFromFile; + } else { + automaticTransactionGeneratorConfiguration = + this.getTemplateFromFile()?.AutomaticTransactionGenerator; } - return this.getTemplateFromFile()?.AutomaticTransactionGenerator; + return { + ...automaticTransactionGeneratorConfiguration, + ...Constants.DEFAULT_ATG_CONFIGURATION, + }; } public startAutomaticTransactionGenerator(connectorIds?: number[]): void { diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 6d2a6bf0..a5cd8150 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -8,20 +8,15 @@ 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: 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, + minDuration: 60, + maxDuration: 120, + minDelayBetweenTwoTransactions: 15, + maxDelayBetweenTwoTransactions: 30, probabilityOfStart: 1, - stopAfterHours: Constants.DEFAULT_ATG_STOP_AFTER_HOURS, + stopAfterHours: 0.25, stopOnConnectionFailure: true, });