forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetexModule.java
125 lines (104 loc) · 4.67 KB
/
NetexModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package org.opentripplanner.netex;
import java.util.List;
import org.opentripplanner.ext.flex.FlexTripsMapper;
import org.opentripplanner.framework.application.OTPFeature;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.graph_builder.model.GraphBuilderModule;
import org.opentripplanner.graph_builder.module.AddTransitModelEntitiesToGraph;
import org.opentripplanner.graph_builder.module.ValidateAndInterpolateStopTimesForEachTrip;
import org.opentripplanner.model.OtpTransitService;
import org.opentripplanner.model.TripStopTimes;
import org.opentripplanner.model.calendar.CalendarServiceData;
import org.opentripplanner.model.calendar.ServiceDateInterval;
import org.opentripplanner.model.impl.OtpTransitServiceBuilder;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingHelper;
import org.opentripplanner.standalone.config.BuildConfig;
import org.opentripplanner.transit.service.TransitModel;
/**
* This module is used for importing the NeTEx CEN Technical Standard for exchanging Public
* Transport schedules and related data (<a href="http://netex-cen.eu/">http://netex-cen.eu/</a>).
* Currently it only supports the Norwegian profile (<a href="https://enturas.atlassian.net/wiki/spaces/PUBLIC/">https://enturas.atlassian.net/wiki/spaces/PUBLIC/</a>),
* but it is intended to be updated later to support other profiles.
*/
public class NetexModule implements GraphBuilderModule {
private final int subwayAccessTime;
private final Graph graph;
private final TransitModel transitModel;
private final DataImportIssueStore issueStore;
/**
* @see BuildConfig#transitServiceStart
* @see BuildConfig#transitServiceEnd
*/
private final ServiceDateInterval transitPeriodLimit;
private final List<NetexBundle> netexBundles;
public NetexModule(
Graph graph,
TransitModel transitModel,
DataImportIssueStore issueStore,
int subwayAccessTime,
ServiceDateInterval transitPeriodLimit,
List<NetexBundle> netexBundles
) {
this.graph = graph;
this.transitModel = transitModel;
this.issueStore = issueStore;
this.subwayAccessTime = subwayAccessTime;
this.transitPeriodLimit = transitPeriodLimit;
this.netexBundles = netexBundles;
}
@Override
public void buildGraph() {
try {
var calendarServiceData = new CalendarServiceData();
boolean hasActiveTransit = false;
for (NetexBundle netexBundle : netexBundles) {
netexBundle.checkInputs();
OtpTransitServiceBuilder transitBuilder = netexBundle.loadBundle(
graph.deduplicator,
issueStore
);
transitBuilder.limitServiceDays(transitPeriodLimit);
for (var tripOnServiceDate : transitBuilder.getTripOnServiceDates().values()) {
transitModel.addTripOnServiceDate(tripOnServiceDate);
}
calendarServiceData.add(transitBuilder.buildCalendarServiceData());
if (OTPFeature.FlexRouting.isOn()) {
transitBuilder
.getFlexTripsById()
.addAll(FlexTripsMapper.createFlexTrips(transitBuilder, issueStore));
}
validateStopTimesForEachTrip(transitBuilder.getStopTimesSortedByTrip());
OtpTransitService otpService = transitBuilder.build();
// if this or previously processed netex bundle has transit that has not been filtered out
hasActiveTransit = hasActiveTransit || otpService.hasActiveTransit();
// TODO OTP2 - Move this into the AddTransitModelEntitiesToGraph
// - and make sure they also work with GTFS feeds - GTFS do no
// - have operators and notice assignments.
transitModel.addOperators(otpService.getAllOperators());
transitModel.addNoticeAssignments(otpService.getNoticeAssignments());
AddTransitModelEntitiesToGraph.addToGraph(
otpService,
subwayAccessTime,
graph,
transitModel
);
transitModel.validateTimeZones();
var lots = transitBuilder.vehicleParkings();
graph.getVehicleParkingService().updateVehicleParking(lots, List.of());
var linker = new VehicleParkingHelper(graph);
lots.forEach(linker::linkVehicleParkingToGraph);
}
transitModel.updateCalendarServiceData(hasActiveTransit, calendarServiceData, issueStore);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void validateStopTimesForEachTrip(TripStopTimes stopTimesByTrip) {
new ValidateAndInterpolateStopTimesForEachTrip(stopTimesByTrip, false, false, issueStore).run();
}
@Override
public void checkInputs() {
netexBundles.forEach(NetexBundle::checkInputs);
}
}