X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FAutomaticTransactionGenerator.js;h=ebb0a8e0a5d17baf73bb1de4733e8717559bc2b8;hb=d3a7883e3b5f20baee6fff45ee599341300d7564;hp=5ba078f8874cc7a6fe08341ec06adfd200c6c1ef;hpb=2e6f5966ecbefada47d60b1b53d21fe49be439a5;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/AutomaticTransactionGenerator.js b/src/charging-station/AutomaticTransactionGenerator.js index 5ba078f8..ebb0a8e0 100644 --- a/src/charging-station/AutomaticTransactionGenerator.js +++ b/src/charging-station/AutomaticTransactionGenerator.js @@ -5,7 +5,7 @@ const {performance, PerformanceObserver} = require('perf_hooks'); class AutomaticTransactionGenerator { constructor(chargingStation) { this._chargingStation = chargingStation; - this._timeToStop = false; + this._timeToStop = true; this._performanceObserver = new PerformanceObserver((list) => { const entry = list.getEntries()[0]; this._chargingStation._statistics.logPerformance(entry, 'AutomaticTransactionGenerator'); @@ -13,9 +13,13 @@ class AutomaticTransactionGenerator { }); } + get timeToStop() { + return this._timeToStop; + } + _basicFormatLog(connectorId = null) { if (connectorId) { - return Utils.basicFormatLog(' ' + this._chargingStation._stationInfo.name + ' ATG on connector #' + connectorId); + return Utils.basicFormatLog(' ' + this._chargingStation._stationInfo.name + ' ATG on connector #' + connectorId + ':'); } return Utils.basicFormatLog(' ' + this._chargingStation._stationInfo.name + ' ATG:'); } @@ -25,7 +29,7 @@ class AutomaticTransactionGenerator { for (const connector in this._chargingStation._connectors) { if (this._chargingStation._connectors[connector].transactionStarted) { logger.info(this._basicFormatLog(connector) + ' ATG OVER. Stop transaction ' + this._chargingStation._connectors[connector].transactionId); - await this._chargingStation.sendStopTransaction(this._chargingStation._connectors[connector].transactionId, connector); + await this._chargingStation.sendStopTransaction(this._chargingStation._connectors[connector].transactionId); } } this._timeToStop = true; @@ -33,12 +37,12 @@ class AutomaticTransactionGenerator { async start() { this._timeToStop = false; - if (this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAutomaticTransactionGeneratorAfterHours && - this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAutomaticTransactionGeneratorAfterHours > 0) { - logger.info(this._basicFormatLog() + ' ATG will stop in ' + Utils.secondstoHHMMSS(this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAutomaticTransactionGeneratorAfterHours * 3600)); + if (this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours && + this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours > 0) { + logger.info(this._basicFormatLog() + ' ATG will stop in ' + Utils.secondstoHHMMSS(this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600)); setTimeout(() => { this.stop(); - }, this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAutomaticTransactionGeneratorAfterHours * 3600 * 1000); + }, this._chargingStation._stationInfo.AutomaticTransactionGenerator.stopAfterHours * 3600 * 1000); } for (const connector in this._chargingStation._connectors) { if (connector > 0) { @@ -49,7 +53,8 @@ class AutomaticTransactionGenerator { async startConnector(connectorId) { do { - const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDelayBetweenTwoTransaction, this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDelayBetweenTwoTransaction) * 1000; + const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDelayBetweenTwoTransactions, + this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDelayBetweenTwoTransactions) * 1000; logger.info(this._basicFormatLog(connectorId) + ' wait for ' + Utils.secondstoHHMMSS(wait / 1000)); await Utils.sleep(wait); if (this._timeToStop) break; @@ -58,7 +63,6 @@ class AutomaticTransactionGenerator { if (start < this._chargingStation._stationInfo.AutomaticTransactionGenerator.probabilityOfStart) { skip = 0; // Start transaction - logger.info(this._basicFormatLog(connectorId) + ' start transaction'); const startTransaction = performance.timerify(this.startTransaction); this._performanceObserver.observe({entryTypes: ['function']}); const startResponse = await startTransaction(connectorId, this); @@ -67,7 +71,8 @@ class AutomaticTransactionGenerator { await Utils.sleep(2000); } else { // Wait until end of transaction - const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDuration, this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDuration) * 1000; + const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDuration, + this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDuration) * 1000; logger.info(this._basicFormatLog(connectorId) + ' transaction ' + this._chargingStation._connectors[connectorId].transactionId + ' will stop in ' + Utils.secondstoHHMMSS(wait / 1000)); await Utils.sleep(wait); // Stop transaction @@ -83,7 +88,7 @@ class AutomaticTransactionGenerator { logger.info(this._basicFormatLog(connectorId) + ' transaction skipped ' + skip); } } while (!this._timeToStop); - logger.info(this._basicFormatLog() + ' ATG is STOPPED'); + logger.info(this._basicFormatLog(connectorId) + ' ATG STOPPED on the connector'); } // eslint-disable-next-line class-methods-use-this @@ -98,7 +103,7 @@ class AutomaticTransactionGenerator { // eslint-disable-next-line class-methods-use-this async stopTransaction(connectorId, self) { - await self._chargingStation.sendStopTransaction(self._chargingStation._connectors[connectorId].transactionId, connectorId); + await self._chargingStation.sendStopTransaction(self._chargingStation._connectors[connectorId].transactionId); } }