Skip to content

Commit

Permalink
Merge pull request #5234 from HSLdevcom/DT-6689
Browse files Browse the repository at this point in the history
DT-6689 fix fake journey end
  • Loading branch information
Antiik91 authored Jan 22, 2025
2 parents 130e376 + a7fc919 commit a2e671f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 50 deletions.
18 changes: 12 additions & 6 deletions app/component/itinerary/navigator/NaviCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ const iconMap = {
};

export default function NaviCard(
{ leg, nextLeg, legType, cardExpanded, startTime, time, position, origin },
{
leg,
nextLeg,
legType,
cardExpanded,
startTime,
time,
position,
tailLength,
},
{ config },
) {
let mainCardContent;
Expand Down Expand Up @@ -83,7 +92,7 @@ export default function NaviCard(
legType={legType}
time={time}
position={position}
origin={origin}
tailLength={tailLength}
/>
</div>
<div type="button" className="navi-top-card-arrow">
Expand Down Expand Up @@ -116,10 +125,7 @@ NaviCard.propTypes = {
lat: PropTypes.number,
lon: PropTypes.number,
}),
origin: PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
}).isRequired,
tailLength: PropTypes.number.isRequired,
};
NaviCard.defaultProps = {
cardExpanded: false,
Expand Down
11 changes: 4 additions & 7 deletions app/component/itinerary/navigator/NaviCardContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function NaviCardContainer(
time,
legs,
position,
origin,
tailLength,
mapLayerRef,
currentLeg,
nextLeg,
Expand Down Expand Up @@ -131,7 +131,7 @@ function NaviCardContainer(
legs,
time,
position,
origin,
tailLength,
intl,
messages,
makeNewItinerarySearch,
Expand Down Expand Up @@ -273,7 +273,7 @@ function NaviCardContainer(
startTime={legTimeStr(firstLeg.start)}
time={time}
position={position}
origin={origin}
tailLength={tailLength}
/>
</button>
{activeMessages.length > 0 && (
Expand All @@ -296,10 +296,7 @@ NaviCardContainer.propTypes = {
}),
mapLayerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
.isRequired,
origin: PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
}).isRequired,
tailLength: PropTypes.number.isRequired,
currentLeg: legShape,
nextLeg: legShape,
firstLeg: legShape,
Expand Down
25 changes: 16 additions & 9 deletions app/component/itinerary/navigator/NaviContainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import distance from '@digitransit-search-util/digitransit-search-util-distance';
import connectToStores from 'fluxible-addons-react/connectToStores';
import { routerShape } from 'found';
import PropTypes from 'prop-types';
import React, { useEffect, useRef } from 'react';
Expand Down Expand Up @@ -43,13 +43,13 @@ function NaviContainer(
const {
realTimeLegs,
time,
origin,
tailLength,
firstLeg,
lastLeg,
previousLeg,
currentLeg,
nextLeg,
} = useRealtimeLegs(relayEnvironment, legs);
} = useRealtimeLegs(relayEnvironment, legs, position);

useEffect(() => {
mapRef?.enableMapTracking(); // try always, shows annoying notifier
Expand Down Expand Up @@ -79,12 +79,11 @@ function NaviContainer(
}

const arrivalTime = legTime(lastLeg.end);

const isDestinationReached =
position && distance(position, lastLeg.to) <= DESTINATION_RADIUS;

(currentLeg === lastLeg || time > arrivalTime) &&
position &&
tailLength <= DESTINATION_RADIUS;
const isPastExpectedArrival = time > arrivalTime + ADDITIONAL_ARRIVAL_TIME;

const isJourneyCompleted = isDestinationReached || isPastExpectedArrival;

if (LEGLOG) {
Expand All @@ -100,7 +99,7 @@ function NaviContainer(
time={time}
position={position}
mapLayerRef={mapLayerRef}
origin={origin}
tailLength={tailLength}
currentLeg={time > arrivalTime ? previousLeg : currentLeg}
nextLeg={nextLeg}
firstLeg={firstLeg}
Expand Down Expand Up @@ -146,4 +145,12 @@ NaviContainer.defaultProps = {
isNavigatorIntroDismissed: false,
};

export default NaviContainer;
const connectedComponent = connectToStores(
NaviContainer,
['MessageStore'],
context => ({
messages: context.getStore('MessageStore').getMessages(),
}),
);

export default connectedComponent;
24 changes: 4 additions & 20 deletions app/component/itinerary/navigator/NaviInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,19 @@ import { displayDistance } from '../../../util/geo-utils';
import { legShape, configShape } from '../../../util/shapes';
import { legDestination, legTimeStr, legTime } from '../../../util/legUtils';
import RouteNumber from '../../RouteNumber';
import {
LEGTYPE,
getLocalizedMode,
getToLocalizedMode,
getRemainingTraversal,
} from './NaviUtils';
import { LEGTYPE, getLocalizedMode, getToLocalizedMode } from './NaviUtils';
import { durationToString } from '../../../util/timeUtils';
import { getRouteMode } from '../../../util/modeUtils';

export default function NaviInstructions(
{ leg, nextLeg, instructions, legType, time, position, origin },
{ leg, nextLeg, instructions, legType, time, position, tailLength },
{ intl, config },
) {
const withRealTime = (rt, children) => (
<span className={cx('bold', { realtime: rt })}>{children}</span>
);

if (legType === LEGTYPE.MOVE) {
const remainingTraversal = getRemainingTraversal(
leg,
position,
origin,
time,
);
const distance = remainingTraversal * leg.distance;

return (
<>
<div className="notification-header">
Expand All @@ -41,7 +28,7 @@ export default function NaviInstructions(
</div>

<div className={cx('duration', { realtime: !!position })}>
{displayDistance(distance, config, intl.formatNumber)}&nbsp;
{displayDistance(tailLength, config, intl.formatNumber)}&nbsp;
{durationToString(legTime(leg.end) - time)}
</div>
</>
Expand Down Expand Up @@ -177,10 +164,7 @@ NaviInstructions.propTypes = {
lat: PropTypes.number,
lon: PropTypes.number,
}),
origin: PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
}).isRequired,
tailLength: PropTypes.number.isRequired,
};

NaviInstructions.defaultProps = {
Expand Down
12 changes: 6 additions & 6 deletions app/component/itinerary/navigator/NaviUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function getRemainingTraversal(leg, pos, origin, time) {
return Math.min(Math.max((legTime(leg.end) - time) / duration, 0), 1.0);
}

function findTransferProblems(legs, time, position, origin) {
function findTransferProblems(legs, time, position, tailLength) {
const transfers = [];

for (let i = 1; i < legs.length - 1; i++) {
Expand Down Expand Up @@ -182,15 +182,15 @@ function findTransferProblems(legs, time, position, origin) {
// has transit walk already started ?
if (time > legTime(leg.start)) {
// compute how transit is proceeding
toGo = getRemainingTraversal(leg, position, origin, time);
toGo = tailLength;
timeLeft = (t2 - time) / 1000;
} else {
toGo = 1.0;
toGo = leg.distance;
timeLeft = duration / 1000; // should we consider also transfer slack here?
}
if (toGo > 0) {
const originalSpeed = leg.distance / leg.duration;
const newSpeed = (toGo * leg.distance) / (timeLeft + 0.0001);
const newSpeed = toGo / (timeLeft + 0.0001);
if (newSpeed > 1.5 * originalSpeed) {
// too high speed compared to user's routing preference
severity = 'ALERT';
Expand Down Expand Up @@ -401,7 +401,7 @@ export const getItineraryAlerts = (
legs,
time,
position,
origin,
tailLength,
intl,
messages,
itinerarySearchCallback,
Expand Down Expand Up @@ -475,7 +475,7 @@ export const getItineraryAlerts = (
}
});
} else {
const transfers = findTransferProblems(legs, time, position, origin);
const transfers = findTransferProblems(legs, time, position, tailLength);
if (transfers.length) {
const prob =
transfers.find(p => p.severity === 'ALERT') ||
Expand Down
10 changes: 8 additions & 2 deletions app/component/itinerary/navigator/hooks/useRealtimeLegs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GeodeticToEcef, GeodeticToEnu } from '../../../../util/geo-utils';
import { legTime } from '../../../../util/legUtils';
import { epochToIso } from '../../../../util/timeUtils';
import { legQuery } from '../../queries/LegQuery';
import { getRemainingTraversal } from '../NaviUtils';

function nextTransitIndex(legs, i) {
for (let j = i; j < legs.length; j++) {
Expand Down Expand Up @@ -147,7 +148,7 @@ function getInitialState(legs) {
};
}

const useRealtimeLegs = (relayEnvironment, initialLegs) => {
const useRealtimeLegs = (relayEnvironment, initialLegs, position) => {
const [{ origin, time, realTimeLegs }, setTimeAndRealTimeLegs] = useState(
() => getInitialState(initialLegs),
);
Expand Down Expand Up @@ -237,10 +238,15 @@ const useRealtimeLegs = (relayEnvironment, initialLegs) => {
const { firstLeg, lastLeg, currentLeg, nextLeg, previousLeg } =
getLegsOfInterest(realTimeLegs, time);

const tailLength = currentLeg
? getRemainingTraversal(currentLeg, position, origin, time) *
currentLeg.distance
: 0;

return {
realTimeLegs,
time,
origin,
tailLength,
firstLeg,
lastLeg,
previousLeg,
Expand Down

0 comments on commit a2e671f

Please sign in to comment.