From: Jérôme Benoit Date: Tue, 25 Jul 2023 20:54:13 +0000 (+0200) Subject: refactor: cleanup log messages X-Git-Tag: v1.2.20~140 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=991fb26bd3814b583395f5d2623acfae7a3ee3f0;p=e-mobility-charging-stations-simulator.git refactor: cleanup log messages Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 1af12661..de29639b 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -712,7 +712,7 @@ const getLimitFromChargingProfiles = ( logger.warn( `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: startSchedule is not a Date object in charging profile id ${chargingProfile.chargingProfileId}. Trying to convert it to a Date object`, ); - chargingSchedule.startSchedule = convertToDate(chargingSchedule.startSchedule)!; + chargingSchedule.startSchedule = convertToDate(chargingSchedule?.startSchedule)!; } if ( chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING && @@ -733,7 +733,7 @@ const getLimitFromChargingProfiles = ( } // Check if the charging profile is active if ( - isValidDate(chargingSchedule.startSchedule) && + isValidDate(chargingSchedule?.startSchedule) && isWithinInterval(currentDate, { start: chargingSchedule.startSchedule!, end: addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), @@ -762,7 +762,7 @@ const getLimitFromChargingProfiles = ( ); continue; } - // Handling of only one schedule period + // Handle only one schedule period if (chargingSchedule.chargingSchedulePeriod.length === 1) { const result: ChargingProfilesLimit = { limit: chargingSchedule.chargingSchedulePeriod[0].limit, @@ -840,10 +840,10 @@ const prepareRecurringChargingProfile = ( checkRecurringChargingProfileDuration(chargingProfile, recurringInterval, logPrefix); if ( !isWithinInterval(currentDate, recurringInterval) && - isBefore(chargingSchedule.startSchedule!, currentDate) + isBefore(recurringInterval.end, currentDate) ) { chargingSchedule.startSchedule = addDays( - chargingSchedule.startSchedule!, + recurringInterval.start, differenceInDays(currentDate, recurringInterval.start), ); recurringInterval = { @@ -860,10 +860,10 @@ const prepareRecurringChargingProfile = ( checkRecurringChargingProfileDuration(chargingProfile, recurringInterval, logPrefix); if ( !isWithinInterval(currentDate, recurringInterval) && - isBefore(chargingSchedule.startSchedule!, currentDate) + isBefore(recurringInterval.end, currentDate) ) { chargingSchedule.startSchedule = addWeeks( - chargingSchedule.startSchedule!, + recurringInterval.start, differenceInWeeks(currentDate, recurringInterval.start), ); recurringInterval = { @@ -877,11 +877,11 @@ const prepareRecurringChargingProfile = ( logger.error( `${logPrefix} ${moduleName}.prepareRecurringChargingProfile: Recurring ${ chargingProfile.recurrencyKind - } charging profile id ${ - chargingProfile.chargingProfileId - } startSchedule ${chargingSchedule.startSchedule!.toISOString()} is not properly translated to current recurrency time interval [${toDate( + } charging profile id ${chargingProfile.chargingProfileId} recurrency time interval [${toDate( recurringInterval!.start, - ).toISOString()}, ${toDate(recurringInterval!.end).toISOString()}]`, + ).toISOString()}, ${toDate( + recurringInterval!.end, + ).toISOString()}] is not properly translated to current date ${currentDate.toISOString()} `, ); } }; diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index b2f1c400..e3899cd5 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -37,6 +37,7 @@ import { DCElectricUtils, convertToFloat, convertToInt, + formatDurationMilliSeconds, getRandomFloatFluctuatedRounded, getRandomFloatRounded, getRandomInteger, @@ -726,10 +727,9 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${roundTo( - interval / (3600 * 1000), - 4, - )}h`, + }: connector id ${connectorId}, transaction id ${connector?.transactionId}, value: ${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${formatDurationMilliSeconds( + interval, + )}(${roundTo(interval, 4)}ms)`, ); } } diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 14869b0d..54b07510 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -355,9 +355,9 @@ export const getWebSocketCloseEventStatusString = (code: number): string => { return '(Unknown)'; }; -export const isArraySorted = (elements: T[], compareFn: (a: T, b: T) => number): boolean => { - for (let i = 0; i < elements.length - 1; ++i) { - if (compareFn(elements[i], elements[i + 1]) > 0) { +export const isArraySorted = (array: T[], compareFn: (a: T, b: T) => number): boolean => { + for (let index = 0; index < array.length - 1; ++index) { + if (compareFn(array[index], array[index + 1]) > 0) { return false; } }