build(simulator): apply updates
[e-mobility-charging-stations-simulator.git] / src / charging-station / IdTagsCache.ts
index 7b49b590d17332a47bc17cbe077ebe664b16b7f0..e5d28181b043de2f7faf1f0f9a71d6dbf6ef44df 100644 (file)
@@ -32,7 +32,7 @@ export class IdTagsCache {
     connectorId: number
   ): string {
     const hashId = chargingStation.stationInfo.hashId;
-    const idTagsFile = ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo);
+    const idTagsFile = ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo);
     switch (distribution) {
       case IdTagDistribution.RANDOM:
         return this.getRandomIdTag(hashId, idTagsFile);
@@ -58,7 +58,7 @@ export class IdTagsCache {
 
   private getRandomIdTag(hashId: string, file: string): string {
     const idTags = this.getIdTags(file);
-    const addressableKey = file + hashId;
+    const addressableKey = this.getIdTagsCacheIndexesAddressableKey(file, hashId);
     this.idTagsCachesAddressableIndexes.set(
       addressableKey,
       Math.floor(Utils.secureRandom() * idTags.length)
@@ -68,7 +68,7 @@ export class IdTagsCache {
 
   private getRoundRobinIdTag(hashId: string, file: string): string {
     const idTags = this.getIdTags(file);
-    const addressableKey = file + hashId;
+    const addressableKey = this.getIdTagsCacheIndexesAddressableKey(file, hashId);
     const idTagIndex = this.idTagsCachesAddressableIndexes.get(addressableKey) ?? 0;
     const idTag = idTags[idTagIndex];
     this.idTagsCachesAddressableIndexes.set(
@@ -79,10 +79,12 @@ export class IdTagsCache {
   }
 
   private getConnectorAffinityIdTag(chargingStation: ChargingStation, connectorId: number): string {
-    const file = ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo);
+    const file = ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo);
     const idTags = this.getIdTags(file);
-    const hashId = chargingStation.stationInfo.hashId;
-    const addressableKey = file + hashId;
+    const addressableKey = this.getIdTagsCacheIndexesAddressableKey(
+      file,
+      chargingStation.stationInfo.hashId
+    );
     this.idTagsCachesAddressableIndexes.set(
       addressableKey,
       (chargingStation.index - 1 + (connectorId - 1)) % idTags.length
@@ -144,6 +146,10 @@ export class IdTagsCache {
     }
   }
 
+  private getIdTagsCacheIndexesAddressableKey(prefix: string, uid: string): string {
+    return `${prefix}${uid}`;
+  }
+
   private getIdTagsFromFile(file: string): string[] {
     let idTags: string[] = [];
     if (file) {