- const compositeScheduleStart: Date = min(
- chargingProfiles.map(
- (chargingProfile) => chargingProfile.chargingSchedule.startSchedule ?? maxTime,
- ),
- );
- const compositeScheduleDuration: number = Math.max(
- ...chargingProfiles.map(
- (chargingProfile) => chargingProfile.chargingSchedule.duration ?? -Infinity,
- ),
- );
- // FIXME: remove overlapping charging schedule periods
- const compositeSchedulePeriods: OCPP16ChargingSchedulePeriod[] = chargingProfiles
- .map((chargingProfile) => chargingProfile.chargingSchedule.chargingSchedulePeriod)
- .reduce(
- (accumulator, value) =>
- accumulator.concat(value).sort((a, b) => a.startPeriod - b.startPeriod),
- [],
- );
- const compositeSchedule: OCPP16ChargingSchedule = {
- startSchedule: compositeScheduleStart,
- duration: compositeScheduleDuration,
- chargingRateUnit: chargingProfiles.every(
- (chargingProfile) =>
- chargingProfile.chargingSchedule.chargingRateUnit === OCPP16ChargingRateUnitType.AMPERE,
- )
- ? OCPP16ChargingRateUnitType.AMPERE
- : chargingProfiles.every(
- (chargingProfile) =>
- chargingProfile.chargingSchedule.chargingRateUnit === OCPP16ChargingRateUnitType.WATT,
- )
- ? OCPP16ChargingRateUnitType.WATT
- : OCPP16ChargingRateUnitType.AMPERE,
- chargingSchedulePeriod: compositeSchedulePeriods,
- minChargeRate: Math.min(
- ...chargingProfiles.map(
- (chargingProfile) => chargingProfile.chargingSchedule.minChargeRate ?? Infinity,
- ),
- ),
- };
- return {
- status: GenericStatus.Accepted,
- scheduleStart: compositeSchedule.startSchedule!,
- connectorId,
- chargingSchedule: compositeSchedule,
- };