@motionstudies/core 0.1.0-alpha.2 → 0.1.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ /** Remaining calls from this snapshot's train. Times may already include realtime adjustments. */
2
+ export function vehicleCalls(snapshot, train, time) {
3
+ if (!Number.isFinite(time) || train.realtime?.status === 'cancelled')
4
+ return [];
5
+ return train.stops.flatMap(([index, arrival, departure], callIndex) => {
6
+ const stop = snapshot.stops[index];
7
+ if (!stop || !Number.isFinite(arrival) || !Number.isFinite(departure) || departure < arrival || departure < time)
8
+ return [];
9
+ const atStop = arrival <= time && time <= departure;
10
+ return [{ id: `${train.id}:${callIndex}`, name: stop[2], time: atStop ? departure : arrival,
11
+ platform: stop[3]?.trim() || undefined, atStop,
12
+ isDestination: callIndex === train.stops.length - 1 && Boolean(train.headsign.trim()) && stop[2].trim() === train.headsign.trim() }];
13
+ });
14
+ }
@@ -0,0 +1,13 @@
1
+ import type { NetworkSnapshot, NetworkTrain, ServiceCategory, StationIndexEntry } from './network.ts';
2
+ export declare function countableVehicleTrains(network: NetworkSnapshot | undefined, stations: readonly StationIndexEntry[], selection: {
3
+ category?: ServiceCategory;
4
+ station?: Pick<StationIndexEntry, 'name'>;
5
+ route?: {
6
+ name: string;
7
+ category: ServiceCategory;
8
+ };
9
+ }): readonly NetworkTrain[];
10
+ /** Build once per immutable selection; clock updates need only two binary searches. */
11
+ export declare function createActiveTimetableVehicleCounter(trains: readonly NetworkTrain[], options?: {
12
+ readonly requirePositionable?: boolean;
13
+ }): (time: number) => number;
@@ -0,0 +1,33 @@
1
+ export function countableVehicleTrains(network, stations, selection) {
2
+ const stationTrainIds = selection.station
3
+ ? new Set(stations.find(station => station.name === selection.station?.name)?.trainIds ?? [])
4
+ : undefined;
5
+ return network?.trains.filter(train => (!selection.category || train.category === selection.category) &&
6
+ (!stationTrainIds || stationTrainIds.has(train.id)) &&
7
+ (!selection.route || (train.route === selection.route.name && train.category === selection.route.category))) ?? [];
8
+ }
9
+ /** Build once per immutable selection; clock updates need only two binary searches. */
10
+ export function createActiveTimetableVehicleCounter(trains, options = {}) {
11
+ const starts = [], ends = [];
12
+ for (const train of trains) {
13
+ if (train.realtime?.status === 'cancelled' || (options.requirePositionable && train.stops.length < 2) || !(train.start <= train.end))
14
+ continue;
15
+ starts.push(train.start);
16
+ ends.push(train.end);
17
+ }
18
+ starts.sort((a, b) => a - b);
19
+ ends.sort((a, b) => a - b);
20
+ const before = (values, time, inclusive) => {
21
+ let low = 0, high = values.length;
22
+ while (low < high) {
23
+ const middle = (low + high) >>> 1;
24
+ if (values[middle] < time || inclusive && values[middle] === time)
25
+ low = middle + 1;
26
+ else
27
+ high = middle;
28
+ }
29
+ return low;
30
+ };
31
+ // Include both departure and arrival instants, including zero-length trips.
32
+ return time => Number.isNaN(time) ? 0 : before(starts, time, true) - before(ends, time, false);
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionstudies/core",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.21",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Transport contracts and motion primitives for Motion Studies.",
@@ -65,6 +65,11 @@
65
65
  "import": "./domain/airport.js",
66
66
  "default": "./domain/airport.js"
67
67
  },
68
+ "./domain/movement-board": {
69
+ "types": "./domain/movement-board.d.ts",
70
+ "import": "./domain/movement-board.js",
71
+ "default": "./domain/movement-board.js"
72
+ },
68
73
  "./domain/boundary": {
69
74
  "types": "./domain/boundary.d.ts",
70
75
  "import": "./domain/boundary.js",
@@ -100,6 +105,16 @@
100
105
  "import": "./domain/network-day.js",
101
106
  "default": "./domain/network-day.js"
102
107
  },
108
+ "./domain/network-patterns": {
109
+ "types": "./domain/network-patterns.d.ts",
110
+ "import": "./domain/network-patterns.js",
111
+ "default": "./domain/network-patterns.js"
112
+ },
113
+ "./domain/station-calls": {
114
+ "types": "./domain/station-calls.d.ts",
115
+ "import": "./domain/station-calls.js",
116
+ "default": "./domain/station-calls.js"
117
+ },
103
118
  "./domain/network-layers": {
104
119
  "types": "./domain/network-layers.d.ts",
105
120
  "import": "./domain/network-layers.js",
@@ -139,6 +154,61 @@
139
154
  "types": "./domain/train-time-index.d.ts",
140
155
  "import": "./domain/train-time-index.js",
141
156
  "default": "./domain/train-time-index.js"
157
+ },
158
+ "./domain/live-airport": {
159
+ "types": "./domain/live-airport.d.ts",
160
+ "import": "./domain/live-airport.js",
161
+ "default": "./domain/live-airport.js"
162
+ },
163
+ "./domain/station-departures": {
164
+ "types": "./domain/station-departures.d.ts",
165
+ "import": "./domain/station-departures.js",
166
+ "default": "./domain/station-departures.js"
167
+ },
168
+ "./domain/vehicle-counts": {
169
+ "types": "./domain/vehicle-counts.d.ts",
170
+ "import": "./domain/vehicle-counts.js",
171
+ "default": "./domain/vehicle-counts.js"
172
+ },
173
+ "./domain/aggregate-road": {
174
+ "types": "./domain/aggregate-road.d.ts",
175
+ "import": "./domain/aggregate-road.js",
176
+ "default": "./domain/aggregate-road.js"
177
+ },
178
+ "./domain/vehicle-calls": {
179
+ "types": "./domain/vehicle-calls.d.ts",
180
+ "import": "./domain/vehicle-calls.js",
181
+ "default": "./domain/vehicle-calls.js"
182
+ },
183
+ "./domain/supported-field": {
184
+ "types": "./domain/supported-field.d.ts",
185
+ "import": "./domain/supported-field.js",
186
+ "default": "./domain/supported-field.js"
187
+ },
188
+ "./domain/gridded-series": {
189
+ "types": "./domain/gridded-series.d.ts",
190
+ "import": "./domain/gridded-series.js",
191
+ "default": "./domain/gridded-series.js"
192
+ },
193
+ "./domain/published-day": {
194
+ "types": "./domain/published-day.d.ts",
195
+ "import": "./domain/published-day.js",
196
+ "default": "./domain/published-day.js"
197
+ },
198
+ "./domain/field-paths": {
199
+ "types": "./domain/field-paths.d.ts",
200
+ "import": "./domain/field-paths.js",
201
+ "default": "./domain/field-paths.js"
202
+ },
203
+ "./domain/daylight": {
204
+ "types": "./domain/daylight.d.ts",
205
+ "import": "./domain/daylight.js",
206
+ "default": "./domain/daylight.js"
207
+ },
208
+ "./domain/power-day": {
209
+ "types": "./domain/power-day.d.ts",
210
+ "import": "./domain/power-day.js",
211
+ "default": "./domain/power-day.js"
142
212
  }
143
213
  },
144
214
  "files": [
@@ -147,6 +217,8 @@
147
217
  "**/*.d.ts",
148
218
  "**/*.d.mts",
149
219
  "**/*.css",
220
+ "**/*.woff2",
221
+ "**/*-OFL.txt",
150
222
  "README.md",
151
223
  "LICENSE"
152
224
  ],