Skip to content
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

Add query for cancelled trips to GTFS GraphQL API #5393

Merged
merged 57 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4b052d5
Draft upcoming cancelled trips query
vesameskanen Oct 2, 2023
2e6529e
Remove duplicate imports
vesameskanen Oct 3, 2023
627d251
Node resolver for DatedTrip
vesameskanen Oct 3, 2023
6c26434
Hook in DatedTrip data fetcher
vesameskanen Oct 4, 2023
fb71d74
Feed filtering parameter for cancelled trips query
vesameskanen Oct 4, 2023
184e7e2
More efficient iteration over all trips
vesameskanen Oct 4, 2023
2787b7e
Sort cancelled trips by ascending time
vesameskanen Oct 4, 2023
58f0387
Move filtering by feed into transit service
vesameskanen Oct 4, 2023
3388c15
Merge remote-tracking branch 'otp/dev-2.x' into gtfsgraphql-cancelled…
vesameskanen Oct 17, 2023
45aacde
Merge remote-tracking branch 'otp/dev-2.x' into gtfsgraphql-cancelled…
vesameskanen Dec 28, 2023
a1fe6e3
Merge remote-tracking branch 'upstream/dev-2.x' into gtfsgraphql-canc…
optionsome Aug 6, 2024
20df02b
Use LocalDate for date and include trip's fields instead of trip
optionsome Aug 7, 2024
2a9df2a
Improve documentation and mark cancelledTripTimes as deprecated
optionsome Aug 8, 2024
b142bdf
Add start and end to schema
optionsome Aug 8, 2024
8e12d3a
Create DatedStopTime type and use it in DatedTrip
optionsome Aug 9, 2024
53ff5d5
cancelled -> canceled
optionsome Aug 9, 2024
0469361
Add graphql test
optionsome Aug 9, 2024
c0648b7
Rename method
optionsome Aug 9, 2024
6437bd7
Add small tests
optionsome Aug 9, 2024
6e143d9
Realtime -> RealTime
optionsome Aug 9, 2024
1de24b2
Add more tests
optionsome Aug 9, 2024
7251391
Refactor canceled trips fetching to be more efficient
optionsome Sep 9, 2024
bedee96
Update and fix tests
optionsome Sep 9, 2024
c0768e0
Create an union for dated stoptimes
optionsome Sep 9, 2024
66100b9
Use TripOnServiceDate and redesign schema
optionsome Oct 18, 2024
284c483
Merge remote-tracking branch 'upstream/dev-2.x' into gtfsgraphql-canc…
optionsome Oct 18, 2024
079485e
Remove stuff from new stoptime type
optionsome Oct 25, 2024
c15a29e
Mark stopTimes as non-null
optionsome Oct 25, 2024
65927c6
Do less inside timetable snapshot provider initialization
optionsome Oct 25, 2024
9c124df
Minor fixes
optionsome Oct 25, 2024
9e5eb14
Rename FixedDatedStopTime -> FixedStopTimeOnServiceDate
optionsome Oct 25, 2024
c8924fc
Merge remote-tracking branch 'upstream/dev-2.x' into gtfsgraphql-canc…
optionsome Oct 25, 2024
7f1948e
Run codegen
optionsome Oct 25, 2024
7ed48c3
Improve schema doc and mark some fields as non-null
optionsome Oct 31, 2024
2797fa5
Slightly refactor methods to fetch cancelled trips
optionsome Nov 1, 2024
a2b30f8
Improve schema doc
optionsome Nov 1, 2024
6eaef7a
Rename date -> serviceDate
optionsome Nov 1, 2024
396c43c
Rename ArrivalDepartureTime -> FixedArrivalDepartureTime and LegTime …
optionsome Nov 1, 2024
be25fe3
Merge remote-tracking branch 'upstream/dev-2.x' into gtfsgraphql-canc…
optionsome Nov 2, 2024
672a968
Make TripOnServiceDate an interface and rename some types
optionsome Nov 13, 2024
ec59d99
Merge remote-tracking branch 'upstream/dev-2.x' into gtfsgraphql-canc…
optionsome Nov 13, 2024
8885c19
Rename RegularArrivalDepartureTime -> LegCallTime
optionsome Nov 17, 2024
c7d6d43
Refactor LegCallTime
optionsome Nov 17, 2024
178c150
Rename StopTime -> StopCall etc. and create own model for its times
optionsome Nov 18, 2024
349efb6
Create implementations for call times
optionsome Nov 18, 2024
405f580
Remove support for feeds argument
optionsome Nov 19, 2024
ac21d8a
Improve doc
optionsome Nov 21, 2024
ca53100
Redesign schema
optionsome Nov 22, 2024
45a01af
Merge remote-tracking branch 'upstream/dev-2.x' into gtfsgraphql-canc…
optionsome Nov 22, 2024
de5758b
Add module test for listing canceled trips
leonardehrenfried Nov 25, 2024
e6c0036
Remove duplication
leonardehrenfried Nov 25, 2024
bee85de
Renaming or ordering
optionsome Nov 25, 2024
dba65b0
Update application/src/main/resources/org/opentripplanner/apis/gtfs/s…
optionsome Nov 26, 2024
b3bad26
Implement new schema design
optionsome Dec 2, 2024
ff426dc
Merge remote-tracking branch 'upstream/dev-2.x' into gtfsgraphql-canc…
optionsome Dec 2, 2024
6a485a3
Minor schema doc fixes
optionsome Dec 2, 2024
5217ce5
Formatting
optionsome Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.model.fare.FareProductUse;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.model.plan.LegTime;
import org.opentripplanner.model.plan.LegCallTime;
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.StopArrival;
import org.opentripplanner.model.plan.TransitLeg;
Expand Down Expand Up @@ -55,12 +55,12 @@ public Trip getTrip() {
}

@Override
public LegTime start() {
public LegCallTime start() {
return first.start();
}

@Override
public LegTime end() {
public LegCallTime end() {
return second.end();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.opentripplanner.model.PickDrop;
import org.opentripplanner.model.fare.FareProductUse;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.model.plan.LegTime;
import org.opentripplanner.model.plan.LegCallTime;
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.StopArrival;
import org.opentripplanner.model.plan.TransitLeg;
Expand Down Expand Up @@ -87,13 +87,13 @@ public Accessibility getTripWheelchairAccessibility() {
}

@Override
public LegTime start() {
return LegTime.ofStatic(startTime);
public LegCallTime start() {
return LegCallTime.ofStatic(startTime);
}

@Override
public LegTime end() {
return LegTime.ofStatic(endTime);
public LegCallTime end() {
return LegCallTime.ofStatic(endTime);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ApiLeg mapLeg(

api.departureDelay = domain.getDepartureDelay();
api.arrivalDelay = domain.getArrivalDelay();
api.realTime = domain.getRealTime();
api.realTime = domain.isRealTimeUpdated();
api.isNonExactFrequency = domain.getNonExactFrequency();
api.headway = domain.getHeadway();
api.distance = round3Decimals(domain.getDistanceMeters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import java.time.Instant;
import java.util.Locale;
import javax.annotation.Nullable;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLFilterPlaceType;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLFormFactor;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLInputField;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRoutingErrorCode;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLTransitMode;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLWheelchairBoarding;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.routing.api.response.InputField;
import org.opentripplanner.routing.api.response.RoutingErrorCode;
import org.opentripplanner.routing.graphfinder.PlaceType;
Expand Down Expand Up @@ -109,4 +111,17 @@ public static boolean startsWith(String str, String name, Locale locale) {
public static boolean startsWith(I18NString str, String name, Locale locale) {
return str != null && str.toString(locale).toLowerCase(locale).startsWith(name);
}

/**
* Generally the missing values are removed during the graph build. However, for flex trips they
* are not and have to be converted to null here.
*/
@Nullable
public static Integer stopTimeToInt(int value) {
if (value == StopTime.MISSING_VALUE) {
return null;
} else {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@
import org.opentripplanner.apis.gtfs.datafetchers.BikeRentalStationImpl;
import org.opentripplanner.apis.gtfs.datafetchers.BookingInfoImpl;
import org.opentripplanner.apis.gtfs.datafetchers.BookingTimeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.CallScheduledTimeTypeResolver;
import org.opentripplanner.apis.gtfs.datafetchers.CallStopLocationTypeResolver;
import org.opentripplanner.apis.gtfs.datafetchers.CarParkImpl;
import org.opentripplanner.apis.gtfs.datafetchers.ContactInfoImpl;
import org.opentripplanner.apis.gtfs.datafetchers.CoordinatesImpl;
import org.opentripplanner.apis.gtfs.datafetchers.CurrencyImpl;
import org.opentripplanner.apis.gtfs.datafetchers.DefaultFareProductImpl;
import org.opentripplanner.apis.gtfs.datafetchers.DepartureRowImpl;
import org.opentripplanner.apis.gtfs.datafetchers.EstimatedTimeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.FareProductTypeResolver;
import org.opentripplanner.apis.gtfs.datafetchers.FareProductUseImpl;
import org.opentripplanner.apis.gtfs.datafetchers.FeedImpl;
import org.opentripplanner.apis.gtfs.datafetchers.GeometryImpl;
import org.opentripplanner.apis.gtfs.datafetchers.ItineraryImpl;
import org.opentripplanner.apis.gtfs.datafetchers.LegImpl;
import org.opentripplanner.apis.gtfs.datafetchers.LegTimeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.MoneyImpl;
import org.opentripplanner.apis.gtfs.datafetchers.NodeTypeResolver;
import org.opentripplanner.apis.gtfs.datafetchers.OpeningHoursImpl;
Expand All @@ -52,13 +56,15 @@
import org.opentripplanner.apis.gtfs.datafetchers.PlanConnectionImpl;
import org.opentripplanner.apis.gtfs.datafetchers.PlanImpl;
import org.opentripplanner.apis.gtfs.datafetchers.QueryTypeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RealTimeEstimateImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RentalPlaceTypeResolver;
import org.opentripplanner.apis.gtfs.datafetchers.RentalVehicleImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RentalVehicleTypeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RideHailingEstimateImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RouteImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RouteTypeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RoutingErrorImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopCallImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopGeometriesImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopImpl;
import org.opentripplanner.apis.gtfs.datafetchers.StopOnRouteImpl;
Expand All @@ -71,6 +77,7 @@
import org.opentripplanner.apis.gtfs.datafetchers.TranslatedStringImpl;
import org.opentripplanner.apis.gtfs.datafetchers.TripImpl;
import org.opentripplanner.apis.gtfs.datafetchers.TripOccupancyImpl;
import org.opentripplanner.apis.gtfs.datafetchers.TripOnServiceDateImpl;
import org.opentripplanner.apis.gtfs.datafetchers.UnknownImpl;
import org.opentripplanner.apis.gtfs.datafetchers.VehicleParkingImpl;
import org.opentripplanner.apis.gtfs.datafetchers.VehiclePositionImpl;
Expand Down Expand Up @@ -128,6 +135,8 @@ protected static GraphQLSchema buildSchema() {
.type("StopPosition", type -> type.typeResolver(new StopPosition() {}))
.type("FareProduct", type -> type.typeResolver(new FareProductTypeResolver()))
.type("AlertEntity", type -> type.typeResolver(new AlertEntityTypeResolver()))
.type("CallStopLocation", type -> type.typeResolver(new CallStopLocationTypeResolver()))
.type("CallScheduledTime", type -> type.typeResolver(new CallScheduledTimeTypeResolver()))
.type(typeWiring.build(AgencyImpl.class))
.type(typeWiring.build(AlertImpl.class))
.type(typeWiring.build(BikeParkImpl.class))
Expand Down Expand Up @@ -180,7 +189,12 @@ protected static GraphQLSchema buildSchema() {
.type(typeWiring.build(CurrencyImpl.class))
.type(typeWiring.build(FareProductUseImpl.class))
.type(typeWiring.build(DefaultFareProductImpl.class))
.type(typeWiring.build(TripOnServiceDateImpl.class))
.type(typeWiring.build(StopCallImpl.class))
.type(typeWiring.build(TripOccupancyImpl.class))
.type(typeWiring.build(LegTimeImpl.class))
.type(typeWiring.build(RealTimeEstimateImpl.class))
.type(typeWiring.build(EstimatedTimeImpl.class))
.build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
return schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.TypeResolutionEnvironment;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.TypeResolver;
import org.opentripplanner.apis.gtfs.model.ArrivalDepartureTime;

public class CallScheduledTimeTypeResolver implements TypeResolver {

@Override
public GraphQLObjectType getType(TypeResolutionEnvironment environment) {
Object o = environment.getObject();
GraphQLSchema schema = environment.getSchema();

if (o instanceof ArrivalDepartureTime) {
return schema.getObjectType("ArrivalDepartureTime");
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.TypeResolutionEnvironment;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.TypeResolver;
import org.opentripplanner.transit.model.site.StopLocation;

public class CallStopLocationTypeResolver implements TypeResolver {

@Override
public GraphQLObjectType getType(TypeResolutionEnvironment environment) {
Object o = environment.getObject();
GraphQLSchema schema = environment.getSchema();

if (o instanceof StopLocation) {
return schema.getObjectType("Stop");
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.time.Duration;
import java.time.OffsetDateTime;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.transit.model.timetable.EstimatedTime;

public class EstimatedTimeImpl implements GraphQLDataFetchers.GraphQLEstimatedTime {

@Override
public DataFetcher<Duration> delay() {
return environment -> getSource(environment).delay();
}

@Override
public DataFetcher<OffsetDateTime> time() {
return environment -> getSource(environment).time().toOffsetDateTime();
}

private EstimatedTime getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.apis.gtfs.mapping.NumberMapper;
import org.opentripplanner.apis.gtfs.mapping.PickDropMapper;
import org.opentripplanner.apis.gtfs.mapping.RealtimeStateMapper;
import org.opentripplanner.ext.restapi.mapping.LocalDateMapper;
import org.opentripplanner.ext.ridehailing.model.RideEstimate;
import org.opentripplanner.ext.ridehailing.model.RideHailingLeg;
import org.opentripplanner.framework.graphql.GraphQLUtils;
import org.opentripplanner.model.PickDrop;
import org.opentripplanner.model.fare.FareProductUse;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.model.plan.LegTime;
import org.opentripplanner.model.plan.LegCallTime;
import org.opentripplanner.model.plan.ScheduledTransitLeg;
import org.opentripplanner.model.plan.StopArrival;
import org.opentripplanner.model.plan.StreetLeg;
Expand Down Expand Up @@ -67,12 +67,12 @@ public DataFetcher<BookingInfo> dropOffBookingInfo() {
}

@Override
public DataFetcher<String> dropoffType() {
public DataFetcher<GraphQLTypes.GraphQLPickupDropoffType> dropoffType() {
Copy link
Member

Choose a reason for hiding this comment

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

Very nice.

return environment -> {
if (getSource(environment).getAlightRule() == null) {
return PickDrop.SCHEDULED.name();
return GraphQLTypes.GraphQLPickupDropoffType.SCHEDULED;
}
return getSource(environment).getAlightRule().name();
return PickDropMapper.map(getSource(environment).getAlightRule());
};
}

Expand All @@ -82,7 +82,7 @@ public DataFetcher<Double> duration() {
}

@Override
public DataFetcher<LegTime> end() {
public DataFetcher<LegCallTime> end() {
return environment -> getSource(environment).end();
}

Expand Down Expand Up @@ -178,18 +178,18 @@ public DataFetcher<BookingInfo> pickupBookingInfo() {
}

@Override
public DataFetcher<String> pickupType() {
public DataFetcher<GraphQLTypes.GraphQLPickupDropoffType> pickupType() {
return environment -> {
if (getSource(environment).getBoardRule() == null) {
return PickDrop.SCHEDULED.name();
return GraphQLTypes.GraphQLPickupDropoffType.SCHEDULED;
}
return getSource(environment).getBoardRule().name();
return PickDropMapper.map(getSource(environment).getBoardRule());
};
}

@Override
public DataFetcher<Boolean> realTime() {
return environment -> getSource(environment).getRealTime();
return environment -> getSource(environment).isRealTimeUpdated();
}

@Override
Expand Down Expand Up @@ -228,7 +228,7 @@ public DataFetcher<String> serviceDate() {
}

@Override
public DataFetcher<LegTime> start() {
public DataFetcher<LegCallTime> start() {
return environment -> getSource(environment).start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.time.OffsetDateTime;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.model.plan.LegCallTime;
import org.opentripplanner.model.plan.LegRealTimeEstimate;

public class LegTimeImpl implements GraphQLDataFetchers.GraphQLLegTime {

@Override
public DataFetcher<LegRealTimeEstimate> estimated() {
return environment -> getSource(environment).estimated();
}

@Override
public DataFetcher<OffsetDateTime> scheduledTime() {
return environment -> getSource(environment).scheduledTime().toOffsetDateTime();
}

private LegCallTime getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.opentripplanner.apis.gtfs.model.StopPosition;
import org.opentripplanner.apis.gtfs.model.StopPosition.PositionAtStop;
import org.opentripplanner.framework.graphql.GraphQLUtils;
import org.opentripplanner.model.plan.LegTime;
import org.opentripplanner.model.plan.LegCallTime;
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.StopArrival;
import org.opentripplanner.model.plan.VertexType;
Expand All @@ -19,7 +19,7 @@
public class PlaceImpl implements GraphQLDataFetchers.GraphQLPlace {

@Override
public DataFetcher<LegTime> arrival() {
public DataFetcher<LegCallTime> arrival() {
return environment -> getSource(environment).arrival;
}

Expand Down Expand Up @@ -58,7 +58,7 @@ public DataFetcher<VehicleParking> carPark() {

@Deprecated
@Override
public DataFetcher<LegTime> departure() {
public DataFetcher<LegCallTime> departure() {
return environment -> getSource(environment).departure;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.opentripplanner.transit.model.site.Station;
import org.opentripplanner.transit.model.site.StopLocation;
import org.opentripplanner.transit.model.timetable.Trip;
import org.opentripplanner.transit.model.timetable.TripOnServiceDate;
import org.opentripplanner.transit.service.TransitService;
import org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher;
import org.opentripplanner.utils.time.ServiceDateUtils;
Expand Down Expand Up @@ -195,7 +196,10 @@ public DataFetcher<Iterable<VehicleRentalPlace>> bikeRentalStations() {
};
}

// TODO
/**
* @deprecated Replaced by {@link #canceledTrips()}.
*/
@Deprecated
@Override
public DataFetcher<Iterable<TripTimeOnDate>> cancelledTripTimes() {
return environment -> null;
Expand Down Expand Up @@ -831,6 +835,14 @@ public DataFetcher<Iterable<Trip>> trips() {
};
}

@Override
public DataFetcher<Connection<TripOnServiceDate>> canceledTrips() {
return environment -> {
var trips = getTransitService(environment).listCanceledTrips();
return new SimpleListConnection<>(trips).get(environment);
};
}

@Override
public DataFetcher<VehicleParking> vehicleParking() {
return environment -> {
Expand Down
Loading
Loading