Skip to content

Commit

Permalink
Move stuff around in GTFS
Browse files Browse the repository at this point in the history
  • Loading branch information
michaz committed Jan 20, 2020
1 parent 0af725f commit c3dad34
Show file tree
Hide file tree
Showing 17 changed files with 11 additions and 523 deletions.
31 changes: 0 additions & 31 deletions reader-gtfs/src/main/java/com/conveyal/gtfs/model/Agency.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import java.io.IOException;
import java.net.URL;
import java.util.Iterator;

public class Agency extends Entity {

Expand Down Expand Up @@ -79,34 +78,4 @@ public void loadOneRow() throws IOException {

}

public static class Writer extends Entity.Writer<Agency> {
public Writer(GTFSFeed feed) {
super(feed, "agency");
}

@Override
public void writeHeaders() throws IOException {
writer.writeRecord(new String[] {"agency_id", "agency_name", "agency_url", "agency_lang",
"agency_phone", "agency_timezone", "agency_fare_url", "agency_branding_url"});
}

@Override
public void writeOneRow(Agency a) throws IOException {
writeStringField(a.agency_id);
writeStringField(a.agency_name);
writeUrlField(a.agency_url);
writeStringField(a.agency_lang);
writeStringField(a.agency_phone);
writeStringField(a.agency_timezone);
writeUrlField(a.agency_fare_url);
writeUrlField(a.agency_branding_url);
endRecord();
}

@Override
public Iterator<Agency> iterator() {
return this.feed.agency.values().iterator();
}
}

}
50 changes: 0 additions & 50 deletions reader-gtfs/src/main/java/com/conveyal/gtfs/model/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@

import com.conveyal.gtfs.GTFSFeed;
import com.conveyal.gtfs.error.DuplicateKeyError;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;

import java.io.IOException;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;

public class Calendar extends Entity implements Serializable {
Expand Down Expand Up @@ -100,50 +96,4 @@ public void loadOneRow() throws IOException {
}
}

public static class Writer extends Entity.Writer<Calendar> {
public Writer(GTFSFeed feed) {
super(feed, "calendar");
}

@Override
protected void writeHeaders() throws IOException {
writer.writeRecord(new String[] {"service_id", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "start_date", "end_date"});
}

@Override
protected void writeOneRow(Calendar c) throws IOException {
writeStringField(c.service_id);
writeIntField(c.monday);
writeIntField(c.tuesday);
writeIntField(c.wednesday);
writeIntField(c.thursday);
writeIntField(c.friday);
writeIntField(c.saturday);
writeIntField(c.sunday);
writeIntField(c.start_date);
writeIntField(c.end_date);
endRecord();
}

@Override
protected Iterator<Calendar> iterator() {
// wrap an iterator over services
Iterator<Calendar> calIt = Iterators.transform(feed.services.values().iterator(), new Function<Service, Calendar> () {
@Override
public Calendar apply (Service s) {
return s.calendar;
}
});

// not every service has a calendar (e.g. TriMet has no calendars, just calendar dates).
// This is legal GTFS, so skip services with no calendar
return Iterators.filter(calIt, new Predicate<Calendar> () {
@Override
public boolean apply(Calendar c) {
return c != null;
}
});

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@

import com.conveyal.gtfs.GTFSFeed;
import com.conveyal.gtfs.error.DuplicateKeyError;
import com.google.common.base.Function;
import com.google.common.collect.Iterators;

import java.io.IOException;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Iterator;
import java.util.Map;

public class CalendarDate extends Entity implements Cloneable, Serializable {
Expand Down Expand Up @@ -90,33 +87,4 @@ public void loadOneRow() throws IOException {
}
}

public static class Writer extends Entity.Writer<CalendarDate> {
public Writer (GTFSFeed feed) {
super(feed, "calendar_dates");
}

@Override
protected void writeHeaders() throws IOException {
writer.writeRecord(new String[] {"service_id", "date", "exception_type"});
}

@Override
protected void writeOneRow(CalendarDate d) throws IOException {
writeStringField(d.service_id);
writeDateField(d.date);
writeIntField(d.exception_type);
endRecord();
}

@Override
protected Iterator<CalendarDate> iterator() {
Iterator<Service> serviceIterator = feed.services.values().iterator();
return Iterators.concat(Iterators.transform(serviceIterator, new Function<Service, Iterator<CalendarDate>> () {
@Override
public Iterator<CalendarDate> apply(Service service) {
return service.calendar_dates.values().iterator();
}
}));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.conveyal.gtfs.error.DuplicateKeyError;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

public class FareAttribute extends Entity {
Expand Down Expand Up @@ -72,8 +71,8 @@ public void loadOneRow() throws IOException {
fa.price = getDoubleField("price", true, 0, Integer.MAX_VALUE);
fa.currency_type = getStringField("currency_type", true);
fa.payment_method = getIntField("payment_method", true, 0, 1);
fa.transfers = getIntField("transfers", false, 0, 10); // TODO missing means "unlimited" in this case (rather than 0), supply default value or just use the NULL to mean unlimited
fa.transfer_duration = getIntField("transfer_duration", false, 0, 24 * 60 * 60);
fa.transfers = getIntField("transfers", false, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
fa.transfer_duration = getIntField("transfer_duration", false, 0, 24*60*60, 24*60*60);
fa.feed = feed;
fa.feed_id = feed.feedId;
fare.fare_attribute = fa;
Expand All @@ -83,34 +82,4 @@ public void loadOneRow() throws IOException {

}

public static class Writer extends Entity.Writer<FareAttribute> {
public Writer(GTFSFeed feed) {
super(feed, "fare_attributes");
}

@Override
public void writeHeaders() throws IOException {
writer.writeRecord(new String[] {"fare_id", "price", "currency_type", "payment_method",
"transfers", "transfer_duration"});
}

@Override
public void writeOneRow(FareAttribute fa) throws IOException {
writeStringField(fa.fare_id);
writeDoubleField(fa.price);
writeStringField(fa.currency_type);
writeIntField(fa.payment_method);
writeIntField(fa.transfers);
writeIntField(fa.transfer_duration);
endRecord();
}

@Override
public Iterator<FareAttribute> iterator() {
return feed.fares.values().stream()
.map(f -> f.fare_attribute)
.iterator();
}
}

}
31 changes: 0 additions & 31 deletions reader-gtfs/src/main/java/com/conveyal/gtfs/model/FareRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.conveyal.gtfs.error.ReferentialIntegrityError;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

public class FareRule extends Entity {
Expand Down Expand Up @@ -82,34 +81,4 @@ public void loadOneRow() throws IOException {

}

public static class Writer extends Entity.Writer<FareRule> {
public Writer(GTFSFeed feed) {
super(feed, "fare_rules");
}

@Override
public void writeHeaders() throws IOException {
writer.writeRecord(new String[] {"fare_id", "route_id", "origin_id", "destination_id",
"contains_id"});
}

@Override
public void writeOneRow(FareRule fr) throws IOException {
writeStringField(fr.fare_id);
writeStringField(fr.route_id);
writeStringField(fr.origin_id);
writeStringField(fr.destination_id);
writeStringField(fr.contains_id);
endRecord();
}

@Override
public Iterator<FareRule> iterator() {
return feed.fares.values().stream()
.map(f -> f.fare_rules)
.flatMap(fr -> fr.stream())
.iterator();
}
}

}
35 changes: 0 additions & 35 deletions reader-gtfs/src/main/java/com/conveyal/gtfs/model/FeedInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.util.Iterator;

public class FeedInfo extends Entity implements Cloneable {

Expand Down Expand Up @@ -85,38 +84,4 @@ public void loadOneRow() throws IOException {
}
}

public static class Writer extends Entity.Writer<FeedInfo> {

public Writer(GTFSFeed feed) {
super(feed, "feed_info");
}

@Override
public void writeHeaders() throws IOException {
writer.writeRecord(new String[] {"feed_id", "feed_publisher_name", "feed_publisher_url", "feed_lang",
"feed_start_date", "feed_end_date", "feed_version"});
}

@Override
public void writeOneRow(FeedInfo i) throws IOException {
writeStringField(i.feed_id != null && i.feed_id.equals("NONE") ? "" : i.feed_id);
writeStringField(i.feed_publisher_name);
writeUrlField(i.feed_publisher_url);
writeStringField(i.feed_lang);

if (i.feed_start_date != null) writeDateField(i.feed_start_date);
else writeStringField("");

if (i.feed_end_date != null) writeDateField(i.feed_end_date);
else writeStringField("");

writeStringField(i.feed_version);
endRecord();
}

@Override
public Iterator<FeedInfo> iterator() {
return feed.feedInfo.values().iterator();
}
}
}
31 changes: 0 additions & 31 deletions reader-gtfs/src/main/java/com/conveyal/gtfs/model/Frequency.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.mapdb.Fun;

import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;

import static com.conveyal.gtfs.model.Entity.Writer.convertToGtfsTime;
Expand Down Expand Up @@ -95,34 +94,4 @@ public void loadOneRow() throws IOException {
}
}

public static class Writer extends Entity.Writer<Frequency> {
public Writer (GTFSFeed feed) {
super(feed, "frequencies");
}

@Override
public void writeHeaders() throws IOException {
writer.writeRecord(new String[] {"trip_id", "start_time", "end_time", "headway_secs", "exact_times"});
}

@Override
public void writeOneRow(Frequency f) throws IOException {
writeStringField(f.trip_id);
writeTimeField(f.start_time);
writeTimeField(f.end_time);
writeIntField(f.headway_secs);
writeIntField(f.exact_times);
endRecord();
}

@Override
public Iterator<Frequency> iterator() {
return feed.frequencies.stream()
.map(t2 -> t2.b)
.iterator();
}


}

}
Loading

0 comments on commit c3dad34

Please sign in to comment.