refactor: cleanup imports
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index 033fc4b36f79647746106169fe462834d241e463..ab781fae3cb3382022abb8f61ed7b55f021e9ef0 100644 (file)
@@ -1,6 +1,6 @@
-import crypto from 'node:crypto';
-import type EventEmitter from 'node:events';
-import path from 'node:path';
+import { createHash, randomBytes } from 'node:crypto';
+import type { EventEmitter } from 'node:events';
+import { basename, dirname, join } from 'node:path';
 import { fileURLToPath } from 'node:url';
 
 import chalk from 'chalk';
@@ -55,6 +55,19 @@ export class ChargingStationUtils {
         )}${idSuffix}`;
   }
 
+  public static countReservableConnectors(connectors: Map<number, ConnectorStatus>) {
+    let reservableConnectors = 0;
+    for (const [connectorId, connectorStatus] of connectors) {
+      if (connectorId === 0) {
+        continue;
+      }
+      if (connectorStatus.status === ConnectorStatusEnum.Available) {
+        ++reservableConnectors;
+      }
+    }
+    return reservableConnectors;
+  }
+
   public static getHashId(index: number, stationTemplate: ChargingStationTemplate): string {
     const chargingStationInfo = {
       chargePointModel: stationTemplate.chargePointModel,
@@ -72,8 +85,7 @@ export class ChargingStationUtils {
         meterType: stationTemplate.meterType,
       }),
     };
-    return crypto
-      .createHash(Constants.DEFAULT_HASH_ALGORITHM)
+    return createHash(Constants.DEFAULT_HASH_ALGORITHM)
       .update(
         `${JSON.stringify(chargingStationInfo)}${ChargingStationUtils.getChargingStationId(
           index,
@@ -533,11 +545,7 @@ export class ChargingStationUtils {
   public static getIdTagsFile(stationInfo: ChargingStationInfo): string | undefined {
     return (
       stationInfo.idTagsFile &&
-      path.join(
-        path.dirname(fileURLToPath(import.meta.url)),
-        'assets',
-        path.basename(stationInfo.idTagsFile)
-      )
+      join(dirname(fileURLToPath(import.meta.url)), 'assets', basename(stationInfo.idTagsFile))
     );
   }
 
@@ -765,9 +773,7 @@ export class ChargingStationUtils {
     randomBytesLength?: number;
     upperCase?: boolean;
   }): string {
-    const randomSerialNumberSuffix = crypto
-      .randomBytes(params?.randomBytesLength ?? 16)
-      .toString('hex');
+    const randomSerialNumberSuffix = randomBytes(params?.randomBytesLength ?? 16).toString('hex');
     if (params?.upperCase) {
       return randomSerialNumberSuffix.toUpperCase();
     }