Skip to content

Refactoring SIRI StopConditions from TransitAlert to EntitySelector - #4196

Merged
hannesj merged 6 commits into
opentripplanner:dev-2.xfrom
entur:refactor_siri_stopconditions
Nov 4, 2022
Merged

hannesj merged 6 commits into
opentripplanner:dev-2.xfrom
entur:refactor_siri_stopconditions

Conversation

@lassetyr

@lassetyr lassetyr commented Jun 1, 2022

Copy link
Copy Markdown
Contributor

Summary

The SIRI SX StopConditions can be defined separately on each StopPoint, and OTP needs to support that. Today the StopConditions are combined and added to the entire TransitAlert.

This PR is intended to be the starting point of a discussion on how this best should be solved.

Necessary requirements:
Example-datastructure:

- TransitAlert
  - EntitySelector 1
      - trip 1
      - stop 1
      - [StopCondition.START_POINT]
  - EntitySelector 2
      - trip 1 
      - stop 2
      - [StopCondition.START_POINT, StopCondition.DESTINATION]
  - EntitySelector 3
      - trip 1
      - stop 3
      - [StopCondition.DESTINATION]

Each stop may have a different set of StopConditions that needs to be included in each EntitySelector

When adding alerts to a trip-result in AlertToLegMapper, the EntitySelector should only return a match if both the stopId match, and at least one of the EntitySelector's StopConditions matches the current StopCondition-filter for each part of the Leg.
E.g. if a leg matches both trip and stops in the example above:
-filtering on START_POINT should return EntitySelector 1 and 2
-filtering on DESTINATION should return EntitySelector 2 and 3
-filtering on both START_POINT and DESTINATION should return all 3
-filtering on REQUEST_STOP should return none of them
-when the filter is empty, all EntitySelectors should be returned

Currently, the EntitySelector for e.g. trip/stop is matched by using an equals/hashcode towards a HashMap in the index. When matching StopConditions in an EntitySelector, the StopConditions used to filter does not necessarily need to be equal, but can either contain a subset or superset of the StopConditions in the EntitySelector - or the filter can be empty. Because of this, it is not obvious that the StopCondition-matching should be performed in the equals().

Any good ideas?

Issue

closes #4142

@leonardehrenfried

Copy link
Copy Markdown
Member

What about setting up separate indices for each StopCondition. So you say "Give me everything with DESTINATION and everything with START_POINT" and in the end you remove the duplicates (if there is a result that has both conditions).

@t2gran t2gran added this to the 2.2 milestone Jun 7, 2022
@t2gran t2gran added the +Real-Time The issue/PR is related to RealTime updates label Jun 7, 2022
@hannesj
hannesj force-pushed the refactor_siri_stopconditions branch from 9fabcd4 to 72801c7 Compare October 25, 2022 18:51
@hannesj
hannesj marked this pull request as ready for review November 1, 2022 12:42
@hannesj
hannesj requested a review from a team as a code owner November 1, 2022 12:42
@hannesj

hannesj commented Nov 1, 2022

Copy link
Copy Markdown
Contributor

This is now ready for review. However we need to discuss the semantics of the handling around the service date for a Trip keyed alert. Should we return alerts which don't have any date associated to a trip when requesting the alerts for a trip for a specific date?

@t2gran t2gran modified the milestones: 2.2, 2.3 Nov 1, 2022
@lassetyr

lassetyr commented Nov 2, 2022

Copy link
Copy Markdown
Contributor Author

I think alerts tagged on a Trip by ID (and not a specific date) should apply to all occurrences of that trip within the defined validity-period for the alert.

I.e. no specified date then means "any date".

@hannesj
hannesj force-pushed the refactor_siri_stopconditions branch from ecc5ebf to 2bb2a35 Compare November 4, 2022 12:17
hannesj
hannesj previously approved these changes Nov 4, 2022
@optionsome
optionsome self-requested a review November 4, 2022 13:50
public class StopConditionsHelper {

/**
* Matches an EntitySelector's stopConditions with the stopConditions required. Returns true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand this sentence.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expanded javadoc

Comment on lines +60 to +62
Set<StopCondition> stopConditions = isFirstLeg
? StopCondition.DEPARTURE
: StopCondition.FIRST_DEPARTURE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this logic upside down? I would expect first leg to use StopCondition.FIRST_DEPARTURE.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good find, fixed


@Override
public Collection<TransitAlert> getStopAlerts(FeedScopedId stop) {
public Collection<TransitAlert> getStopAlerts(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add some javadoc on the class here (not needed for the methods) so it's easier to understand what is the purpose of this Delegating service.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done

// Then transitAlertService should have been called with stop and route ids
Mockito.verify(transitAlertService, Mockito.atLeastOnce()).getStopAlerts(A.stop.getId());
Mockito.verify(transitAlertService, Mockito.atLeastOnce()).getStopAlerts(E.stop.getId());
Mockito

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just out of curiosity, do we need to use mockito here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We check that the transitAlertService gets queried with the correct arguments, without needing to have one.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Base: 60.46% // Head: 60.48% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (fbf875f) compared to base (dbecc35).
Patch coverage: 51.50% of modified lines in pull request are covered.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #4196      +/-   ##
=============================================
+ Coverage      60.46%   60.48%   +0.01%     
- Complexity     12110    12125      +15     
=============================================
  Files           1574     1577       +3     
  Lines          63274    63232      -42     
  Branches        7005     6992      -13     
=============================================
- Hits           38256    38243      -13     
+ Misses         22838    22807      -31     
- Partials        2180     2182       +2     
Impacted Files Coverage Δ
...aphqlapi/datafetchers/LegacyGraphQLAgencyImpl.java 24.44% <0.00%> (+0.53%) ⬆️
...raphqlapi/datafetchers/LegacyGraphQLAlertImpl.java 12.50% <0.00%> (-0.08%) ⬇️
...graphqlapi/datafetchers/LegacyGraphQLFeedImpl.java 11.11% <0.00%> (ø)
...phqlapi/datafetchers/LegacyGraphQLPatternImpl.java 13.27% <0.00%> (ø)
...qlapi/datafetchers/LegacyGraphQLQueryTypeImpl.java 6.19% <0.00%> (+0.04%) ⬆️
...raphqlapi/datafetchers/LegacyGraphQLRouteImpl.java 17.00% <0.00%> (+0.33%) ⬆️
...graphqlapi/datafetchers/LegacyGraphQLStopImpl.java 11.06% <0.00%> (-0.09%) ⬇️
...graphqlapi/datafetchers/LegacyGraphQLTripImpl.java 13.40% <0.00%> (ø)
...transmodelapi/model/siri/et/EstimatedCallType.java 67.33% <0.00%> (+0.27%) ⬆️
...modelapi/model/siri/sx/PtSituationElementType.java 58.06% <0.00%> (ø)
... and 16 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@hannesj
hannesj merged commit a005235 into opentripplanner:dev-2.x Nov 4, 2022
@hannesj
hannesj deleted the refactor_siri_stopconditions branch November 4, 2022 20:29
t2gran pushed a commit that referenced this pull request Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+Real-Time The issue/PR is related to RealTime updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIRI SX: StopConditions should be handled in the entity selectors

6 participants