-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create DatedStopTime type and use it in DatedTrip
- Loading branch information
1 parent
b142bdf
commit 8e12d3a
Showing
11 changed files
with
311 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/main/java/org/opentripplanner/apis/gtfs/datafetchers/DatedStopTimeImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package org.opentripplanner.apis.gtfs.datafetchers; | ||
|
||
import static org.opentripplanner.apis.gtfs.GraphQLUtils.stopTimeToInt; | ||
|
||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.time.ZonedDateTime; | ||
import org.opentripplanner.apis.gtfs.GraphQLRequestContext; | ||
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers; | ||
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes; | ||
import org.opentripplanner.apis.gtfs.mapping.PickDropMapper; | ||
import org.opentripplanner.apis.gtfs.model.ArrivalDepartureTime; | ||
import org.opentripplanner.framework.graphql.GraphQLUtils; | ||
import org.opentripplanner.framework.time.ServiceDateUtils; | ||
import org.opentripplanner.model.TripTimeOnDate; | ||
import org.opentripplanner.transit.service.TransitService; | ||
|
||
public class DatedStopTimeImpl implements GraphQLDataFetchers.GraphQLDatedStopTime { | ||
|
||
@Override | ||
public DataFetcher<ArrivalDepartureTime> arrival() { | ||
return environment -> { | ||
var tripTime = getSource(environment); | ||
var scheduledTime = getZonedDateTime(environment, tripTime.getScheduledArrival()); | ||
if (scheduledTime == null) { | ||
return null; | ||
} | ||
return tripTime.isRealtime() | ||
? ArrivalDepartureTime.of(scheduledTime, tripTime.getArrivalDelay()) | ||
: ArrivalDepartureTime.ofStatic(scheduledTime); | ||
}; | ||
} | ||
|
||
@Override | ||
public DataFetcher<ArrivalDepartureTime> departure() { | ||
return environment -> { | ||
var tripTime = getSource(environment); | ||
var scheduledTime = getZonedDateTime(environment, tripTime.getScheduledDeparture()); | ||
if (scheduledTime == null) { | ||
return null; | ||
} | ||
return tripTime.isRealtime() | ||
? ArrivalDepartureTime.of(scheduledTime, tripTime.getDepartureDelay()) | ||
: ArrivalDepartureTime.ofStatic(scheduledTime); | ||
}; | ||
} | ||
|
||
@Override | ||
public DataFetcher<String> dropoffType() { | ||
return environment -> PickDropMapper.map(getSource(environment).getDropoffType()); | ||
} | ||
|
||
@Override | ||
public DataFetcher<String> headsign() { | ||
return environment -> | ||
GraphQLUtils.getTranslation(getSource(environment).getHeadsign(), environment); | ||
} | ||
|
||
@Override | ||
public DataFetcher<String> pickupType() { | ||
return environment -> PickDropMapper.map(getSource(environment).getPickupType()); | ||
} | ||
|
||
@Override | ||
public DataFetcher<GraphQLTypes.GraphQLStopRealTimeState> realtimeState() { | ||
return environment -> { | ||
var tripTime = getSource(environment); | ||
// TODO support ADDED state | ||
if (tripTime.isCanceledEffectively()) { | ||
return GraphQLTypes.GraphQLStopRealTimeState.CANCELED; | ||
} | ||
if (tripTime.isNoDataStop()) { | ||
return GraphQLTypes.GraphQLStopRealTimeState.NO_DATA; | ||
} | ||
if (tripTime.isRecordedStop()) { | ||
return GraphQLTypes.GraphQLStopRealTimeState.RECORDED; | ||
} | ||
if (tripTime.isRealtime()) { | ||
return GraphQLTypes.GraphQLStopRealTimeState.UPDATED; | ||
} | ||
return GraphQLTypes.GraphQLStopRealTimeState.UNUPDATED; | ||
}; | ||
} | ||
|
||
@Override | ||
public DataFetcher<Integer> stopPosition() { | ||
return environment -> getSource(environment).getGtfsSequence(); | ||
} | ||
|
||
@Override | ||
public DataFetcher<Object> stop() { | ||
return environment -> getSource(environment).getStop(); | ||
} | ||
|
||
@Override | ||
public DataFetcher<Boolean> timepoint() { | ||
return environment -> getSource(environment).isTimepoint(); | ||
} | ||
|
||
private TransitService getTransitService(DataFetchingEnvironment environment) { | ||
return environment.<GraphQLRequestContext>getContext().transitService(); | ||
} | ||
|
||
private ZonedDateTime getZonedDateTime(DataFetchingEnvironment environment, int time) { | ||
var fixedTime = stopTimeToInt(time); | ||
if (fixedTime == null) { | ||
return null; | ||
} | ||
var serviceDate = getSource(environment).getServiceDay(); | ||
TransitService transitService = getTransitService(environment); | ||
return ServiceDateUtils.toZonedDateTime(serviceDate, transitService.getTimeZone(), fixedTime); | ||
} | ||
|
||
private TripTimeOnDate getSource(DataFetchingEnvironment environment) { | ||
return environment.getSource(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/opentripplanner/apis/gtfs/mapping/PickDropMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.opentripplanner.apis.gtfs.mapping; | ||
|
||
import javax.annotation.Nullable; | ||
import org.opentripplanner.model.PickDrop; | ||
|
||
public final class PickDropMapper { | ||
|
||
@Nullable | ||
public static String map(PickDrop pickDrop) { | ||
return switch (pickDrop) { | ||
case SCHEDULED -> "SCHEDULED"; | ||
case NONE -> "NONE"; | ||
case CALL_AGENCY -> "CALL_AGENCY"; | ||
case COORDINATE_WITH_DRIVER -> "COORDINATE_WITH_DRIVER"; | ||
case CANCELLED -> null; | ||
}; | ||
} | ||
} |
Oops, something went wrong.