Skip to content

Commit a839cef

Browse files
authored
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
1 parent a00d423 commit a839cef

File tree

5 files changed

+19
-65
lines changed

5 files changed

+19
-65
lines changed

packages/simulator/lib/region.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const tripsInKommun = (kommuner) => (stops) =>
5555
),
5656
map(({ name }) => ({
5757
tripId: firstStop.tripId,
58+
lineNumber: stops[0].lineNumber,
5859
stops,
5960
firstStop,
6061
lastStop,
@@ -65,7 +66,7 @@ const tripsInKommun = (kommuner) => (stops) =>
6566
)
6667

6768
class Region {
68-
constructor({ id, name, geometry, stops, lineShapes, kommuner }) {
69+
constructor({ id, name, geometry, stops, kommuner }) {
6970
this.id = id
7071

7172
this.geometry = geometry
@@ -79,7 +80,16 @@ class Region {
7980
)
8081
)
8182
)
82-
this.lineShapes = lineShapes
83+
this.lineShapes = this.trips.pipe(
84+
map(({ tripId, stops, lineNumber, firstStop, lastStop, kommun }) => ({
85+
tripId,
86+
lineNumber,
87+
from: firstStop.name,
88+
to: lastStop.name,
89+
kommun,
90+
stops: stops.map(({ stop }) => stop.position),
91+
}))
92+
)
8393
this.kommuner = kommuner // TODO: Rename to municipalities.
8494

8595
/**

packages/simulator/streams/publicTransport.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,8 @@ function publicTransport(operator) {
7373
shareReplay()
7474
)
7575

76-
const lineShapes = todaysStops.pipe(
77-
groupBy((line) => line.tripId),
78-
mergeMap((group) => group.pipe(toArray())),
79-
map((stops) => ({
80-
tripId: stops[0].tripId,
81-
lineNumber: stops[0].lineNumber,
82-
from: stops[0].stop.name,
83-
to: stops[stops.length - 1].stop.name,
84-
stops: stops.map(({ stop }) => stop.position),
85-
})),
86-
catchError((err) => error('GTFS', err)),
87-
shareReplay()
88-
)
8976
return {
9077
stops: todaysStops,
91-
lineShapes,
9278
}
9379
}
9480

packages/simulator/streams/regions/norrbotten.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { stops, lineShapes } = require('../publicTransport')('norrbotten')
1+
const { stops } = require('../publicTransport')('norrbotten')
22
const { filter } = require('rxjs')
33
const Region = require('../../lib/region')
44

@@ -32,7 +32,6 @@ const norrbotten = (municipalitiesStream) => {
3232

3333
// Bus things.
3434
stops,
35-
lineShapes,
3635
})
3736
}
3837

packages/simulator/streams/regions/skane.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const { stops, lineShapes } = require('../publicTransport')('skane')
2-
const { filter, shareReplay, map } = require('rxjs')
1+
const { stops } = require('../publicTransport')('skane')
2+
const { filter, shareReplay } = require('rxjs')
33
const Region = require('../../lib/region')
4-
const { isInsideCoordinates } = require('../../lib/polygon')
54

65
const includedMunicipalities = [
76
'Helsingborgs stad',
@@ -15,45 +14,11 @@ const skane = (municipalitiesStream) => {
1514
shareReplay()
1615
)
1716

18-
const geometries = []
19-
municipalities
20-
.pipe(
21-
map((municipality) => {
22-
geometries.push({
23-
name: municipality.name,
24-
coordinates: municipality.geometry.coordinates,
25-
})
26-
})
27-
)
28-
.subscribe()
29-
30-
/**
31-
* Include line shapes that have at least one stop inside the active municipalities.
32-
*/
33-
const localLineShapes = lineShapes.pipe(
34-
filter((lineShape) => {
35-
let lineShapeHasAnyStopInsideActiveMunicipalities = false
36-
geometries.forEach((geometry) => {
37-
lineShape.stops.forEach((stop) => {
38-
if (isInsideCoordinates(stop, geometry.coordinates)) {
39-
lineShapeHasAnyStopInsideActiveMunicipalities = true
40-
}
41-
})
42-
})
43-
44-
return lineShapeHasAnyStopInsideActiveMunicipalities
45-
}),
46-
shareReplay()
47-
)
48-
4917
return new Region({
5018
id: 'skane',
5119
name: 'Skåne',
5220
kommuner: municipalities,
5321
stops,
54-
55-
// Bus things.
56-
lineShapes: localLineShapes.pipe(shareReplay()),
5722
})
5823
}
5924

packages/simulator/web/routes.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,11 @@ function register(io) {
8686
clearTimeout(socket.data.timeout)
8787
}
8888
})
89-
89+
*/
9090
socket.on('disconnect', (reason) => {
91-
info('Client disconnected', reason, 'shutting down experiment in 60s...')
92-
93-
clearTimeout(socket.data.timeout)
94-
socket.data.timeout = setTimeout(() => {
95-
info('Shutting down experiment due to inactivity')
96-
process.kill(process.pid, 'SIGUSR2')
97-
socket.data.experiment.subscriptions.map((e) => e.unsubscribe())
98-
}, 5 * 60_000)
99-
})*/
91+
info('Client disconnected', reason, 'Removing subscriptions..')
92+
socket.data.experiment.subscriptions.map((e) => e.unsubscribe())
93+
})
10094
})
10195
}
10296
module.exports = {

0 commit comments

Comments
 (0)