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

Network: Add footPathInfoRedundant flag to trip response #649

Merged
merged 3 commits into from
Feb 28, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ data class TripResponse(
*/
@SerialName("footPathInfo") val footPathInfo: List<FootPathInfo>? = null,

/**
* This element indicates whether the walking directions are redundant in [footPathInfo].
*/
@SerialName("footPathInfoRedundant") val footPathInfoRedundant: Boolean? = null,

/**
* This element describes a single information message that may be associated with a journey leg.
* The data in this is similar to that from add_info endpoint, but is presented differently.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,17 @@ internal fun TripResponse.buildJourneyList(): ImmutableList<TimeTableState.Journ
if (originTimeUTC != null && arrivalTimeUTC != null && totalStops > 0 && legsList != null &&
transportModeLines != null
) {
// A walking leg consists of walking leg + footpath info from public transport leg
val walkingDurationStr = legs.sumOf { leg ->
if (leg.isWalkingLeg()) leg.duration ?: 0L else 0L
}.let { totalDuration ->
val footPathDuration = legs.sumOf { leg ->
leg.footPathInfo?.firstOrNull()?.duration ?: 0L
}
val combinedDuration = totalDuration + footPathDuration
if (combinedDuration == 0L) {
null
} else {
combinedDuration.toDuration(DurationUnit.SECONDS)
.toFormattedDurationTimeString()
}
// A walking leg consists of walking leg
// + footpath info from public transport leg (if footPathInfoRedundant is true)
val totalWalkingDuration = legs.sumOf { leg ->
if (leg.isWalkingLeg() && leg.footPathInfoRedundant != true)
leg.duration ?: 0L else 0L
}

val walkingDurationStr =
totalWalkingDuration.takeIf { it > 0L }?.toDuration(DurationUnit.SECONDS)
?.toFormattedDurationTimeString()

TimeTableState.JourneyCardInfo(
timeText = originTimeUTC.getTimeText(),
platformText = firstPublicTransportLeg.getPlatformText(),
Expand Down Expand Up @@ -171,11 +166,9 @@ private fun TripResponse.Leg.toUiModel(): TimeTableState.JourneyCardInfo.Leg? {

return when {
// Walking Leg - Always check before public transport leg
isWalkingLeg() -> {
displayDuration?.let {
TimeTableState.JourneyCardInfo.Leg.WalkingLeg(duration = displayDuration)
}
}
isWalkingLeg() -> if (displayDuration != null && this.footPathInfoRedundant != true) {
TimeTableState.JourneyCardInfo.Leg.WalkingLeg(duration = displayDuration)
} else null

else -> { // Public Transport Leg
if (transportMode != null && lineName != null && displayText != null &&
Expand Down