From 996759d0013baf0fd2f106bfccc8ce7ab444dece Mon Sep 17 00:00:00 2001 From: sbriat Date: Tue, 19 Sep 2023 14:59:31 +0200 Subject: [PATCH] add schedule in candidate --- .../selector/passenger-oriented.selector.ts | 18 ++++- src/modules/ad/core/domain/candidate.types.ts | 5 ++ .../unit/core/algorithm.abstract.spec.ts | 14 ++++ .../tests/unit/core/candidate.entity.spec.ts | 70 +++++++++++++++++++ ...er-oriented-carpool-path-completer.spec.ts | 28 ++++++++ .../passenger-oriented-geo-filter.spec.ts | 14 ++++ .../tests/unit/core/route.completer.spec.ts | 14 ++++ 7 files changed, 162 insertions(+), 1 deletion(-) diff --git a/src/modules/ad/core/application/queries/match/selector/passenger-oriented.selector.ts b/src/modules/ad/core/application/queries/match/selector/passenger-oriented.selector.ts index 9b70919..7768fba 100644 --- a/src/modules/ad/core/application/queries/match/selector/passenger-oriented.selector.ts +++ b/src/modules/ad/core/application/queries/match/selector/passenger-oriented.selector.ts @@ -1,10 +1,10 @@ import { Frequency, Role } from '@modules/ad/core/domain/ad.types'; import { Selector } from '../algorithm.abstract'; -import { ScheduleItem } from '../match.query'; import { Waypoint } from '../../../types/waypoint.type'; import { Point } from '../../../types/point.type'; import { CandidateEntity } from '@modules/ad/core/domain/candidate.entity'; import { AdEntity } from '@modules/ad/core/domain/ad.entity'; +import { ScheduleItem } from '@modules/ad/core/domain/value-objects/schedule-item.value-object'; export class PassengerOrientedSelector extends Selector { select = async (): Promise => { @@ -60,6 +60,22 @@ export class PassengerOrientedSelector extends Selector { adsRole.role == Role.PASSENGER ? (adEntity.getProps().driverDuration as number) : (this.query.driverRoute?.duration as number), + driverSchedule: + adsRole.role == Role.PASSENGER + ? adEntity.getProps().schedule + : this.query.schedule.map((scheduleItem: ScheduleItem) => ({ + day: scheduleItem.day as number, + time: scheduleItem.time, + margin: scheduleItem.margin as number, + })), + passengerSchedule: + adsRole.role == Role.DRIVER + ? adEntity.getProps().schedule + : this.query.schedule.map((scheduleItem: ScheduleItem) => ({ + day: scheduleItem.day as number, + time: scheduleItem.time, + margin: scheduleItem.margin as number, + })), spacetimeDetourRatio: { maxDistanceDetourRatio: this.query .maxDetourDistanceRatio as number, diff --git a/src/modules/ad/core/domain/candidate.types.ts b/src/modules/ad/core/domain/candidate.types.ts index d466a2f..c387860 100644 --- a/src/modules/ad/core/domain/candidate.types.ts +++ b/src/modules/ad/core/domain/candidate.types.ts @@ -1,5 +1,6 @@ import { Role } from './ad.types'; import { PointProps } from './value-objects/point.value-object'; +import { ScheduleItemProps } from './value-objects/schedule-item.value-object'; import { WayStepProps } from './value-objects/waystep.value-object'; // All properties that a Candidate has @@ -12,6 +13,8 @@ export interface CandidateProps { carpoolSteps?: WayStepProps[]; // carpool path for the crew (driver + passenger) distance?: number; duration?: number; + driverSchedule: ScheduleItemProps[]; + passengerSchedule: ScheduleItemProps[]; spacetimeDetourRatio: SpacetimeDetourRatio; } @@ -23,6 +26,8 @@ export interface CreateCandidateProps { driverDuration: number; driverWaypoints: PointProps[]; passengerWaypoints: PointProps[]; + driverSchedule: ScheduleItemProps[]; + passengerSchedule: ScheduleItemProps[]; spacetimeDetourRatio: SpacetimeDetourRatio; } diff --git a/src/modules/ad/tests/unit/core/algorithm.abstract.spec.ts b/src/modules/ad/tests/unit/core/algorithm.abstract.spec.ts index 9c0c01d..c9757ce 100644 --- a/src/modules/ad/tests/unit/core/algorithm.abstract.spec.ts +++ b/src/modules/ad/tests/unit/core/algorithm.abstract.spec.ts @@ -89,6 +89,20 @@ class SomeSelector extends Selector { ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, diff --git a/src/modules/ad/tests/unit/core/candidate.entity.spec.ts b/src/modules/ad/tests/unit/core/candidate.entity.spec.ts index fcf52c7..c70d573 100644 --- a/src/modules/ad/tests/unit/core/candidate.entity.spec.ts +++ b/src/modules/ad/tests/unit/core/candidate.entity.spec.ts @@ -31,6 +31,20 @@ describe('Candidate entity', () => { ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, @@ -64,6 +78,20 @@ describe('Candidate entity', () => { ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, @@ -130,6 +158,20 @@ describe('Candidate entity', () => { ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, @@ -164,6 +206,20 @@ describe('Candidate entity', () => { ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, @@ -197,6 +253,20 @@ describe('Candidate entity', () => { ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, diff --git a/src/modules/ad/tests/unit/core/passenger-oriented-carpool-path-completer.spec.ts b/src/modules/ad/tests/unit/core/passenger-oriented-carpool-path-completer.spec.ts index b1235e3..a7f0a90 100644 --- a/src/modules/ad/tests/unit/core/passenger-oriented-carpool-path-completer.spec.ts +++ b/src/modules/ad/tests/unit/core/passenger-oriented-carpool-path-completer.spec.ts @@ -72,6 +72,20 @@ const candidates: CandidateEntity[] = [ ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, @@ -102,6 +116,20 @@ const candidates: CandidateEntity[] = [ ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, diff --git a/src/modules/ad/tests/unit/core/passenger-oriented-geo-filter.spec.ts b/src/modules/ad/tests/unit/core/passenger-oriented-geo-filter.spec.ts index 331183c..1155369 100644 --- a/src/modules/ad/tests/unit/core/passenger-oriented-geo-filter.spec.ts +++ b/src/modules/ad/tests/unit/core/passenger-oriented-geo-filter.spec.ts @@ -71,6 +71,20 @@ const candidate: CandidateEntity = CandidateEntity.create({ ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3, diff --git a/src/modules/ad/tests/unit/core/route.completer.spec.ts b/src/modules/ad/tests/unit/core/route.completer.spec.ts index 5aff29e..b64cdf1 100644 --- a/src/modules/ad/tests/unit/core/route.completer.spec.ts +++ b/src/modules/ad/tests/unit/core/route.completer.spec.ts @@ -91,6 +91,20 @@ const candidate: CandidateEntity = CandidateEntity.create({ ], driverDistance: 350145, driverDuration: 13548, + driverSchedule: [ + { + day: 0, + time: '07:00', + margin: 900, + }, + ], + passengerSchedule: [ + { + day: 0, + time: '07:10', + margin: 900, + }, + ], spacetimeDetourRatio: { maxDistanceDetourRatio: 0.3, maxDurationDetourRatio: 0.3,