Skip to content

Commit 3d4392f

Browse files
authored
Feat/to pickup (#256)
* feat: toPickup status * fix: remove simulated loadingtime, it seems to create weird behavior
1 parent 31e45e9 commit 3d4392f

File tree

6 files changed

+21
-32
lines changed

6 files changed

+21
-32
lines changed

packages/simulator/lib/dispatch/dispatchCentral.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const dispatch = (cars, bookings) => {
6565
filter((cars) => cars.length > 0),
6666
mergeMap((cars) =>
6767
bookings.pipe(
68+
filter((booking) => !booking.car),
6869
bufferTime(5000),
6970
filter((b) => b.length > 0),
7071
//mergeMap((bookings) => getVroomPlan(cars, bookings)),

packages/simulator/lib/vehicles/bus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Bus extends Vehicle {
4343
if (!this.booking) {
4444
this.booking = booking
4545
booking.assign(this)
46-
this.status = 'pickup'
46+
this.status = 'toPickup'
4747
await this.navigateTo(booking.destination.position)
4848
this.movedEvents.next(this)
4949
} else {

packages/simulator/lib/vehicles/taxi.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ class Taxi extends Vehicle {
4343
switch (this.status) {
4444
case 'pickup':
4545
await virtualTime.waitUntil(this.instruction.arrival)
46+
this.status = 'toPickup'
4647
return this.navigateTo(this.booking.pickup.position)
4748
case 'delivery':
49+
this.status = 'toDelivery'
4850
await virtualTime.waitUntil(this.instruction.arrival)
4951
return this.navigateTo(this.booking.destination.position)
5052
case 'returning':

packages/simulator/lib/vehicles/truck.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ class Truck extends Vehicle {
2525
case 'start':
2626
return this.navigateTo(this.startPosition)
2727
case 'pickup':
28+
this.status = 'toPickup'
2829
return this.navigateTo(this.booking.pickup.position)
2930
case 'delivery':
31+
this.status = 'toDelivery'
3032
return this.navigateTo(this.booking.destination.position)
3133
case 'ready':
3234
case 'returning':
@@ -46,7 +48,11 @@ class Truck extends Vehicle {
4648

4749
async pickup() {
4850
// Wait 1 minute to simulate loading/unloading
49-
await virtualTime.wait(60_000)
51+
// this.simulate(false) // pause interpolation while we wait
52+
// await virtualTime.wait(60_000)
53+
if (!this.booking) return info('ERR: No booking to pickup', this.id)
54+
if (this.cargo.indexOf(this.booking) > -1)
55+
return info('ERR: Already picked up', this.id, this.booking.id)
5056

5157
info('Pickup cargo', this.id, this.booking.id)
5258
// this.cargo = [...this.cargo, this.booking?.passenger]
@@ -63,6 +69,7 @@ class Truck extends Vehicle {
6369
}
6470

6571
async handleBooking(booking) {
72+
if (this.queue.indexOf(booking) > -1) throw new Error('Already queued')
6673
this.queue.push(booking)
6774
booking.assign(this)
6875
booking.queued(this)

packages/simulator/lib/vehicles/vehicle.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { ReplaySubject } = require('rxjs')
2-
const { scan } = require('rxjs/operators')
2+
const { scan, filter } = require('rxjs/operators')
33
const moment = require('moment')
44
const { assert } = require('console')
55

@@ -8,7 +8,7 @@ const { haversine, bearing } = require('../distance')
88
const interpolate = require('../interpolate')
99
const Booking = require('../models/booking')
1010
const { safeId } = require('../id')
11-
const { error } = require('../log')
11+
const { error, info } = require('../log')
1212
const { virtualTime } = require('../virtualTime')
1313
const Position = require('../models/position')
1414

@@ -142,7 +142,7 @@ class Vehicle {
142142
if (!this.booking) {
143143
this.booking = booking
144144
booking.assign(this)
145-
this.status = 'pickup'
145+
this.status = 'toPickup'
146146
this.statusEvents.next(this)
147147

148148
this.navigateTo(booking.pickup.position)
@@ -191,7 +191,7 @@ class Vehicle {
191191
})
192192
if (this.booking && this.booking.destination) {
193193
this.booking.pickedUp(this.position)
194-
this.status = 'delivery'
194+
this.status = 'toDelivery'
195195
this.statusEvents.next(this)
196196

197197
// should we first pickup more bookings before going to the destination?
@@ -300,13 +300,16 @@ class Vehicle {
300300
}
301301
}
302302

303+
// start -> toPickup -> pickup -> toDelivery -> delivery -> start
304+
303305
stopped() {
306+
info(`Vehicle ${this.id} stopped. Status: ${this.status}`)
304307
this.speed = 0
305308
this.statusEvents.next(this)
306309
if (this.booking) {
307310
this.simulate(false)
308-
if (this.status === 'pickup') return this.pickup()
309-
if (this.status === 'delivery') return this.dropOff()
311+
if (this.status === 'toPickup') return this.pickup()
312+
if (this.status === 'toDelivery') return this.dropOff()
310313
}
311314
}
312315

packages/visualisation/package-lock.json

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)