Skip to content

Commit 7287f8d

Browse files
authored
Merge a5e4381 into 37ed5e7
2 parents 37ed5e7 + a5e4381 commit 7287f8d

File tree

6 files changed

+164
-1
lines changed

6 files changed

+164
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ app/pkg/bin/
104104
processor/notices/bin/
105105
processor/notices/tests/bin/
106106
web/service/bin/
107+
108+
RULES.md

main/src/main/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadata.java

+57-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public class FeedMetadata {
6060
new Pair<>("Zone-Based Fares", GtfsArea.FILENAME),
6161
new Pair<>("Transfer Fares", GtfsFareTransferRule.FILENAME),
6262
new Pair<>("Time-Based Fares", GtfsTimeframe.FILENAME),
63-
new Pair<>("Levels", GtfsLevel.FILENAME));
63+
new Pair<>("Levels", GtfsLevel.FILENAME),
64+
new Pair<>("Booking Rules", GtfsBookingRules.FILENAME),
65+
new Pair<>("Fixed-Stops Demand Responsive Transit", GtfsLocationGroups.FILENAME));
6466

6567
protected FeedMetadata() {}
6668

@@ -156,6 +158,60 @@ private void loadSpecFeaturesBasedOnFieldPresence(GtfsFeedContainer feedContaine
156158
loadPathwayExtraFeature(feedContainer);
157159
loadRouteBasedFaresFeature(feedContainer);
158160
loadContinuousStopsFeature(feedContainer);
161+
loadZoneBasedDemandResponsiveTransitFeature(feedContainer);
162+
loadDeviatedFixedRouteFeature(feedContainer);
163+
}
164+
165+
private void loadDeviatedFixedRouteFeature(GtfsFeedContainer feedContainer) {
166+
specFeatures.put("Deviated Fixed Route", hasAtLeastOneTripWithAllFields(feedContainer));
167+
}
168+
169+
private boolean hasAtLeastOneTripWithAllFields(GtfsFeedContainer feedContainer) {
170+
Optional<GtfsTableContainer<?>> optionalStopTimeTable =
171+
feedContainer.getTableForFilename(GtfsStopTime.FILENAME);
172+
if (optionalStopTimeTable.isPresent()) {
173+
for (GtfsEntity entity : optionalStopTimeTable.get().getEntities()) {
174+
if (entity instanceof GtfsStopTime) {
175+
GtfsStopTime stopTime = (GtfsStopTime) entity;
176+
return stopTime.hasTripId()
177+
&& stopTime.tripId() != null
178+
&& stopTime.hasLocationId()
179+
&& stopTime.locationId() != null
180+
&& stopTime.hasStopId()
181+
&& stopTime.stopId() != null
182+
&& stopTime.hasArrivalTime()
183+
&& stopTime.arrivalTime() != null
184+
&& stopTime.hasDepartureTime()
185+
&& stopTime.departureTime() != null;
186+
}
187+
}
188+
}
189+
return false;
190+
}
191+
192+
private void loadZoneBasedDemandResponsiveTransitFeature(GtfsFeedContainer feedContainer) {
193+
specFeatures.put(
194+
"Zone-Based Demand Responsive Transit", hasAtLeastOneTripWithOnlyLocationId(feedContainer));
195+
}
196+
197+
private boolean hasAtLeastOneTripWithOnlyLocationId(GtfsFeedContainer feedContainer) {
198+
Optional<GtfsTableContainer<?>> optionalStopTimeTable =
199+
feedContainer.getTableForFilename(GtfsStopTime.FILENAME);
200+
if (optionalStopTimeTable.isPresent()) {
201+
for (GtfsEntity entity : optionalStopTimeTable.get().getEntities()) {
202+
if (entity instanceof GtfsStopTime) {
203+
GtfsStopTime stopTime = (GtfsStopTime) entity;
204+
if (stopTime.hasTripId()
205+
&& stopTime.tripId() != null
206+
&& stopTime.hasLocationId()
207+
&& stopTime.locationId() != null
208+
&& (!stopTime.hasStopId() || stopTime.stopId() == null)) {
209+
return true;
210+
}
211+
}
212+
}
213+
}
214+
return false;
159215
}
160216

161217
private void loadContinuousStopsFeature(GtfsFeedContainer feedContainer) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.mobilitydata.gtfsvalidator.table;
2+
3+
import org.mobilitydata.gtfsvalidator.annotation.ConditionallyRequired;
4+
import org.mobilitydata.gtfsvalidator.annotation.FieldType;
5+
import org.mobilitydata.gtfsvalidator.annotation.FieldTypeEnum;
6+
import org.mobilitydata.gtfsvalidator.annotation.GtfsTable;
7+
import org.mobilitydata.gtfsvalidator.annotation.MixedCase;
8+
import org.mobilitydata.gtfsvalidator.annotation.PrimaryKey;
9+
import org.mobilitydata.gtfsvalidator.annotation.Required;
10+
import org.mobilitydata.gtfsvalidator.type.GtfsTime;
11+
12+
@GtfsTable("booking_rules.txt")
13+
public interface GtfsBookingRulesSchema extends GtfsEntity {
14+
@FieldType(FieldTypeEnum.ID)
15+
@PrimaryKey
16+
@Required
17+
String bookingRuleId();
18+
19+
@Required
20+
GtfsBookingType bookingType();
21+
22+
@ConditionallyRequired
23+
int priorNoticeDurationMin();
24+
25+
@ConditionallyRequired
26+
int priorNoticeDurationMax();
27+
28+
@ConditionallyRequired
29+
int priorNoticeStartDay();
30+
31+
@ConditionallyRequired
32+
GtfsTime priorNoticeStartTime();
33+
34+
@ConditionallyRequired
35+
int priorNoticeLastDay();
36+
37+
@ConditionallyRequired
38+
GtfsTime priorNoticeLastTime();
39+
40+
@ConditionallyRequired
41+
String priorNoticeServiceId();
42+
43+
@MixedCase
44+
String message();
45+
46+
@MixedCase
47+
String pickupMessage();
48+
49+
@MixedCase
50+
String dropOffMessage();
51+
52+
@FieldType(FieldTypeEnum.PHONE_NUMBER)
53+
String phoneNumber();
54+
55+
@FieldType(FieldTypeEnum.URL)
56+
String infoUrl();
57+
58+
@FieldType(FieldTypeEnum.URL)
59+
String bookingUrl();
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mobilitydata.gtfsvalidator.table;
17+
18+
import org.mobilitydata.gtfsvalidator.annotation.GtfsEnumValue;
19+
20+
@GtfsEnumValue(name = "REALTIME", value = 0)
21+
@GtfsEnumValue(name = "SAMEDAY", value = 1)
22+
@GtfsEnumValue(name = "PRIORDAY", value = 2)
23+
public interface GtfsBookingTypeEnum {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.mobilitydata.gtfsvalidator.table;
2+
3+
import org.mobilitydata.gtfsvalidator.annotation.FieldType;
4+
import org.mobilitydata.gtfsvalidator.annotation.FieldTypeEnum;
5+
import org.mobilitydata.gtfsvalidator.annotation.GtfsTable;
6+
import org.mobilitydata.gtfsvalidator.annotation.MixedCase;
7+
import org.mobilitydata.gtfsvalidator.annotation.PrimaryKey;
8+
import org.mobilitydata.gtfsvalidator.annotation.Required;
9+
10+
@GtfsTable("location_groups.txt")
11+
public interface GtfsLocationGroupsSchema extends GtfsEntity {
12+
@FieldType(FieldTypeEnum.ID)
13+
@PrimaryKey
14+
@Required
15+
String locationGroupId();
16+
17+
@MixedCase
18+
String locationGroupName();
19+
}

main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsStopTimeSchema.java

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public interface GtfsStopTimeSchema extends GtfsEntity {
5656
@ForeignKey(table = "stops.txt", field = "stop_id")
5757
String stopId();
5858

59+
@FieldType(FieldTypeEnum.ID)
60+
String locationId();
61+
5962
@PrimaryKey(isSequenceUsedForSorting = true, translationRecordIdType = RECORD_SUB_ID)
6063
@Required
6164
@NonNegative

0 commit comments

Comments
 (0)