Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stop viewer next days departures #1005

Merged
merged 13 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
# skip git, yarn, pixel test script and HAR file, and all i18n resources.
# Also, the a11y test file has a false positive and the ignore list does not work
# see https://github.com/opentripplanner/otp-react-redux/pull/436/checks?check_run_id=3369380014
skip: ./.git,yarn.lock,./a11y/a11y.test.js,./a11y/mocks,./percy/percy.test.js,./percy/mock.har,./i18n
skip: ./.git,yarn.lock,./a11y/a11y.test.js,./a11y/mocks,./percy/percy.test.js,./percy/mock.har,./i18n,./__tests__/mocks
8,153 changes: 3,454 additions & 4,699 deletions __tests__/components/viewers/__snapshots__/stop-viewer.js.snap

Large diffs are not rendered by default.

286 changes: 286 additions & 0 deletions __tests__/mocks/stop-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
{
"id": "40:99256",
"code": "C15-T2",
"lat": 47.580589,
"lon": -122.327263,
"locationType": "STOP",
"name": "SODO Station",
"wheelchairBoarding": "POSSIBLE",
"zoneId": "73",
"geometries": {
"geoJson": {
"type": "Point",
"coordinates": [
-122.3273,
47.5806
]
}
},
"routes": [
{
"id": "40:100479",
"agency": {
"gtfsId": "40:40",
"name": "Sound Transit"
},
"longName": "Northgate - Angle Lake",
"mode": "TRAM",
"color": "28813F",
"textColor": "FFFFFF",
"shortName": "1-Line"
}
],
"stopTimes": [
{
"pattern": {
"id": "40:100479:1:01",
"desc": "1-Line to Northgate Station (40:990006) from Angle Lake Station (40:99914)",
"routeId": "40:100479",
"headsign": "Northgate"
},
"times": [
{
"stopId": "40:99256",
"stopIndex": 8,
"stopCount": 19,
"scheduledArrival": 23850,
"scheduledDeparture": 23880,
"realtimeArrival": 23850,
"realtimeDeparture": 23880,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695193200,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1016",
"blockId": "59906",
"headsign": "Northgate"
},
{
"stopId": "40:99256",
"stopIndex": 8,
"stopCount": 19,
"scheduledArrival": 23370,
"scheduledDeparture": 23400,
"realtimeArrival": 23370,
"realtimeDeparture": 23400,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695193200,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1014",
"blockId": "59905",
"headsign": "Northgate"
},
{
"stopId": "40:99256",
"stopIndex": 8,
"stopCount": 19,
"scheduledArrival": 22890,
"scheduledDeparture": 22920,
"realtimeArrival": 22890,
"realtimeDeparture": 22920,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695193200,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1013",
"blockId": "59904",
"headsign": "Northgate"
}
]
},
{
"pattern": {
"id": "40:100479:1:06",
"desc": "1-Line University of Washington",
"routeId": "40:100479",
"headsign": "University of Washington"
},
"times": [
{
"stopId": "40:99256",
"stopIndex": 0,
"stopCount": 8,
"scheduledArrival": 15810,
"scheduledDeparture": 15840,
"realtimeArrival": 15810,
"realtimeDeparture": 15840,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695366000,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1001",
"blockId": "59904",
"headsign": "University of Washington"
},
{
"stopId": "40:99256",
"stopIndex": 0,
"stopCount": 8,
"scheduledArrival": 15810,
"scheduledDeparture": 15840,
"realtimeArrival": 15810,
"realtimeDeparture": 15840,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695279600,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1001",
"blockId": "59904",
"headsign": "University of Washington"
}
]
},
{
"pattern": {
"id": "40:100479:1:07",
"desc": "1-Line Stadium",
"routeId": "40:100479",
"headsign": "Stadium"
},
"times": [
{
"stopId": "40:99256",
"stopIndex": 8,
"stopCount": 10,
"scheduledArrival": 90090,
"scheduledDeparture": 90120,
"realtimeArrival": 90090,
"realtimeDeparture": 90120,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695193200,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1132",
"blockId": "59904",
"headsign": "Stadium"
},
{
"stopId": "40:99256",
"stopIndex": 8,
"stopCount": 10,
"scheduledArrival": 89190,
"scheduledDeparture": 89220,
"realtimeArrival": 89190,
"realtimeDeparture": 89220,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695193200,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1131",
"blockId": "59924",
"headsign": "Stadium"
},
{
"stopId": "40:99256",
"stopIndex": 8,
"stopCount": 10,
"scheduledArrival": 88290,
"scheduledDeparture": 88320,
"realtimeArrival": 88290,
"realtimeDeparture": 88320,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695193200,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1130",
"blockId": "59903",
"headsign": "Stadium"
}
]
},
{
"pattern": {
"id": "40:100479:1:05",
"desc": "1-Line to Northgate Station (40:990006) from SODO Station (40:99256)",
"routeId": "40:100479",
"headsign": "Northgate"
},
"times": [
{
"stopId": "40:99256",
"stopIndex": 0,
"stopCount": 11,
"scheduledArrival": 17250,
"scheduledDeparture": 17280,
"realtimeArrival": 17250,
"realtimeDeparture": 17280,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695279600,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1003",
"blockId": "59908",
"headsign": "Northgate"
},
{
"stopId": "40:99256",
"stopIndex": 0,
"stopCount": 11,
"scheduledArrival": 16530,
"scheduledDeparture": 16560,
"realtimeArrival": 16530,
"realtimeDeparture": 16560,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695279600,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1002",
"blockId": "59922",
"headsign": "Northgate"
},
{
"stopId": "40:99256",
"stopIndex": 0,
"stopCount": 11,
"scheduledArrival": 52470,
"scheduledDeparture": 52500,
"realtimeArrival": 52470,
"realtimeDeparture": 52500,
"arrivalDelay": 0,
"departureDelay": 0,
"timepoint": true,
"realtime": false,
"realtimeState": "SCHEDULED",
"serviceDay": 1695193200,
"tripId": "40:LLR_2023-09-18_Sept18_Weekday_100479_1072",
"blockId": "59925",
"headsign": "Northgate"
}
]
}
],
"agencyId": "40:40",
"agencyName": "Sound Transit",
"color": "#28813F",
"bikeRental": {
"stations": []
},
"parkAndRideLocations": [],
"vehicleRental": {
"stations": []
},
"nearbyStops": [],
"fetchStatus": 2,
"stopTimesLastUpdated": 1695215706401
}
63 changes: 63 additions & 0 deletions __tests__/util/stop-times.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { utcToZonedTime } from 'date-fns-tz'

import '../test-utils/mock-window-url'
import { groupAndSortStopTimesByPatternByDay } from '../../lib/util/stop-times'

const stopData = require('../mocks/stop-data.json')
const now = utcToZonedTime(
new Date(stopData.stopTimesLastUpdated),
'America/Los_Angeles'
)
const daysAhead = 2

describe('util > stop-times', () => {
describe('sortAndGroupStopTimesByDay', () => {
it('should sort and group stop times by day', () => {
const stopTimesByPatternByDay = groupAndSortStopTimesByPatternByDay(
stopData,
now,
daysAhead,
3
)

function getPatternDays(id: string) {
return stopTimesByPatternByDay
.filter((p) => p.id === id)
.map((p) => p.day)
}

// Stop time data has 4 patterns aggregating to 3 final destinations.
// (This method assumes that the routing is roughly the same for patterns
// that have the same destination.)
const headsigns = new Set(
stopTimesByPatternByDay.map((st) => st.pattern.headsign)
)
expect(headsigns).toEqual(
new Set(['Northgate', 'Stadium', 'University of Washington'])
)

// The pattern to UWA should be included twice, once per service day outside of today.
expect(getPatternDays('40:100479-University of Washington')).toEqual([
1695279600, 1695366000
])

// Patterns to Stadium (last trips in the evening) should be for "today"'s service day.
expect(getPatternDays('40:100479-Stadium')).toEqual([1695193200])

// No next-day pattern to Northgate should be returned (same-day depatures exist).
expect(getPatternDays('40:100479-Northgate')).toEqual([1695193200])

// Patterns should be sorted by day, then by departure time.
for (let i = 1; i < stopTimesByPatternByDay.length; i++) {
const prevPattern = stopTimesByPatternByDay[i - 1]
const thisPattern = stopTimesByPatternByDay[i]
expect(
prevPattern.day < thisPattern.day ||
(prevPattern.day === thisPattern.day &&
prevPattern.times[0].realtimeDeparture <=
thisPattern.times[0].realtimeDeparture)
).toBe(true)
}
})
})
})
Loading
Loading