Skip to content

Add available types and spaces to VehicleRentalStation - #5425

Merged
optionsome merged 3 commits into
opentripplanner:dev-2.xfrom
cedarbaum:vehicle_rental_station_vehicle_types
Oct 26, 2023
Merged

optionsome merged 3 commits into
opentripplanner:dev-2.xfrom
cedarbaum:vehicle_rental_station_vehicle_types

Conversation

@cedarbaum

Copy link
Copy Markdown
Contributor

Summary

This PR adds vehicleTypesAvailable and vehicleSpacesAvailable to the VehicleRentalStation type. These fields return the count of each vehicle type available for pickup and drop-off, respectively. As an example, this is what the new fields look like in the vehicleRentalStation query:

...
    "vehicleRentalStation": {
      "stationId": "NYC:cc7b86cf-a2fb-4738-b967-de7b197dc930",
      "name": "Ave A & E 14 St",
      "vehiclesAvailable": 2,
      "vehicleTypesAvailable": [
        {
          "vehicleType": {
            "formFactor": "BICYCLE",
            "propulsionType": "HUMAN"
          },
          "count": 0
        },
        {
          "vehicleType": {
            "formFactor": "BICYCLE",
            "propulsionType": "ELECTRIC_ASSIST"
          },
          "count": 2
        }
      ],
...

Issue

N/A

Unit tests

  • GraphQL integration test added that runs the vehicleRentalStation query with the new fields
  • Manual testing done with the interactive GraphQL explorer

Documentation

  • Documentation added for new GraphQL fields

@cedarbaum
cedarbaum requested a review from a team as a code owner October 12, 2023 19:53
@codecov

codecov Bot commented Oct 12, 2023 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fc29339) 66.67% compared to head (8575360) 66.87%.
Report is 101 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5425      +/-   ##
=============================================
+ Coverage      66.67%   66.87%   +0.19%     
- Complexity     15396    15495      +99     
=============================================
  Files           1794     1800       +6     
  Lines          69682    69793     +111     
  Branches        7345     7353       +8     
=============================================
+ Hits           46461    46672     +211     
+ Misses         20757    20662      -95     
+ Partials        2464     2459       -5     
Files Coverage Δ
...is/gtfs/datafetchers/VehicleRentalStationImpl.java 91.30% <100.00%> (+5.59%) ⬆️
...anner/apis/gtfs/generated/GraphQLDataFetchers.java 0.00% <ø> (ø)
...vehiclerental/model/RentalVehicleEntityCounts.java 100.00% <100.00%> (ø)
...ce/vehiclerental/model/RentalVehicleTypeCount.java 100.00% <100.00%> (ø)
...vice/vehiclerental/model/VehicleRentalStation.java 96.82% <100.00%> (+2.38%) ⬆️

... and 49 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leonardehrenfried leonardehrenfried left a comment

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.

For a very first PR this is a really good job!

I've left a few comments about things that I'd like you to change.

The failing test will be fixed if you add a mapping for VehicleTypeCount in the codegen config:

VehicleRentalStation: org.opentripplanner.service.vehiclerental.model.VehicleRentalStation#VehicleRentalStation

We will be doing some thinking over the next few days if the want to keep the API schema or will ask you to change it.

@@ -0,0 +1,37 @@
{

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.

Well done for finding out how to use these tests.

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.

We are now adding tests for this in two different prs, since this is a more complete version, lets try to get this merged first and I'll update #5411 afterwards.

Comment on lines +572 to +581
"""
Number of vehicles currently available on the rental station, grouped by vehicle type.
"""
vehicleTypesAvailable: [RentalVehicleTypeCount!]

"""
Number of free spaces currently available on the rental station, grouped by vehicle type.
"""
vehicleSpacesAvailable: [RentalVehicleTypeCount!]

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 think this is a good way of expressing the information but we will discuss this in one of our meeting if we can do better. (We leave ourselves lots of time to think about API schemas because once they are released it's almost impossible to change them later.)

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 think I would model this something like this (names are up for discussion):
image

Comment thread src/test/java/org/opentripplanner/apis/gtfs/GraphQLIntegrationTest.java Outdated
@leonardehrenfried

Copy link
Copy Markdown
Member

Also please merge or rebase onto dev-2.x so I can get an accurate view of the code coverage.

@cedarbaum
cedarbaum force-pushed the vehicle_rental_station_vehicle_types branch 3 times, most recently from b356df7 to cc4f2f3 Compare October 14, 2023 00:48
Comment on lines +193 to +212
public List<RentalVehicleTypeCount> getVehicleTypeCounts() {
return vehicleRentalTypeMapToList(vehicleTypesAvailable);
}

public List<RentalVehicleTypeCount> getVehicleSpaceCounts() {
return vehicleRentalTypeMapToList(vehicleSpacesAvailable);
}

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.

This file is not a good example but we would like to see Javadoc for all public methods.

Comment on lines +575 to +580
vehicleTypesAvailable: [RentalVehicleTypeCount!]

"""
Number of free spaces currently available on the rental station, grouped by vehicle type.
"""
vehicleSpacesAvailable: [RentalVehicleTypeCount!]

@leonardehrenfried leonardehrenfried Oct 16, 2023 •

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 thinking out aloud: whenever I read a repeated word in the schema I wonder if these two properties should be grouped together. Perhaps something like this:

availability {
  types: VehicleTypeCount
  spaces: VehicleTypeCount
}

cc @optionsome @t2gran

(Please don't do anything yet, @cedarbaum, as this thought is not fully formed yet. We will discuss in a dev meeting.)

@leonardehrenfried leonardehrenfried Oct 17, 2023 •

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.

@optionsome and I had a chat what we want the schema to look like and we have landed on the following (pseudo-graphqls language):

availableVehicles {
  total: Int
  byType: [VehicleTypeCount!]!
}

availableSpaces {
  total: Int
  byType: [VehicleTypeCount!]!
}

We also want to deprecate the spacesAvailable and vehiclesAvailable fields so it's not too confusing for the consumers.

Does this make sense, @cedarbaum ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This makes sense, I went ahead and updated the PR with the new query structure. I did keep the Rental prefix for the GraphQL types to be consistent with other existing types, but let me know if you have a preference for these type names (RentalVehicleEntityCounts and RentalVehicleTypeCount, specifically).

I also noticed that @t2gran proposed an alternative query structure. Is there consensus with the maintainers about the final design or is it still being discussed? If it's still being discussed and it would be helpful for me to attend a future dev meeting, I am happy to do so!

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.

Well I thought there was a consensus until there wasn't. :)

We will definitely discuss this again today at our meeting at 3pm CET. Everybody is welcome to attend but it will not be required to get this merged.

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 am fine with the suggestion made by @optionsome and @leonardehrenfried.

@cedarbaum
cedarbaum force-pushed the vehicle_rental_station_vehicle_types branch from cc4f2f3 to 859b168 Compare October 17, 2023 01:29
@leonardehrenfried leonardehrenfried changed the title [API] Add vehicleTypesAvailable and vehicleSpacesAvailable to VehicleRentalStation Add vehicleTypesAvailable and vehicleSpacesAvailable to VehicleRentalStation Oct 17, 2023
@leonardehrenfried leonardehrenfried added the !Improvement A functional improvement or micro feature label Oct 17, 2023
@leonardehrenfried leonardehrenfried changed the title Add vehicleTypesAvailable and vehicleSpacesAvailable to VehicleRentalStation Add available types and spaces to VehicleRentalStation Oct 17, 2023
@cedarbaum
cedarbaum force-pushed the vehicle_rental_station_vehicle_types branch from 859b168 to 89a6b14 Compare October 19, 2023 03:59
@leonardehrenfried

Copy link
Copy Markdown
Member

Quick update, @cedarbaum: There was a bit of miscommunication between @optionsome, I and @t2gran as the latter hadn't realised that we made a proposal for the schema.

He's going to take another look at what we suggested and will let us know if he agrees or not.

@t2gran
t2gran removed their request for review October 24, 2023 11:47
@t2gran

t2gran commented Oct 24, 2023

Copy link
Copy Markdown
Member

I will leave the final review to @leonardehrenfried and @optionsome. Thank you for contributing.

Comment thread src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls Outdated
Comment thread src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls Outdated

@leonardehrenfried leonardehrenfried left a comment

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've taken the liberty to apply a few cosmetic changes directly. I hope this is ok.

Thanks for the contribution!


type RentalVehicleEntityCounts {
"""The total number of entities (e.g. vehicles, spaces)."""
total: Int!

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 think this should be nullable because I know there are rental operators who are incapable of reporting realtime status of available vehicles/spaces for the stations. We can discuss this in the developer meeting today @leonardehrenfried. Alternatively, the available spaces/vehicles fields could be nullable.

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.

In GBFS they are mandatory. Are you thinking of your own custom importer for Vilkuu?

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'm not sure about this. The 2.3 documentation says for num_docks_available "REQUIRED except for stations that have unlimited docking capacity (for example, valet stations) ". We got rid of the Vilkku updater as they now provide gbfs but it still has similar problems and it can't be the only network in the world where they are not able to provide real numbers for everything.

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.

Ok, lets have a chat on the call today.

Comment thread src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls Outdated
Comment thread src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls Outdated
@optionsome
optionsome merged commit eaf1ea2 into opentripplanner:dev-2.x Oct 26, 2023
t2gran pushed a commit that referenced this pull request Oct 26, 2023
@t2gran t2gran added this to the 2.5 (next release) milestone Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Improvement A functional improvement or micro feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants