Skip to content

feat(itinerary): add ability to sort itineraries by fare #1411

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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

josh-willis-arcadis
Copy link
Contributor

Adds logic to sort itineraries by only transit fare. The difference between sorting by fare and cost is that itineraries with driving or biking have increased cost than just transit itineraries.

PR Checklist:

  • Does the code follow accessibility standards (WCAG 2.1 AA Compliant)?
  • Are all languages supported (Internationalization/Localization)?
  • Are appropriate Typescript types implemented?

Copy link
Contributor

@daniel-heppner-ibigroup daniel-heppner-ibigroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Simple change

@@ -453,10 +454,12 @@ export function addSortingCosts<T extends Itinerary>(
totalFareResult === null ? Number.MAX_VALUE : totalFareResult

const rank = calculateItineraryCost(itinerary, config)
const transitFare = getFare(itinerary).transitFare || 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you just let this stay as undefined instead setting it to zero? does that mess up the sort?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the value is zero or undefined the sort does not change.

Copy link
Contributor Author

@josh-willis-arcadis josh-willis-arcadis Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can remove || 0 as well for cleaner code. I'll let second reviewer decide.

@@ -48,6 +48,7 @@ export interface ItineraryWithCO2Info extends Itinerary {
export interface ItineraryWithSortingCosts extends Itinerary {
rank: number
totalFare: number
transitFare?: number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this is an optional, which leads me to my next question. I think either you should remove the optional here or remove the || 0 below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the optional, as both values of zero and undefined do not change the sort order

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if we get an undefined fare we return .01 or something? So that the confirmed free trips are sorted above fares where we don't actually know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a fare is undefined would that be a data issue? Should we try to handle data issues?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If agencies don't provide us fares we display "no fare available" and i think that's fine to do, I just don't know how it fits into this PR

Copy link
Contributor

@amy-corson-ibigroup amy-corson-ibigroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking because the logic to actually return the fare is commented out.

Wondering also if the user facing label "fare" should be changed to "transit fare"? I'm worried about people assuming we're incorporating rental bike price into the total fare for micromobility trips

@amy-corson-ibigroup
Copy link
Contributor

amy-corson-ibigroup commented Jun 13, 2025

There's also a distinction between a $0 fare and "no fare information". I don't think "no fare info" should be weighted the exact same as a free trip? Feels like if you sort by cheapest fare you should see free trips before you see n/a fares. Idk @daniel-heppner-ibigroup what are your thoughts on this

Copy link
Contributor

@amy-corson-ibigroup amy-corson-ibigroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to approve so I'm not blocking while on vacation, but would still love to discuss the difference in sorting between undefined fares and $0 fares before we merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants