improve creation of schedules
This commit is contained in:
parent
100fb3487d
commit
0446d267ef
|
@ -96,40 +96,50 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
|||
* Create the driver schedule based on the passenger schedule
|
||||
*/
|
||||
private _createDriverSchedule = (): void => {
|
||||
let driverSchedule: ScheduleItemProps[] = this.props.passengerSchedule!.map(
|
||||
(scheduleItemProps: ScheduleItemProps) => ({
|
||||
day: scheduleItemProps.day,
|
||||
time: scheduleItemProps.time,
|
||||
margin: scheduleItemProps.margin,
|
||||
}),
|
||||
);
|
||||
let driverSchedule: Array<ScheduleItemProps | undefined> =
|
||||
this.props.passengerSchedule!.map(
|
||||
(scheduleItemProps: ScheduleItemProps) => ({
|
||||
day: scheduleItemProps.day,
|
||||
time: scheduleItemProps.time,
|
||||
margin: scheduleItemProps.margin,
|
||||
}),
|
||||
);
|
||||
// adjust the driver theoretical schedule :
|
||||
// we guess the ideal driver departure time based on the duration to
|
||||
// reach the passenger starting point from the driver starting point
|
||||
driverSchedule = driverSchedule.map(
|
||||
(scheduleItemProps: ScheduleItemProps) => {
|
||||
const driverDate: Date = CalendarTools.firstDate(
|
||||
scheduleItemProps.day,
|
||||
this.props.dateInterval,
|
||||
);
|
||||
const driverStartDatetime: Date = CalendarTools.datetimeWithSeconds(
|
||||
driverDate,
|
||||
scheduleItemProps.time,
|
||||
-this._passengerStartDuration(),
|
||||
);
|
||||
return {
|
||||
day: driverDate.getUTCDay(),
|
||||
margin: scheduleItemProps.margin,
|
||||
time: `${driverStartDatetime
|
||||
.getUTCHours()
|
||||
.toString()
|
||||
.padStart(2, '0')}:${driverStartDatetime
|
||||
.getUTCMinutes()
|
||||
.toString()
|
||||
.padStart(2, '0')}`,
|
||||
};
|
||||
},
|
||||
);
|
||||
driverSchedule = driverSchedule
|
||||
.map((scheduleItemProps: ScheduleItemProps) => {
|
||||
try {
|
||||
const driverDate: Date = CalendarTools.firstDate(
|
||||
scheduleItemProps.day,
|
||||
this.props.dateInterval,
|
||||
);
|
||||
const driverStartDatetime: Date = CalendarTools.datetimeWithSeconds(
|
||||
driverDate,
|
||||
scheduleItemProps.time,
|
||||
-this._passengerStartDuration(),
|
||||
);
|
||||
return <ScheduleItemProps>{
|
||||
day: driverDate.getUTCDay(),
|
||||
margin: scheduleItemProps.margin,
|
||||
time: `${driverStartDatetime
|
||||
.getUTCHours()
|
||||
.toString()
|
||||
.padStart(2, '0')}:${driverStartDatetime
|
||||
.getUTCMinutes()
|
||||
.toString()
|
||||
.padStart(2, '0')}`,
|
||||
};
|
||||
} catch (e) {
|
||||
// no possible driver date or time
|
||||
// TODO : find a test case !
|
||||
return undefined;
|
||||
}
|
||||
})
|
||||
.filter(
|
||||
(scheduleItemProps: ScheduleItemProps | undefined) =>
|
||||
scheduleItemProps !== undefined,
|
||||
);
|
||||
this.props.driverSchedule = driverSchedule.map(
|
||||
(scheduleItemProps: ScheduleItemProps) => ({
|
||||
day: scheduleItemProps.day,
|
||||
|
@ -159,40 +169,50 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
|||
* Create the passenger schedule based on the driver schedule
|
||||
*/
|
||||
private _createPassengerSchedule = (): void => {
|
||||
let passengerSchedule: ScheduleItemProps[] = this.props.driverSchedule!.map(
|
||||
(scheduleItemProps: ScheduleItemProps) => ({
|
||||
day: scheduleItemProps.day,
|
||||
time: scheduleItemProps.time,
|
||||
margin: scheduleItemProps.margin,
|
||||
}),
|
||||
);
|
||||
let passengerSchedule: Array<ScheduleItemProps | undefined> =
|
||||
this.props.driverSchedule!.map(
|
||||
(scheduleItemProps: ScheduleItemProps) => ({
|
||||
day: scheduleItemProps.day,
|
||||
time: scheduleItemProps.time,
|
||||
margin: scheduleItemProps.margin,
|
||||
}),
|
||||
);
|
||||
// adjust the passenger theoretical schedule :
|
||||
// we guess the ideal passenger departure time based on the duration to
|
||||
// reach the passenger starting point from the driver starting point
|
||||
passengerSchedule = passengerSchedule.map(
|
||||
(scheduleItemProps: ScheduleItemProps) => {
|
||||
const passengerDate: Date = CalendarTools.firstDate(
|
||||
scheduleItemProps.day,
|
||||
this.props.dateInterval,
|
||||
);
|
||||
const passengeStartDatetime: Date = CalendarTools.datetimeWithSeconds(
|
||||
passengerDate,
|
||||
scheduleItemProps.time,
|
||||
this._passengerStartDuration(),
|
||||
);
|
||||
return {
|
||||
day: passengerDate.getUTCDay(),
|
||||
margin: scheduleItemProps.margin,
|
||||
time: `${passengeStartDatetime
|
||||
.getUTCHours()
|
||||
.toString()
|
||||
.padStart(2, '0')}:${passengeStartDatetime
|
||||
.getUTCMinutes()
|
||||
.toString()
|
||||
.padStart(2, '0')}`,
|
||||
};
|
||||
},
|
||||
);
|
||||
passengerSchedule = passengerSchedule
|
||||
.map((scheduleItemProps: ScheduleItemProps) => {
|
||||
try {
|
||||
const passengerDate: Date = CalendarTools.firstDate(
|
||||
scheduleItemProps.day,
|
||||
this.props.dateInterval,
|
||||
);
|
||||
const passengeStartDatetime: Date = CalendarTools.datetimeWithSeconds(
|
||||
passengerDate,
|
||||
scheduleItemProps.time,
|
||||
this._passengerStartDuration(),
|
||||
);
|
||||
return {
|
||||
day: passengerDate.getUTCDay(),
|
||||
margin: scheduleItemProps.margin,
|
||||
time: `${passengeStartDatetime
|
||||
.getUTCHours()
|
||||
.toString()
|
||||
.padStart(2, '0')}:${passengeStartDatetime
|
||||
.getUTCMinutes()
|
||||
.toString()
|
||||
.padStart(2, '0')}`,
|
||||
};
|
||||
} catch (e) {
|
||||
// no possible passenger date or time
|
||||
// TODO : find a test case !
|
||||
return undefined;
|
||||
}
|
||||
})
|
||||
.filter(
|
||||
(scheduleItemProps: ScheduleItemProps | undefined) =>
|
||||
scheduleItemProps !== undefined,
|
||||
);
|
||||
this.props.passengerSchedule = passengerSchedule.map(
|
||||
(scheduleItemProps: ScheduleItemProps) => ({
|
||||
day: scheduleItemProps.day,
|
||||
|
|
Loading…
Reference in New Issue