Merge branch 'main' into reservation-feature
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 25 May 2023 15:59:10 +0000 (17:59 +0200)
committerGitHub <noreply@github.com>
Thu, 25 May 2023 15:59:10 +0000 (17:59 +0200)
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/performance/PerformanceStatistics.ts
src/utils/Constants.ts
src/worker/WorkerSet.ts

index 011f1a1594af49893f94799dc5316aad562b263f..c5076adce7ca9a24f7c25ea50a45a1c916a355cf 100644 (file)
@@ -265,8 +265,8 @@ export class AutomaticTransactionGenerator extends AsyncResource {
           await this.stopTransaction(connectorId);
         }
       } else {
-        this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions++;
-        this.connectorsStatus.get(connectorId).skippedTransactions++;
+        ++this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions;
+        ++this.connectorsStatus.get(connectorId).skippedTransactions;
         logger.info(
           `${this.logPrefix(connectorId)} skipped consecutively ${this.connectorsStatus
             .get(connectorId)
@@ -303,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.CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS) *
+        this.chargingStation.getAutomaticTransactionGeneratorConfiguration().stopAfterHours *
           3600 *
           1000 -
         previousRunDuration
@@ -381,9 +380,9 @@ export class AutomaticTransactionGenerator extends AsyncResource {
           >(this.chargingStation, RequestCommand.AUTHORIZE, {
             idTag,
           });
-        this.connectorsStatus.get(connectorId).authorizeRequests++;
+        ++this.connectorsStatus.get(connectorId).authorizeRequests;
         if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
-          this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++;
+          ++this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests;
           logger.info(startTransactionLogMsg);
           // Start transaction
           startResponse = await this.chargingStation.ocppRequestService.requestHandler<
@@ -397,7 +396,7 @@ export class AutomaticTransactionGenerator extends AsyncResource {
           PerformanceStatistics.endMeasure(measureId, beginId);
           return startResponse;
         }
-        this.connectorsStatus.get(connectorId).rejectedAuthorizeRequests++;
+        ++this.connectorsStatus.get(connectorId).rejectedAuthorizeRequests;
         PerformanceStatistics.endMeasure(measureId, beginId);
         return startResponse;
       }
@@ -433,11 +432,11 @@ export class AutomaticTransactionGenerator extends AsyncResource {
     let stopResponse: StopTransactionResponse;
     if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) {
       stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason);
-      this.connectorsStatus.get(connectorId).stopTransactionRequests++;
+      ++this.connectorsStatus.get(connectorId).stopTransactionRequests;
       if (stopResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
-        this.connectorsStatus.get(connectorId).acceptedStopTransactionRequests++;
+        ++this.connectorsStatus.get(connectorId).acceptedStopTransactionRequests;
       } else {
-        this.connectorsStatus.get(connectorId).rejectedStopTransactionRequests++;
+        ++this.connectorsStatus.get(connectorId).rejectedStopTransactionRequests;
       }
     } else {
       const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId;
@@ -469,12 +468,12 @@ export class AutomaticTransactionGenerator extends AsyncResource {
     connectorId: number,
     startResponse: StartTransactionResponse
   ): void {
-    this.connectorsStatus.get(connectorId).startTransactionRequests++;
+    ++this.connectorsStatus.get(connectorId).startTransactionRequests;
     if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
-      this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests++;
+      ++this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests;
     } else {
       logger.warn(`${this.logPrefix(connectorId)} start transaction rejected`);
-      this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++;
+      ++this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests;
     }
   }
 }
index 3c049c068e10ed1f21b2c3be95d12d5fa0532eeb..3eab1fc815956f94ae481f4bc2929206512a53aa 100644 (file)
@@ -831,12 +831,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 {
+      ...Constants.DEFAULT_ATG_CONFIGURATION,
+      ...automaticTransactionGeneratorConfiguration,
+    };
   }
 
   public startAutomaticTransactionGenerator(connectorIds?: number[]): void {
@@ -1878,7 +1888,7 @@ export class ChargingStation {
             skipBufferingOnError: true,
           });
           if (this.isRegistered() === false) {
-            this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
+            this.getRegistrationMaxRetries() !== -1 && ++registrationRetryCount;
             await Utils.sleep(
               this?.bootNotificationResponse?.interval
                 ? this.bootNotificationResponse.interval * 1000
@@ -2440,7 +2450,7 @@ export class ChargingStation {
       this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries() ||
       this.getAutoReconnectMaxRetries() === -1
     ) {
-      this.autoReconnectRetryCount++;
+      ++this.autoReconnectRetryCount;
       const reconnectDelay = this.getReconnectExponentialDelay()
         ? Utils.exponentialDelay(this.autoReconnectRetryCount)
         : this.getConnectionTimeout() * 1000;
index a329eb53c9383cefce2a7aca2c2c788c29ba88ce..f86c5d783b82657c483183f9bf43c562e2c11de1 100644 (file)
@@ -161,18 +161,10 @@ export class ChargingStationUtils {
       throw new BaseError(errorMsg);
     }
     if (Utils.isEmptyObject(stationTemplate.AutomaticTransactionGenerator)) {
-      stationTemplate.AutomaticTransactionGenerator = {
-        enable: false,
-        minDuration: 60,
-        maxDuration: 120,
-        minDelayBetweenTwoTransactions: 15,
-        maxDelayBetweenTwoTransactions: 30,
-        probabilityOfStart: 1,
-        stopAfterHours: 0.3,
-        stopOnConnectionFailure: true,
-      };
+      stationTemplate.AutomaticTransactionGenerator = Constants.DEFAULT_ATG_CONFIGURATION;
       logger.warn(
-        `${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default values`
+        `${logPrefix} Empty automatic transaction generator configuration from template file ${templateFile}, set to default: %j`,
+        Constants.DEFAULT_ATG_CONFIGURATION
       );
     }
     if (
index 25d62962fbed2dcad29ec0fe6e0064fb1b0e0cdd..b66cd8a09d21ca9179361c8232babe6e7f1c76c3 100644 (file)
@@ -47,7 +47,7 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel {
     } else if (
       this.responses.get(uuid)?.responsesReceived <= this.responses.get(uuid)?.responsesExpected
     ) {
-      this.responses.get(uuid).responsesReceived++;
+      ++this.responses.get(uuid).responsesReceived;
       this.responses.get(uuid)?.responses.push(responsePayload);
     }
     if (
index 80ed03b61bc6de9adede1d450464473d512eb4f8..1999473d74690e03fce39af5a261d44b450c5930 100644 (file)
@@ -612,7 +612,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
         }#${transactionConnectorId.toString()} for idTag '${requestPayload.idTag}'`
       );
       if (chargingStation.stationInfo.powerSharedByConnectors) {
-        chargingStation.powerDivider++;
+        ++chargingStation.powerDivider;
       }
       const configuredMeterValueSampleInterval =
         ChargingStationConfigurationUtils.getConfigurationKey(
index 587532b7cf09c6e4729876a961c91c341730e723..61ef1b012946319ac1080fac1d9ca89b672fefd9 100644 (file)
@@ -78,7 +78,7 @@ export class PerformanceStatistics {
           this.statistics.statisticsData.has(command) &&
           this.statistics.statisticsData.get(command)?.countRequest
         ) {
-          this.statistics.statisticsData.get(command).countRequest++;
+          ++this.statistics.statisticsData.get(command).countRequest;
         } else {
           this.statistics.statisticsData.set(command, {
             ...this.statistics.statisticsData.get(command),
@@ -91,7 +91,7 @@ export class PerformanceStatistics {
           this.statistics.statisticsData.has(command) &&
           this.statistics.statisticsData.get(command)?.countResponse
         ) {
-          this.statistics.statisticsData.get(command).countResponse++;
+          ++this.statistics.statisticsData.get(command).countResponse;
         } else {
           this.statistics.statisticsData.set(command, {
             ...this.statistics.statisticsData.get(command),
@@ -104,7 +104,7 @@ export class PerformanceStatistics {
           this.statistics.statisticsData.has(command) &&
           this.statistics.statisticsData.get(command)?.countError
         ) {
-          this.statistics.statisticsData.get(command).countError++;
+          ++this.statistics.statisticsData.get(command).countError;
         } else {
           this.statistics.statisticsData.set(command, {
             ...this.statistics.statisticsData.get(command),
index 6c641cf62da79416498fd2149380d1d17223b4f7..bb765c75dcf8f00d6ed766c1c1f8ccdcd1592357 100644 (file)
@@ -1,3 +1,5 @@
+import type { AutomaticTransactionGeneratorConfiguration } from '../types';
+
 export class Constants {
   static readonly DEFAULT_BOOT_NOTIFICATION_INTERVAL = 60000; // Ms
   static readonly DEFAULT_HEARTBEAT_INTERVAL = 60000; // Ms
@@ -5,7 +7,18 @@ export class Constants {
 
   static readonly CHARGING_STATION_DEFAULT_RESET_TIME = 60000; // Ms
   static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000; // Ms
-  static readonly CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS = 0.25; // Hours
+
+  static readonly DEFAULT_ATG_CONFIGURATION: AutomaticTransactionGeneratorConfiguration =
+    Object.freeze({
+      enable: false,
+      minDuration: 60,
+      maxDuration: 120,
+      minDelayBetweenTwoTransactions: 15,
+      maxDelayBetweenTwoTransactions: 30,
+      probabilityOfStart: 1,
+      stopAfterHours: 0.25,
+      stopOnConnectionFailure: true,
+    });
 
   // See https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
   static readonly SEMVER_PATTERN =
index eaa19ac8f384ed5ce591362696e13bfdf765ab5a..513efb506f7a8f6f5cddaba641ec8e771fc10955 100644 (file)
@@ -55,7 +55,7 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
       id: WorkerMessageEvents.startWorkerElement,
       data: elementData,
     });
-    this.getLastWorkerSetElement().numberOfWorkerElements++;
+    ++this.getLastWorkerSetElement().numberOfWorkerElements;
     // Start element sequentially to optimize memory at startup
     if (this.workerOptions.elementStartDelay > 0) {
       await WorkerUtils.sleep(this.workerOptions.elementStartDelay);