Skip to content

Commit a2e671f

Browse files
authored
Merge pull request #5234 from HSLdevcom/DT-6689
DT-6689 fix fake journey end
2 parents 130e376 + a7fc919 commit a2e671f

File tree

6 files changed

+50
-50
lines changed

6 files changed

+50
-50
lines changed

app/component/itinerary/navigator/NaviCard.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ const iconMap = {
2727
};
2828

2929
export default function NaviCard(
30-
{ leg, nextLeg, legType, cardExpanded, startTime, time, position, origin },
30+
{
31+
leg,
32+
nextLeg,
33+
legType,
34+
cardExpanded,
35+
startTime,
36+
time,
37+
position,
38+
tailLength,
39+
},
3140
{ config },
3241
) {
3342
let mainCardContent;
@@ -83,7 +92,7 @@ export default function NaviCard(
8392
legType={legType}
8493
time={time}
8594
position={position}
86-
origin={origin}
95+
tailLength={tailLength}
8796
/>
8897
</div>
8998
<div type="button" className="navi-top-card-arrow">
@@ -116,10 +125,7 @@ NaviCard.propTypes = {
116125
lat: PropTypes.number,
117126
lon: PropTypes.number,
118127
}),
119-
origin: PropTypes.shape({
120-
x: PropTypes.number.isRequired,
121-
y: PropTypes.number.isRequired,
122-
}).isRequired,
128+
tailLength: PropTypes.number.isRequired,
123129
};
124130
NaviCard.defaultProps = {
125131
cardExpanded: false,

app/component/itinerary/navigator/NaviCardContainer.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function NaviCardContainer(
5959
time,
6060
legs,
6161
position,
62-
origin,
62+
tailLength,
6363
mapLayerRef,
6464
currentLeg,
6565
nextLeg,
@@ -131,7 +131,7 @@ function NaviCardContainer(
131131
legs,
132132
time,
133133
position,
134-
origin,
134+
tailLength,
135135
intl,
136136
messages,
137137
makeNewItinerarySearch,
@@ -273,7 +273,7 @@ function NaviCardContainer(
273273
startTime={legTimeStr(firstLeg.start)}
274274
time={time}
275275
position={position}
276-
origin={origin}
276+
tailLength={tailLength}
277277
/>
278278
</button>
279279
{activeMessages.length > 0 && (
@@ -296,10 +296,7 @@ NaviCardContainer.propTypes = {
296296
}),
297297
mapLayerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
298298
.isRequired,
299-
origin: PropTypes.shape({
300-
x: PropTypes.number.isRequired,
301-
y: PropTypes.number.isRequired,
302-
}).isRequired,
299+
tailLength: PropTypes.number.isRequired,
303300
currentLeg: legShape,
304301
nextLeg: legShape,
305302
firstLeg: legShape,

app/component/itinerary/navigator/NaviContainer.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import distance from '@digitransit-search-util/digitransit-search-util-distance';
1+
import connectToStores from 'fluxible-addons-react/connectToStores';
22
import { routerShape } from 'found';
33
import PropTypes from 'prop-types';
44
import React, { useEffect, useRef } from 'react';
@@ -43,13 +43,13 @@ function NaviContainer(
4343
const {
4444
realTimeLegs,
4545
time,
46-
origin,
46+
tailLength,
4747
firstLeg,
4848
lastLeg,
4949
previousLeg,
5050
currentLeg,
5151
nextLeg,
52-
} = useRealtimeLegs(relayEnvironment, legs);
52+
} = useRealtimeLegs(relayEnvironment, legs, position);
5353

5454
useEffect(() => {
5555
mapRef?.enableMapTracking(); // try always, shows annoying notifier
@@ -79,12 +79,11 @@ function NaviContainer(
7979
}
8080

8181
const arrivalTime = legTime(lastLeg.end);
82-
8382
const isDestinationReached =
84-
position && distance(position, lastLeg.to) <= DESTINATION_RADIUS;
85-
83+
(currentLeg === lastLeg || time > arrivalTime) &&
84+
position &&
85+
tailLength <= DESTINATION_RADIUS;
8686
const isPastExpectedArrival = time > arrivalTime + ADDITIONAL_ARRIVAL_TIME;
87-
8887
const isJourneyCompleted = isDestinationReached || isPastExpectedArrival;
8988

9089
if (LEGLOG) {
@@ -100,7 +99,7 @@ function NaviContainer(
10099
time={time}
101100
position={position}
102101
mapLayerRef={mapLayerRef}
103-
origin={origin}
102+
tailLength={tailLength}
104103
currentLeg={time > arrivalTime ? previousLeg : currentLeg}
105104
nextLeg={nextLeg}
106105
firstLeg={firstLeg}
@@ -146,4 +145,12 @@ NaviContainer.defaultProps = {
146145
isNavigatorIntroDismissed: false,
147146
};
148147

149-
export default NaviContainer;
148+
const connectedComponent = connectToStores(
149+
NaviContainer,
150+
['MessageStore'],
151+
context => ({
152+
messages: context.getStore('MessageStore').getMessages(),
153+
}),
154+
);
155+
156+
export default connectedComponent;

app/component/itinerary/navigator/NaviInstructions.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,19 @@ import { displayDistance } from '../../../util/geo-utils';
66
import { legShape, configShape } from '../../../util/shapes';
77
import { legDestination, legTimeStr, legTime } from '../../../util/legUtils';
88
import RouteNumber from '../../RouteNumber';
9-
import {
10-
LEGTYPE,
11-
getLocalizedMode,
12-
getToLocalizedMode,
13-
getRemainingTraversal,
14-
} from './NaviUtils';
9+
import { LEGTYPE, getLocalizedMode, getToLocalizedMode } from './NaviUtils';
1510
import { durationToString } from '../../../util/timeUtils';
1611
import { getRouteMode } from '../../../util/modeUtils';
1712

1813
export default function NaviInstructions(
19-
{ leg, nextLeg, instructions, legType, time, position, origin },
14+
{ leg, nextLeg, instructions, legType, time, position, tailLength },
2015
{ intl, config },
2116
) {
2217
const withRealTime = (rt, children) => (
2318
<span className={cx('bold', { realtime: rt })}>{children}</span>
2419
);
2520

2621
if (legType === LEGTYPE.MOVE) {
27-
const remainingTraversal = getRemainingTraversal(
28-
leg,
29-
position,
30-
origin,
31-
time,
32-
);
33-
const distance = remainingTraversal * leg.distance;
34-
3522
return (
3623
<>
3724
<div className="notification-header">
@@ -41,7 +28,7 @@ export default function NaviInstructions(
4128
</div>
4229

4330
<div className={cx('duration', { realtime: !!position })}>
44-
{displayDistance(distance, config, intl.formatNumber)}&nbsp;
31+
{displayDistance(tailLength, config, intl.formatNumber)}&nbsp;
4532
{durationToString(legTime(leg.end) - time)}
4633
</div>
4734
</>
@@ -177,10 +164,7 @@ NaviInstructions.propTypes = {
177164
lat: PropTypes.number,
178165
lon: PropTypes.number,
179166
}),
180-
origin: PropTypes.shape({
181-
x: PropTypes.number.isRequired,
182-
y: PropTypes.number.isRequired,
183-
}).isRequired,
167+
tailLength: PropTypes.number.isRequired,
184168
};
185169

186170
NaviInstructions.defaultProps = {

app/component/itinerary/navigator/NaviUtils.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function getRemainingTraversal(leg, pos, origin, time) {
122122
return Math.min(Math.max((legTime(leg.end) - time) / duration, 0), 1.0);
123123
}
124124

125-
function findTransferProblems(legs, time, position, origin) {
125+
function findTransferProblems(legs, time, position, tailLength) {
126126
const transfers = [];
127127

128128
for (let i = 1; i < legs.length - 1; i++) {
@@ -182,15 +182,15 @@ function findTransferProblems(legs, time, position, origin) {
182182
// has transit walk already started ?
183183
if (time > legTime(leg.start)) {
184184
// compute how transit is proceeding
185-
toGo = getRemainingTraversal(leg, position, origin, time);
185+
toGo = tailLength;
186186
timeLeft = (t2 - time) / 1000;
187187
} else {
188-
toGo = 1.0;
188+
toGo = leg.distance;
189189
timeLeft = duration / 1000; // should we consider also transfer slack here?
190190
}
191191
if (toGo > 0) {
192192
const originalSpeed = leg.distance / leg.duration;
193-
const newSpeed = (toGo * leg.distance) / (timeLeft + 0.0001);
193+
const newSpeed = toGo / (timeLeft + 0.0001);
194194
if (newSpeed > 1.5 * originalSpeed) {
195195
// too high speed compared to user's routing preference
196196
severity = 'ALERT';
@@ -401,7 +401,7 @@ export const getItineraryAlerts = (
401401
legs,
402402
time,
403403
position,
404-
origin,
404+
tailLength,
405405
intl,
406406
messages,
407407
itinerarySearchCallback,
@@ -475,7 +475,7 @@ export const getItineraryAlerts = (
475475
}
476476
});
477477
} else {
478-
const transfers = findTransferProblems(legs, time, position, origin);
478+
const transfers = findTransferProblems(legs, time, position, tailLength);
479479
if (transfers.length) {
480480
const prob =
481481
transfers.find(p => p.severity === 'ALERT') ||

app/component/itinerary/navigator/hooks/useRealtimeLegs.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GeodeticToEcef, GeodeticToEnu } from '../../../../util/geo-utils';
77
import { legTime } from '../../../../util/legUtils';
88
import { epochToIso } from '../../../../util/timeUtils';
99
import { legQuery } from '../../queries/LegQuery';
10+
import { getRemainingTraversal } from '../NaviUtils';
1011

1112
function nextTransitIndex(legs, i) {
1213
for (let j = i; j < legs.length; j++) {
@@ -147,7 +148,7 @@ function getInitialState(legs) {
147148
};
148149
}
149150

150-
const useRealtimeLegs = (relayEnvironment, initialLegs) => {
151+
const useRealtimeLegs = (relayEnvironment, initialLegs, position) => {
151152
const [{ origin, time, realTimeLegs }, setTimeAndRealTimeLegs] = useState(
152153
() => getInitialState(initialLegs),
153154
);
@@ -237,10 +238,15 @@ const useRealtimeLegs = (relayEnvironment, initialLegs) => {
237238
const { firstLeg, lastLeg, currentLeg, nextLeg, previousLeg } =
238239
getLegsOfInterest(realTimeLegs, time);
239240

241+
const tailLength = currentLeg
242+
? getRemainingTraversal(currentLeg, position, origin, time) *
243+
currentLeg.distance
244+
: 0;
245+
240246
return {
241247
realTimeLegs,
242248
time,
243-
origin,
249+
tailLength,
244250
firstLeg,
245251
lastLeg,
246252
previousLeg,

0 commit comments

Comments
 (0)