-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GTFS FaresV2 timeframes #7139
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
base: dev-2.x
Are you sure you want to change the base?
GTFS FaresV2 timeframes #7139
Conversation
ffe2544 to
fed34b6
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #7139 +/- ##
=============================================
+ Coverage 72.12% 72.16% +0.03%
- Complexity 20837 20884 +47
=============================================
Files 2268 2273 +5
Lines 84338 84470 +132
Branches 8415 8424 +9
=============================================
+ Hits 60827 60955 +128
- Misses 20538 20542 +4
Partials 2973 2973 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
binh-dam-ibigroup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to play with it, however I'm going to request you replace all the Entity.of() methods that return builders with either new EntityBuilder() or Entity.builder().
application/src/ext-test/java/org/opentripplanner/ext/fares/service/gtfs/v2/AreasTest.java
Show resolved
Hide resolved
...xt-test/java/org/opentripplanner/ext/fares/service/gtfs/v2/OnlyFromTimeframeMatcherTest.java
Show resolved
Hide resolved
application/src/ext/java/org/opentripplanner/ext/fares/model/Timeframe.java
Show resolved
Hide resolved
application/src/ext/java/org/opentripplanner/ext/fares/service/gtfs/v2/TimeframeMatcher.java
Show resolved
Hide resolved
| var t = Timeframe.of() | ||
| .withServiceId(serviceId) | ||
| .withStart(rhs.getStartTime()) | ||
| .withEnd(rhs.getEndTime()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if that's an issue with OBA, a blank end_time value will map to midnight "00:00:00" (same as blank start_time values), so this will fail timeframe matching where end_time is omitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good catch. I had set the default to LocalDate.MIDNIGHT and had assumed that that means 24:00 but it is the same as LocalDate.MIN.
I had seconds thoughts about the OBA default values and have removed them: OneBusAway/onebusaway-gtfs-modules#431
The handling of the missing value now happens in the OTP mapping process: bf0d9a9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to set up a "free fare Sunday afternoons for cash customers" rule but was not able to make it work smoothly. I'm attaching excerpts below. Basically, in order to override the regular cash fare that would normally apply, I have to populate rule_priority, however, right now, applying rule_priority hides other fare products, unless the corresponding fare leg rules also have the same priority value.
In trying to make fare products appear in the trip response, I also found an issue where leg rules with the default timeframe_regular timeframe were skipped altogether, and that needs to be fixed as well.
Happy to discuss further during the dev call.
Relevant GTFS data:
timeframes.txt (fare_regular is a calendar entry that applies 7 days, FallSunday only applies Sundays)
timeframe_group_id,start_time,end_time,service_id
timeframe_regular,,,fare_regular
timeframe_free_sundays_afternoons,12:00:00,18:00:00,FallSunday
fare_products.txt
fare_product_id,fare_product_name,fare_media_id,amount,currency
prod_free_fare_sundays_afternoons_cash,Free fare Sundays Afternoons Cash,cash,0.00,USD
prod_rapid_transit_cash,Subway cash fare,cash,2.40,USD
prod_rapid_transit_quick_subway,Subway Quick Ticket,charlieticket,2.40,USD
fare_leg_rules.txt (without priorities)
leg_group_id,network_id,from_area_id,to_area_id,fare_product_id,from_timeframe_group_id,to_timeframe_group_id,transfer_only
leg_rapid_transit_cash,rapid_transit,,,prod_rapid_transit_cash,,,1
leg_rapid_transit_cash,rapid_transit,,,prod_free_fare_sundays_afternoons_cash,timeframe_free_sundays_afternoons,,1
leg_rapid_transit_quick_subway,rapid_transit,area_bl,,prod_rapid_transit_quick_subway,,
I wrote some tests today to make sure, but I believe that this is how the priorities are supposed to work. So lets say you have three rules (I'm condensing the entities for brevity):
If rule 1 matches, then both rule 2 and 3 will be excluded. Is this what you made you scratch your head? If so then I believe that this is the correct behaviour, according to the spec: https://gtfs.org/documentation/schedule/reference/#fare_leg_rulestxt In particular:
So I believe that you need to increase the rule priority of rule 3 to 2, if you want both 1 and 3 to show up on Sundays. Let's discuss this because I do think it's a little surprising how this works. |
Yes, because in this example, I don't think the youth fare should not be affected by what is happening to the regular fare.
The spec is indeed vague about this. How I interpreted was "When multiple entries in the same |
|
@binh-dam-ibigroup I'm currently asking about this in the MobilityData Slack: https://mobilitydata-io.slack.com/archives/C01KL7PR170/p1766060365033259 |
49bbdaf to
55afdd9
Compare
|
@binh-dam-ibigroup I don't think that we will get a definitive answer on our spec question. I believe the best way forward is to come up with our own definition and then remain flexible should the spec become clearer. |
a7bf48a to
cafc4aa
Compare
# Conflicts: # application/src/ext-test/java/org/opentripplanner/ext/fares/service/gtfs/v1/custom/AtlantaFareServiceTest.java # application/src/ext-test/java/org/opentripplanner/ext/fares/service/gtfs/v1/custom/OrcaFareServiceTest.java # application/src/test-fixtures/java/org/opentripplanner/ext/fares/model/FareModelForTest.java
70d98ac to
d35953e
Compare
d35953e to
106cdf9
Compare
|
Binh and I had a private chat and we came to conclusion that we will keep the current rule priority logic as is. We are aware that the spec is not precise enough and you could definitely produce conflicting data when combining priorities and timeframes. However, CTRAN, the only feed that we know of that produces timeframes, handles this problem by producing non-overlapping timeframes. We might have to revisit this when we see this problem re-appear in real-world data. |
After our discussion, it should be noted that in order for the timeframes.txt: fare_leg_rules.txt: |
binh-dam-ibigroup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The basic logic works now, as we discussed. Thanks for the changes.
Summary
Implements GTFS FaresV2 timeframes.
In order to manage the complexity a bit better, I have introduced the following changes:
Lets have a chat about the model classes and the mappers in the dev meeting.
Unit tests
Lots added and adapted.
Documentation
Javadoc.