Skip to content
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
12 changes: 10 additions & 2 deletions src/transfer-risk/__tests__/transfer-risk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('getTransferRisk', () => {
expect(getTransferRisk(600)).toBeUndefined();
});

it('treats a zero gap as uncertain', () => {
expect(getTransferRisk(0)).toBe('uncertain');
it('passes on a zero gap, which the planner treats as feasible', () => {
expect(getTransferRisk(0)).toBeUndefined();
});

it('is uncertain at any negative gap, however large', () => {
Expand Down Expand Up @@ -81,6 +81,14 @@ describe('getLegTransferRisk', () => {
expect(getLegTransferRisk(legs, 1)).toBeUndefined();
});

it('passes when the connection leaves the instant you arrive', () => {
const legs = [
transitLeg({expectedEndTime: '2024-01-01T10:10:00.000Z'}),
transitLeg({expectedStartTime: '2024-01-01T10:10:00.000Z'}),
];
expect(getLegTransferRisk(legs, 1)).toBeUndefined();
});

it('passes on the first leg, which nothing precedes', () => {
expect(getLegTransferRisk([transitLeg(), transitLeg()], 0)).toBeUndefined();
});
Expand Down
15 changes: 7 additions & 8 deletions src/transfer-risk/transfer-risk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import type {TransferLeg} from './types';
import {TransferRisk} from './types';

/**
* Classifies the gap between arriving and the next departure: any gap that is
* not positive is uncertain, however large. Zero counts, because arriving
* exactly as the service leaves is not a transfer you can rely on. A
* non-finite gap yields undefined.
* Classifies the gap between arriving and the next departure: a negative gap is
* uncertain, however small. A zero-second transfer is treated as feasible by Entur and may be
* returned by the trip planner, so it is not treated as a risky transfer. Non-finite values yield undefined.
*/
export const getTransferRisk = (seconds: number): TransferRisk | undefined => {
if (!Number.isFinite(seconds) || seconds > 0) {
if (!Number.isFinite(seconds) || seconds >= 0) {
return undefined;
}
return TransferRisk.Uncertain;
Expand All @@ -24,9 +23,9 @@ export const isTransitLeg = (leg: TransferLeg): boolean =>
* before, so an intervening walk counts.
*
* Undefined when the leg is not transit, when no transit leg precedes it, or
* when the transfer still holds. The transit check also keeps the warning off
* the leg leading *into* a walk: those gaps are commonly re-anchored to exactly
* zero, which would otherwise fire on every transfer.
* when the transfer still holds. The transit check keeps the warning off the leg
* leading *into* a walk, where it would sit on a leg clients are free to filter
* out of the display.
*/
export const getLegTransferRisk = (
legs: TransferLeg[],
Expand Down
5 changes: 2 additions & 3 deletions src/transfer-risk/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Transfer risk classification for transfers with no slack (0s) or already
* missed (negative gaps). Kept as a string (vs boolean) because additional
* levels (e.g. `shortWait`) may be added later.
* Transfer risk classification for transfers. Kept as a string (vs boolean)
* because additional levels may be added later (e.g. `shortWait`).
*/
export const TransferRisk = {
Uncertain: 'uncertain',
Expand Down