Skip to content

Commit 27eabab

Browse files
ironyAlexander Czigler
andauthored
Feat/snackbar (#262)
* chore: correct path for mount (#128) * feat: add skåne gtfs feed * feat: add snackbar * Delete agency.txt * fix: autohide snackbar + less info msgs * chore: 3s timeout before closing * chore: remove skane data * feat: black bar instead * Feat/no line shapes (#266) * chore: correct path for mount (#128) * feat: add skåne gtfs feed * feat: remove lineshapes and calculate them from trips * fix: remove skane, it's in cache * fix: remove subscriptions before starting new experiment * feat: move functionality to new menu (#263) * chore: do not bust cache on .gitignore * refactor: cleanup * feat: add layer toggles to new menu * refactor: cleanup * feat: edit experiment modal * chore: remove unused code * refactor: moved reset button to new component * fix: styling * refactor: move modal to new component * refactor: naming * fix: styling * refactor: cleaning up * fix: modal styling * feat: add logo * feat: show modal with kibana link * fix: naming * feat: show experiment id --------- Co-authored-by: Alexander Czigler <[email protected]>
1 parent ea65299 commit 27eabab

File tree

14 files changed

+61
-15
lines changed

14 files changed

+61
-15
lines changed

packages/simulator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ const {
88
} = require('rxjs/operators')
99

1010
const { virtualTime } = require('./lib/virtualTime')
11-
1211
const { safeId } = require('./lib/id')
1312
const { read } = require('./config')
1413
const statistics = require('./lib/statistics')
15-
const { info, error } = require('./lib/log')
14+
const { info, error, logStream } = require('./lib/log')
1615
const { haversine, getNrOfPointsBetween } = require('./lib/distance')
1716

1817
const engine = {
@@ -40,6 +39,7 @@ const engine = {
4039
statistics.collectExperimentMetadata(parameters)
4140

4241
const experiment = {
42+
logStream,
4343
busStops: regions.pipe(
4444
filter((region) => region.stops),
4545
mergeMap((region) => region.stops),

packages/simulator/lib/dispatch/busDispatch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const busDispatch = async (buses, trips) => {
7070

7171
const kommunName = trips[0].kommun
7272
info(
73-
`Calling vroom for ${kommunName} with ${vehicles.length} buses and ${shipments.length} trips`
73+
`Finding optimal route in ${kommunName} for ${vehicles.length} buses and ${shipments.length} trips`
7474
)
7575

7676
const result = await plan({

packages/simulator/lib/dispatch/dispatchCentral.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
retryWhen,
1010
toArray,
1111
} = require('rxjs/operators')
12-
const { info, error, warn } = require('../log')
12+
const { info, error, warn, debug } = require('../log')
1313
const { clusterPositions } = require('../kmeans')
1414

1515
const dispatch = (cars, bookings) => {
@@ -52,7 +52,7 @@ const dispatch = (cars, bookings) => {
5252
mergeAll(),
5353
filter(({ bookings }) => bookings.length > 0),
5454
tap(({ car, bookings }) =>
55-
info(
55+
debug(
5656
`Plan ${car.id} (${car.fleet.name}) received ${bookings.length} bookings`
5757
)
5858
),

packages/simulator/lib/dispatch/taxiDispatch.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
const { plan, taxiToVehicle, bookingToShipment } = require('../vroom')
22
const moment = require('moment')
3-
const { error, debug, write } = require('../log')
3+
const { error, debug, write, info } = require('../log')
44
const { virtualTime } = require('../virtualTime')
55

66
const taxiDispatch = async (taxis, bookings) => {
77
const vehicles = taxis.map(taxiToVehicle)
88
const shipments = bookings.map(bookingToShipment) // TODO: concat bookings from existing vehicles with previous assignments
9-
debug('Calling vroom for taxi', vehicles.length, shipments.length)
9+
info(
10+
`Finding optimal route for ${vehicles.length} taxis and ${shipments.length} pickups`
11+
)
1012
write('🚕')
1113
const result = await plan({ shipments, vehicles })
1214
const virtualNow = await virtualTime.getTimeInMillisecondsAsPromise()

packages/simulator/lib/log.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const chalk = require('chalk')
2+
const { ReplaySubject } = require('rxjs')
23

34
// eslint-disable-next-line no-undef
45
const LOG_LEVEL = process.env.LOG_LEVEL || 'info'
@@ -9,6 +10,8 @@ const logLevelIsAtLeastInfo =
910
const logLevelIsAtLeastWarn =
1011
LOG_LEVEL.toUpperCase() === 'WARN' || logLevelIsAtLeastInfo
1112

13+
const logStream = new ReplaySubject(10)
14+
1215
const print = (logFn, titleFn, messageFn, title, message, data, ...rest) => {
1316
if (data) {
1417
logFn(
@@ -23,6 +26,7 @@ const print = (logFn, titleFn, messageFn, title, message, data, ...rest) => {
2326
}
2427

2528
module.exports = {
29+
logStream,
2630
debug: (message, data, ...rest) => {
2731
if (logLevelIsAtLeastDebug) {
2832
print(
@@ -48,6 +52,10 @@ module.exports = {
4852
)
4953
},
5054
info: (message, data, ...rest) => {
55+
logStream.next(
56+
message + ' ' + [data, ...rest].map((x) => JSON.stringify(x)).join(' ')
57+
)
58+
5159
if (logLevelIsAtLeastInfo) {
5260
print(
5361
console.log,

packages/simulator/lib/queueSubject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { Subject, mergeMap, catchError, from } = require('rxjs')
22
const { debug, error } = require('./log')
33

4-
const API_CALL_LIMIT = 5
4+
const API_CALL_LIMIT = 3
55

66
const queueSubject = new Subject()
77

packages/simulator/lib/region.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ class Region {
176176
this.taxis.pipe(
177177
scan((acc, taxi) => acc.push(taxi) && acc, []),
178178
debounceTime(1000),
179-
tap((cars) => info('region taxis', cars.length)),
180179
filter((taxis) => taxis.length > 0),
181180
mergeMap((taxis) =>
182181
merge(this.manualBookings, this.unhandledBookings).pipe(

packages/simulator/lib/vehicles/truck.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { findBestRouteToPickupBookings } = require('../dispatch/truckDispatch')
2-
const { info, warn } = require('../log')
2+
const { info, warn, debug } = require('../log')
33
const Vehicle = require('./vehicle')
44

55
class Truck extends Vehicle {
@@ -53,7 +53,7 @@ class Truck extends Vehicle {
5353
if (this.cargo.indexOf(this.booking) > -1)
5454
return warn('Already picked up', this.id, this.booking.id)
5555

56-
info('Pickup cargo', this.id, this.booking.id)
56+
debug('Pickup cargo', this.id, this.booking.id)
5757
// this.cargo = [...this.cargo, this.booking?.passenger]
5858
this.cargo.push(this.booking)
5959
this.cargoEvents.next(this)

packages/simulator/lib/vroom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = {
6767
async plan({ jobs, shipments, vehicles }) {
6868
const result = await getFromCache({ jobs, shipments, vehicles })
6969
if (result) {
70-
info('Vroom cache hit')
70+
debug('Vroom cache hit')
7171
return result
7272
}
7373
debug('Vroom cache miss')

packages/simulator/simulator/citizens.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const getCitizensInSquare = (
99
workplaces,
1010
kommunName
1111
) => {
12-
const nrOfCitizens = Math.floor(population * 0.01) // sample x% of the population
12+
const nrOfCitizens = Math.floor(population * 0.001) // sample x% of the population
1313
if (nrOfCitizens === 0) return from([])
1414
const addresses = from(getAddressesInArea(position, area, nrOfCitizens)).pipe(
1515
mergeAll()

0 commit comments

Comments
 (0)