-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cleanup itinerary, make it immutable #6535
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
Cleanup itinerary, make it immutable #6535
Conversation
To avoid rounding errors we should use centi-seconds in cost. This is the same resolution used in Raptor.
When legs are modified the totals are recalculated, when this happen we need to add the original elevation edge calculation together with the new totals from elevation profile.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #6535 +/- ##
=============================================
+ Coverage 70.22% 70.24% +0.02%
- Complexity 18331 18367 +36
=============================================
Files 2085 2087 +2
Lines 77308 77383 +75
Branches 7840 7840
=============================================
+ Hits 54286 54359 +73
+ Misses 20250 20249 -1
- Partials 2772 2775 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 read through the code and even though I could find a few typos I chose to leave them as is and we will clean the up later.
I also ran the IBI smoke test suite on this PR and it passed so I'm pretty confident that no bugs were introduced.
And there is a fix for the tests that you had to disable: leonardehrenfried@61eab43
You may want to cherry-pick (not merge) it. If not we can do it afterwards.
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.
Nice job. This is a bit too big to do a thorough review but I commented on a few minor things that can be addressed later.
|
||
assertEquals(1, itineraries.size()); | ||
itinerary = itineraries.getFirst(); |
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.
Nit: I think it would be nicer to use separate variables for the original and the modified itineraries
@@ -428,8 +445,8 @@ public void setElevationGained(Double elevationGained) { | |||
* <p> | |||
* -1 indicate that the cost is not set/computed. |
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.
This comment should be updated
|
||
public List<ScheduledTransitLeg> getScheduledTransitLegs() { | ||
return getLegs() | ||
public List<ScheduledTransitLeg> findScheduledTransitLegs() { |
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.
Using "find" here seems strange to me. Shouldn't it rather be listScheduledTransitLegs()
?
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.
Agree, this was a mistake.
.parallelStream() | ||
.map(leg -> decorateLegWithRideEstimate(i, leg, service)) | ||
.toList(); | ||
|
||
i.setLegs(legs); | ||
return builder.withLegs(ignore -> legs).build(); |
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.
Why don't we run the decoration in this lambda?
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.
Because we are updating the existing legs, not setting them. You always start with creating a builder passing in the legs. So, I wanted to make sure the developer setting the legs we careful - not just replacing the new legs, witch may cause information loss.
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 will add a comment on it.
/** | ||
* The fare products of this itinerary. | ||
*/ | ||
public ItineraryFares fare() { |
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.
Shouldn't this be called fares()
to be consistent with the type name?
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 typename is wrong - it is not a collection of fares it is THE itinerary fare. I can change the typename in a followup PR.
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.
Sometimes 'Information' or 'Info' is added to the class name in cases where the plural is used in this way make it easier to read/talk in natural english. E.g. ItineraryFareInfo
} | ||
|
||
static RoutingResult empty() { | ||
return new RoutingResult(null, null); |
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 think this class would be simpler to follow if you used Collections.emptyList()
instead of null parameters.
@leonardehrenfried Feel free to comment on them, then I can fix them in a follow up PR. |
@habrahamsson-skanetrafiken thank you for the feedback, I will make the fixes in a follwup PR as soon as this is merged. There was a merge conflict so I need the approvals again :-) |
Fix NPE in RoutingWorker after #6535 was merged
Summary
Cleanup Itinerary code. This started with an few errors in our logs at entur, see #6534. The error happens in the mapping in the GraphQL code, but the a negative cost should not be allowed on the itinerary. This PR clean up the Itinerary and
make it immutable except the lifecycle
systemNotices
field.I have added a few TODOs for further cleanup. Also the builder setters and Itinerary getter for
generalizedCost
should use the type-safeCost
type - I changed the internal representation from int to Cost, but has not converted the external representation everywhere.Notable changes
Review
Issue
This is related to #6534
Unit tests
✅ I have extracted some code and added unit-test for it, other than that I relay on existing tests.
Documentation
✅ The JavaDoc is updated in a few places.
Changelog
🟥 Not relevant
Bumping the serialization version id
✅ The
Cost
class is changed