From 071a9315b94fb1c6f7996ca71e42794ac9ff9f82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 26 Sep 2021 12:47:45 +0200 Subject: [PATCH] Add more ATG internal states tracking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 17 +++++++++++++++-- src/types/AutomaticTransactionGenerator.ts | 7 +++++++ src/utils/Constants.ts | 1 - 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 7645e27e..a2854507 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -95,14 +95,16 @@ export default class AutomaticTransactionGenerator { this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions = 0; // Start transaction const startResponse = await this.startTransaction(connectorId); + this.connectorsStatus.get(connectorId).startTransactionRequests++; if (startResponse?.idTagInfo?.status !== AuthorizationStatus.ACCEPTED) { logger.warn(this.logPrefix(connectorId) + ' start transaction rejected'); - await Utils.sleep(Constants.CHARGING_STATION_ATG_WAIT_TIME); + this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++; } else { // Wait until end of transaction const waitTrxEnd = Utils.getRandomInteger(this.chargingStation.stationInfo.AutomaticTransactionGenerator.maxDuration, this.chargingStation.stationInfo.AutomaticTransactionGenerator.minDuration) * 1000; logger.info(this.logPrefix(connectorId) + ' transaction ' + this.chargingStation.getConnector(connectorId).transactionId.toString() + ' started and will stop in ' + Utils.formatDurationMilliSeconds(waitTrxEnd)); + this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests++; await Utils.sleep(waitTrxEnd); // Stop transaction logger.info(this.logPrefix(connectorId) + ' stop transaction ' + this.chargingStation.getConnector(connectorId).transactionId.toString()); @@ -133,8 +135,15 @@ export default class AutomaticTransactionGenerator { } private initStartConnectorStatus(connectorId: number): void { + this.connectorsStatus.get(connectorId).authorizeRequests = this?.connectorsStatus.get(connectorId)?.authorizeRequests ?? 0; + this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests = this?.connectorsStatus.get(connectorId)?.acceptedAuthorizeRequests ?? 0; + this.connectorsStatus.get(connectorId).rejectedAuthorizeRequests = this?.connectorsStatus.get(connectorId)?.rejectedAuthorizeRequests ?? 0; + this.connectorsStatus.get(connectorId).startTransactionRequests = this?.connectorsStatus.get(connectorId)?.startTransactionRequests ?? 0; + this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests = this?.connectorsStatus.get(connectorId)?.acceptedStartTransactionRequests ?? 0; + this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests = this?.connectorsStatus.get(connectorId)?.rejectedStartTransactionRequests ?? 0; + this.connectorsStatus.get(connectorId).stopTransactionRequests = this?.connectorsStatus.get(connectorId)?.stopTransactionRequests ?? 0; this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions = 0; - this.connectorsStatus.get(connectorId).skippedTransactions = 0; + this.connectorsStatus.get(connectorId).skippedTransactions = this?.connectorsStatus.get(connectorId)?.skippedTransactions ?? 0; const previousRunDuration = (this?.connectorsStatus.get(connectorId)?.startDate && this?.connectorsStatus.get(connectorId)?.lastRunDate) ? (this.connectorsStatus.get(connectorId).lastRunDate.getTime() - this.connectorsStatus.get(connectorId).startDate.getTime()) : 0; @@ -154,13 +163,16 @@ export default class AutomaticTransactionGenerator { if (this.chargingStation.getAutomaticTransactionGeneratorRequireAuthorize()) { // Authorize idTag const authorizeResponse = await this.chargingStation.ocppRequestService.sendAuthorize(connectorId, idTag); + this.connectorsStatus.get(connectorId).authorizeRequests++; if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { + this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++; logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag); // Start transaction startResponse = await this.chargingStation.ocppRequestService.sendStartTransaction(connectorId, idTag); PerformanceStatistics.endMeasure(measureId, beginId); return startResponse; } + this.connectorsStatus.get(connectorId).rejectedAuthorizeRequests++; PerformanceStatistics.endMeasure(measureId, beginId); return authorizeResponse; } @@ -187,6 +199,7 @@ export default class AutomaticTransactionGenerator { this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId), this.chargingStation.getTransactionIdTag(transactionId), reason); + this.connectorsStatus.get(connectorId).stopTransactionRequests++; } else { logger.warn(`${this.logPrefix(connectorId)} trying to stop a not started transaction${transactionId ? ' ' + transactionId.toString() : ''}`); } diff --git a/src/types/AutomaticTransactionGenerator.ts b/src/types/AutomaticTransactionGenerator.ts index e7fe178f..940a5d75 100644 --- a/src/types/AutomaticTransactionGenerator.ts +++ b/src/types/AutomaticTransactionGenerator.ts @@ -4,6 +4,13 @@ export interface Status { lastRunDate?: Date; stopDate?: Date; stoppedDate?: Date; + authorizeRequests?: number; + acceptedAuthorizeRequests?: number; + rejectedAuthorizeRequests?: number; + startTransactionRequests?: number; + acceptedStartTransactionRequests?: number; + rejectedStartTransactionRequests?: number; + stopTransactionRequests?: number; skippedConsecutiveTransactions?: number; skippedTransactions?: number; } diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index e6c28221..2852d8f6 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -30,7 +30,6 @@ export default class Constants { static readonly OCPP_TRIGGER_MESSAGE_DELAY = 2000; // Ms static readonly CHARGING_STATION_DEFAULT_RESET_TIME = 60000; // Ms - static readonly CHARGING_STATION_ATG_WAIT_TIME = 2000; // Ms static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000; // Ms static readonly CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS = 0.25; // Hours -- 2.34.1