Skip to content

Commit 27d49e9

Browse files
authored
Merge pull request #241 from conveyal/dev
New major release
2 parents eb69b9f + 629157d commit 27d49e9

20 files changed

+12
-1961
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: java
2-
2+
dist: trusty # jdk 8 not available on xenial
33
# This library uses Java 8 features and Travis doesn't (yet) support OpenJDK 8
44
jdk:
55
- oraclejdk8

src/main/java/com/conveyal/gtfs/FrequencySummary.java

-91
This file was deleted.

src/main/java/com/conveyal/gtfs/GTFSFeed.java

+9-138
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66
import com.conveyal.gtfs.model.*;
77
import com.conveyal.gtfs.model.Calendar;
88
import com.conveyal.gtfs.validator.Validator;
9-
import com.conveyal.gtfs.stats.FeedStats;
109
import com.conveyal.gtfs.validator.service.GeoUtils;
1110
import com.google.common.collect.*;
1211
import com.google.common.eventbus.EventBus;
1312
import com.google.common.util.concurrent.ExecutionError;
1413
import com.vividsolutions.jts.algorithm.ConvexHull;
1514
import com.vividsolutions.jts.geom.*;
1615
import com.vividsolutions.jts.index.strtree.STRtree;
17-
import com.vividsolutions.jts.simplify.DouglasPeuckerSimplifier;
1816
import org.geotools.referencing.GeodeticCalculator;
1917
import org.mapdb.BTreeMap;
20-
import org.mapdb.Bind;
2118
import org.mapdb.DB;
2219
import org.mapdb.DBMaker;
2320
import org.mapdb.Fun;
@@ -33,17 +30,12 @@
3330
import java.io.IOError;
3431
import java.io.IOException;
3532
import java.io.OutputStream;
36-
import java.time.LocalDate;
37-
import java.time.ZoneId;
3833
import java.time.format.DateTimeFormatter;
39-
import java.time.temporal.ChronoUnit;
4034
import java.util.*;
41-
import java.util.concurrent.ConcurrentMap;
4235
import java.util.concurrent.ConcurrentNavigableMap;
4336
import java.util.concurrent.ExecutionException;
4437
import java.util.concurrent.TimeUnit;
4538
import java.util.stream.Collectors;
46-
import java.util.stream.IntStream;
4739
import java.util.stream.StreamSupport;
4840
import java.util.zip.ZipEntry;
4941
import java.util.zip.ZipFile;
@@ -86,13 +78,14 @@ public class GTFSFeed implements Cloneable, Closeable {
8678

8779
// public final ConcurrentMap<String, Long> stopCountByStopTime;
8880

89-
/* Map from stop (stop_id) to stopTimes tuples (trip_id, stop_sequence) */
90-
public final NavigableSet<Tuple2<String, Tuple2>> stopStopTimeSet;
91-
public final ConcurrentMap<String, Long> stopCountByStopTime;
92-
93-
public final NavigableSet<Tuple2<String, String>> tripsPerService;
94-
95-
public final NavigableSet<Tuple2<String, String>> servicesPerDate;
81+
// TODO: Remove these indexes from GTFSFeed.
82+
// /* Map from stop (stop_id) to stopTimes tuples (trip_id, stop_sequence) */
83+
// public final NavigableSet<Tuple2<String, Tuple2>> stopStopTimeSet;
84+
// public final ConcurrentMap<String, Long> stopCountByStopTime;
85+
//
86+
// public final NavigableSet<Tuple2<String, String>> tripsPerService;
87+
//
88+
// public final NavigableSet<Tuple2<String, String>> servicesPerDate;
9689

9790
/* A fare is a fare_attribute and all fare_rules that reference that fare_attribute. */
9891
public final Map<String, Fare> fares;
@@ -196,29 +189,6 @@ else if (feedId == null || feedId.isEmpty()) {
196189
for (GTFSError error : errors) {
197190
LOG.info("{}", error);
198191
}
199-
LOG.info("Building stop to stop times index");
200-
Bind.histogram(stop_times, stopCountByStopTime, (key, stopTime) -> stopTime.stop_id);
201-
Bind.secondaryKeys(stop_times, stopStopTimeSet, (key, stopTime) -> new String[] {stopTime.stop_id});
202-
LOG.info("Building trips per service index");
203-
Bind.secondaryKeys(trips, tripsPerService, (key, trip) -> new String[] {trip.service_id});
204-
LOG.info("Building services per date index");
205-
Bind.secondaryKeys(services, servicesPerDate, (key, service) -> {
206-
207-
LocalDate startDate = service.calendar != null
208-
? service.calendar.start_date
209-
: service.calendar_dates.keySet().stream().sorted().findFirst().get();
210-
LocalDate endDate = service.calendar != null
211-
? service.calendar.end_date
212-
: service.calendar_dates.keySet().stream().sorted().reduce((first, second) -> second).get();
213-
// end date for Period.between is not inclusive
214-
int daysOfService = (int) ChronoUnit.DAYS.between(startDate, endDate.plus(1, ChronoUnit.DAYS));
215-
return IntStream.range(0, daysOfService)
216-
.mapToObj(offset -> startDate.plusDays(offset))
217-
.filter(service::activeOn)
218-
.map(date -> date.format(dateFormatter))
219-
.toArray(size -> new String[size]);
220-
});
221-
222192
loaded = true;
223193
}
224194

@@ -264,15 +234,7 @@ public void toFile (String file) {
264234
throw new RuntimeException(e);
265235
}
266236
}
267-
// public void validate (EventBus eventBus, Validator... validators) {
268-
// if (eventBus == null) {
269-
//
270-
// }
271-
// for (Validator validator : validators) {
272-
// validator.getClass().getSimpleName();
273-
// validator.validate(this, false);
274-
// }
275-
// }
237+
276238
public void validate (boolean repair, Validator... validators) {
277239
long startValidation = System.currentTimeMillis();
278240
for (Validator validator : validators) {
@@ -298,11 +260,6 @@ public void validate () {
298260
/////////////////
299261
}
300262

301-
public FeedStats calculateStats() {
302-
FeedStats feedStats = new FeedStats(this);
303-
return feedStats;
304-
}
305-
306263
/**
307264
* Static factory method returning a new instance of GTFSFeed containing the contents of
308265
* the GTFS file at the supplied filesystem path.
@@ -604,87 +561,6 @@ public double getTripSpeed (String trip_id, boolean straightLine) {
604561
return distance / time; // meters per second
605562
}
606563

607-
/** Get list of stop_times for a given stop_id. */
608-
public List<StopTime> getStopTimesForStop (String stop_id) {
609-
SortedSet<Tuple2<String, Tuple2>> index = this.stopStopTimeSet
610-
.subSet(new Tuple2<>(stop_id, null), new Tuple2(stop_id, Fun.HI));
611-
612-
return index.stream()
613-
.map(tuple -> this.stop_times.get(tuple.b))
614-
.collect(Collectors.toList());
615-
}
616-
617-
public List<Trip> getTripsForService (String service_id) {
618-
SortedSet<Tuple2<String, String>> index = this.tripsPerService
619-
.subSet(new Tuple2<>(service_id, null), new Tuple2(service_id, Fun.HI));
620-
621-
return index.stream()
622-
.map(tuple -> this.trips.get(tuple.b))
623-
.collect(Collectors.toList());
624-
}
625-
626-
/** Get list of services for each date of service. */
627-
public List<Service> getServicesForDate (LocalDate date) {
628-
String dateString = date.format(dateFormatter);
629-
SortedSet<Tuple2<String, String>> index = this.servicesPerDate
630-
.subSet(new Tuple2<>(dateString, null), new Tuple2(dateString, Fun.HI));
631-
632-
return index.stream()
633-
.map(tuple -> this.services.get(tuple.b))
634-
.collect(Collectors.toList());
635-
}
636-
637-
public List<LocalDate> getDatesOfService () {
638-
return this.servicesPerDate.stream()
639-
.map(tuple -> LocalDate.parse(tuple.a, dateFormatter))
640-
.collect(Collectors.toList());
641-
}
642-
643-
/** Get list of distinct trips (filters out multiple visits by a trip) a given stop_id. */
644-
public List<Trip> getDistinctTripsForStop (String stop_id) {
645-
return getStopTimesForStop(stop_id).stream()
646-
.map(stopTime -> this.trips.get(stopTime.trip_id))
647-
.distinct()
648-
.collect(Collectors.toList());
649-
}
650-
651-
/** Get the likely time zone for a stop using the agency of the first stop time encountered for the stop. */
652-
public ZoneId getAgencyTimeZoneForStop (String stop_id) {
653-
StopTime stopTime = getStopTimesForStop(stop_id).iterator().next();
654-
655-
Trip trip = this.trips.get(stopTime.trip_id);
656-
Route route = this.routes.get(trip.route_id);
657-
Agency agency = route.agency_id != null ? this.agency.get(route.agency_id) : this.agency.get(0);
658-
659-
return ZoneId.of(agency.agency_timezone);
660-
}
661-
662-
// TODO: code review
663-
public Geometry getMergedBuffers() {
664-
if (this.mergedBuffers == null) {
665-
// synchronized (this) {
666-
Collection<Geometry> polygons = new ArrayList<>();
667-
for (Stop stop : this.stops.values()) {
668-
if (getStopTimesForStop(stop.stop_id).isEmpty()) {
669-
continue;
670-
}
671-
if (stop.stop_lat > -1 && stop.stop_lat < 1 || stop.stop_lon > -1 && stop.stop_lon < 1) {
672-
continue;
673-
}
674-
Point stopPoint = gf.createPoint(new Coordinate(stop.stop_lon, stop.stop_lat));
675-
Polygon stopBuffer = (Polygon) stopPoint.buffer(.01);
676-
polygons.add(stopBuffer);
677-
}
678-
Geometry multiGeometry = gf.buildGeometry(polygons);
679-
this.mergedBuffers = multiGeometry.union();
680-
if (polygons.size() > 100) {
681-
this.mergedBuffers = DouglasPeuckerSimplifier.simplify(this.mergedBuffers, .001);
682-
}
683-
// }
684-
}
685-
return this.mergedBuffers;
686-
}
687-
688564
public Polygon getConvexHull() {
689565
if (this.convexHull == null) {
690566
synchronized (this) {
@@ -788,11 +664,6 @@ private GTFSFeed (DB db) {
788664

789665
tripPatternMap = db.getTreeMap("patternForTrip");
790666

791-
stopCountByStopTime = db.getTreeMap("stopCountByStopTime");
792-
stopStopTimeSet = db.getTreeSet("stopStopTimeSet");
793-
tripsPerService = db.getTreeSet("tripsPerService");
794-
servicesPerDate = db.getTreeSet("servicesPerDate");
795-
796667
errors = db.getTreeSet("errors");
797668
}
798669
}

src/main/java/com/conveyal/gtfs/GTFSMain.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.conveyal.gtfs;
22

3-
import com.conveyal.gtfs.stats.FeedStats;
43
import com.conveyal.gtfs.util.json.JsonManager;
54
import com.conveyal.gtfs.validator.model.ValidationResult;
65
import org.apache.commons.cli.CommandLine;
@@ -41,7 +40,7 @@ public static void main (String[] args) throws Exception {
4140
if(cmd.hasOption("validate")) {
4241
feed.validate();
4342
JsonManager<ValidationResult> json = new JsonManager(ValidationResult.class);
44-
ValidationResult result = new ValidationResult(arguments[0], feed, new FeedStats(feed));
43+
ValidationResult result = new ValidationResult(arguments[0], feed);
4544
String resultString = json.writePretty(result);
4645
File resultFile;
4746
if (arguments.length >= 2) {

0 commit comments

Comments
 (0)