public timeToStop: boolean;
private startDate!: Date;
private stopDate!: Date;
+ private runningDuration!: number;
private chargingStation: ChargingStation;
constructor(chargingStation: ChargingStation) {
public start(): void {
this.startDate = new Date();
- this.stopDate = new Date(this.startDate.getTime() + (this.chargingStation.stationInfo?.AutomaticTransactionGenerator?.stopAfterHours ?? Constants.CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS) * 3600 * 1000);
+ this.stopDate = new Date(this.startDate.getTime()
+ + (this.chargingStation.stationInfo?.AutomaticTransactionGenerator?.stopAfterHours ?? Constants.CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS) * 3600 * 1000
+ - (this.runningDuration ?? 0));
this.timeToStop = false;
for (const connector in this.chargingStation.connectors) {
if (Utils.convertToInt(connector) > 0) {
});
}
}
- logger.info(this.logPrefix() + ' started and will run for ' + Utils.milliSecondsToHHMMSS(this.stopDate.getTime() - this.startDate.getTime()));
+ logger.info(this.logPrefix() + ' started and will run for ' + Utils.formatDurationMilliSeconds(this.stopDate.getTime() - this.startDate.getTime()));
}
public async stop(reason: StopTransactionReason = StopTransactionReason.NONE): Promise<void> {
- logger.info(this.logPrefix() + ' over. Stopping all transactions');
+ logger.info(`${this.logPrefix()} over and lasted for ${Utils.formatDurationMilliSeconds(this.runningDuration ?? 0)}. Stopping all transactions`);
for (const connector in this.chargingStation.connectors) {
const transactionId = this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionId;
if (this.chargingStation.getConnector(Utils.convertToInt(connector)).transactionStarted) {
}
const wait = Utils.getRandomInt(this.chargingStation.stationInfo.AutomaticTransactionGenerator.maxDelayBetweenTwoTransactions,
this.chargingStation.stationInfo.AutomaticTransactionGenerator.minDelayBetweenTwoTransactions) * 1000;
- logger.info(this.logPrefix(connectorId) + ' waiting for ' + Utils.milliSecondsToHHMMSS(wait));
+ logger.info(this.logPrefix(connectorId) + ' waiting for ' + Utils.formatDurationMilliSeconds(wait));
await Utils.sleep(wait);
- const start = Math.random();
+ const start = Utils.secureRandom();
if (start < this.chargingStation.stationInfo.AutomaticTransactionGenerator.probabilityOfStart) {
transactionSkip = 0;
// Start transaction
// Wait until end of transaction
const waitTrxEnd = Utils.getRandomInt(this.chargingStation.stationInfo.AutomaticTransactionGenerator.maxDuration,
this.chargingStation.stationInfo.AutomaticTransactionGenerator.minDuration) * 1000;
- logger.info(this.logPrefix(connectorId) + ' transaction ' + this.chargingStation.getConnector(connectorId).transactionId.toString() + ' will stop in ' + Utils.milliSecondsToHHMMSS(waitTrxEnd));
+ logger.info(this.logPrefix(connectorId) + ' transaction ' + this.chargingStation.getConnector(connectorId).transactionId.toString() + ' will stop in ' + Utils.formatDurationMilliSeconds(waitTrxEnd));
await Utils.sleep(waitTrxEnd);
// Stop transaction
if (this.chargingStation.getConnector(connectorId)?.transactionStarted) {
totalTransactionSkip++;
logger.info(this.logPrefix(connectorId) + ' skipped transaction ' + transactionSkip.toString() + '/' + totalTransactionSkip.toString());
}
+ this.runningDuration = (new Date()).getTime() - this.startDate.getTime();
}
logger.info(this.logPrefix(connectorId) + ' stopped on connector');
}