From: Jérôme Benoit Date: Mon, 31 Jul 2023 22:02:34 +0000 (+0200) Subject: refactor: cleanup reservation code helpers X-Git-Tag: v1.2.20~52 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=cfc9875aed1b5e773f4baaa30574f1a06534f566;p=e-mobility-charging-stations-simulator.git refactor: cleanup reservation code helpers Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 5f4f58b4..d08079c8 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -419,7 +419,7 @@ export class ChargingStation { } public getNumberOfRunningTransactions(): number { - let trxCount = 0; + let numberOfRunningTransactions = 0; if (this.hasEvses) { for (const [evseId, evseStatus] of this.evses) { if (evseId === 0) { @@ -427,18 +427,18 @@ export class ChargingStation { } for (const connectorStatus of evseStatus.connectors.values()) { if (connectorStatus.transactionStarted === true) { - ++trxCount; + ++numberOfRunningTransactions; } } } } else { for (const connectorId of this.connectors.keys()) { if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) { - ++trxCount; + ++numberOfRunningTransactions; } } } - return trxCount; + return numberOfRunningTransactions; } public getOutOfOrderEndMeterValues(): boolean { @@ -1074,15 +1074,14 @@ export class ChargingStation { } private getNumberOfReservationsOnConnectorZero(): number { - let numberOfReservations = 0; if ( // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (this.hasEvses && this.evses.get(0)?.connectors.get(0)?.reservation) || (!this.hasEvses && this.connectors.get(0)?.reservation) ) { - ++numberOfReservations; + return 1; } - return numberOfReservations; + return 0; } private flushMessageBuffer(): void { diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index d2b1b926..6d274251 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -118,16 +118,16 @@ export const removeExpiredReservations = async ( export const getNumberOfReservableConnectors = ( connectors: Map, ): number => { - let reservableConnectors = 0; + let numberOfReservableConnectors = 0; for (const [connectorId, connectorStatus] of connectors) { if (connectorId === 0) { continue; } if (connectorStatus.status === ConnectorStatusEnum.Available) { - ++reservableConnectors; + ++numberOfReservableConnectors; } } - return reservableConnectors; + return numberOfReservableConnectors; }; export const getHashId = (index: number, stationTemplate: ChargingStationTemplate): string => { @@ -257,7 +257,7 @@ export const checkConnectorsConfiguration = ( templateMaxConnectors: number; templateMaxAvailableConnectors: number; } => { - const configuredMaxConnectors = getConfiguredNumberOfConnectors(stationTemplate); + const configuredMaxConnectors = getConfiguredMaxNumberOfConnectors(stationTemplate); checkConfiguredMaxConnectors(configuredMaxConnectors, logPrefix, templateFile); const templateMaxConnectors = getMaxNumberOfConnectors(stationTemplate.Connectors!); checkTemplateMaxConnectors(templateMaxConnectors, logPrefix, templateFile); @@ -622,16 +622,16 @@ export const waitChargingStationEvents = async ( }); }; -const getConfiguredNumberOfConnectors = (stationTemplate: ChargingStationTemplate): number => { - let configuredMaxConnectors = 0; +const getConfiguredMaxNumberOfConnectors = (stationTemplate: ChargingStationTemplate): number => { + let configuredMaxNumberOfConnectors = 0; if (isNotEmptyArray(stationTemplate.numberOfConnectors) === true) { const numberOfConnectors = stationTemplate.numberOfConnectors as number[]; - configuredMaxConnectors = + configuredMaxNumberOfConnectors = numberOfConnectors[Math.floor(secureRandom() * numberOfConnectors.length)]; } else if (isUndefined(stationTemplate.numberOfConnectors) === false) { - configuredMaxConnectors = stationTemplate.numberOfConnectors as number; + configuredMaxNumberOfConnectors = stationTemplate.numberOfConnectors as number; } else if (stationTemplate.Connectors && !stationTemplate.Evses) { - configuredMaxConnectors = stationTemplate.Connectors[0] + configuredMaxNumberOfConnectors = stationTemplate.Connectors[0] ? getMaxNumberOfConnectors(stationTemplate.Connectors) - 1 : getMaxNumberOfConnectors(stationTemplate.Connectors); } else if (stationTemplate.Evses && !stationTemplate.Connectors) { @@ -639,10 +639,12 @@ const getConfiguredNumberOfConnectors = (stationTemplate: ChargingStationTemplat if (evse === '0') { continue; } - configuredMaxConnectors += getMaxNumberOfConnectors(stationTemplate.Evses[evse].Connectors); + configuredMaxNumberOfConnectors += getMaxNumberOfConnectors( + stationTemplate.Evses[evse].Connectors, + ); } } - return configuredMaxConnectors; + return configuredMaxNumberOfConnectors; }; const checkConfiguredMaxConnectors = (