Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTA GTFS Strategies #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public FareRule getFareRuleForId(int id) {
}

@Override
public FeedInfo getFeedInfoForId(int id) {
public FeedInfo getFeedInfoForId(String id) {
return (FeedInfo) _ops.get(FeedInfo.class, id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@
</class>

<class name="org.onebusaway.gtfs.model.FeedInfo" table="gtfs_feed_info">
<id name="id" column="gid" type="int" length="11" unsaved-value="null">
<generator class="native" />
</id>
<id name="id" column="gid" type="string" length="50">
</id>
<property name="publisherName" />
<property name="publisherUrl" />
<property name="lang" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void testFeedInfo() throws CsvEntityIOException, IOException {

_reader.readEntities(FeedInfo.class, new StringReader(b.toString()));

FeedInfo feedInfo = _dao.getFeedInfoForId(1);
FeedInfo feedInfo = _dao.getFeedInfoForId("1");
assertEquals("Test", feedInfo.getPublisherName());
assertEquals("http://test/", feedInfo.getPublisherUrl());
assertEquals("en", feedInfo.getLang());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (C) 2018 Cambridge Systematics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.gtfs_transformer.csv;

import org.onebusaway.csv_entities.CsvEntityReader;
import org.onebusaway.csv_entities.EntityHandler;

import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class CSVUtil {

public static <T> List<T> readCsv(final Class<T> klass, String csv) {
CsvEntityReader reader = new CsvEntityReader();
final List<T> ret = new ArrayList<>();
reader.addEntityHandler(new EntityHandler() {
@Override
public void handleEntity(Object o) {
ret.add(klass.cast(o));
}
});
try {
reader.readEntities(klass, new FileReader(csv));
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright (C) 2018 Cambridge Systematics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.gtfs_transformer.csv;

import org.onebusaway.csv_entities.schema.annotations.CsvField;
import org.onebusaway.csv_entities.schema.annotations.CsvFields;

@CsvFields(filename = "elevators.txt")
public class MTAElevator {
// Equip ID Equip Loc Stop Desc Stop ID Direction Track Line

@CsvField(name = "Equip ID")
private String id;

@CsvField(name = "Equip Loc")
private String loc;

@CsvField(name = "Stop Desc")
private String desc;

@CsvField(name = "Stop ID")
private String stopId;

@CsvField(name = "Direction")
private String direction;

@CsvField(name = "Track", optional = true)
private String track;

@CsvField(name = "Line", optional = true)
private String line;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getLoc() {
return loc;
}

public void setLoc(String loc) {
this.loc = loc;
}

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}

public String getStopId() {
return stopId;
}

public void setStopId(String stopId) {
this.stopId = stopId;
}

public String getDirection() {
return direction;
}

public void setDirection(String direction) {
this.direction = direction;
}

public String getTrack() {
return track;
}

public void setTrack(String track) {
this.track = track;
}

public String getLine() {
return line;
}

public void setLine(String line) {
this.line = line;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright (C) 2018 Cambridge Systematics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.gtfs_transformer.csv;

import org.onebusaway.csv_entities.schema.annotations.CsvField;
import org.onebusaway.csv_entities.schema.annotations.CsvFields;

@CsvFields(filename = "entrances.txt")
public class MTAEntrance {
// station_key,MRN,entrance_type,latitude,longitude

private String stationKey;

@CsvField(name = "MRN")
private String MRN;

private String entranceType;

// a couple have missing lat/lons

@CsvField(optional = true)
private Double latitude;

@CsvField(optional = true)
private Double longitude;

private String stopId;

public String getStationKey() {
return stationKey;
}

public void setStationKey(String stationKey) {
this.stationKey = stationKey;
}

public String getMRN() {
return MRN;
}

public void setMRN(String MRN) {
this.MRN = MRN;
}

public String getEntranceType() {
return entranceType;
}

public void setEntranceType(String entranceType) {
this.entranceType = entranceType;
}

public Double getLatitude() {
return latitude;
}

public void setLatitude(Double latitude) {
this.latitude = latitude;
}

public Double getLongitude() {
return longitude;
}

public void setLongitude(Double longitude) {
this.longitude = longitude;
}

public String getStopId() {
return stopId;
}

public void setStopId(String stopId) {
this.stopId = stopId;
}

public boolean hasLocation() {
return latitude != null && longitude != null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Copyright (C) 2018 Cambridge Systematics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.gtfs_transformer.csv;

import org.onebusaway.csv_entities.schema.annotations.CsvField;
import org.onebusaway.csv_entities.schema.annotations.CsvFields;

@CsvFields(filename = "directions.txt")
public class MTAStationDirection {

// Station ID,GTFS Stop ID,Line,Stop Name,Daytime Routes,Railroad north descriptor,Railroad south descriptor,Notes

@CsvField(name = "Station ID")
private String stationId;

@CsvField(name = "GTFS Stop ID")
private String gtfsStopId;

@CsvField(name = "Line")
private String line;

@CsvField(name = "Stop Name")
private String stopName;

@CsvField(name = "Daytime Routes")
private String daytimeRoutes;

@CsvField(name = "Railroad north descriptor")
private String northDesc;

@CsvField(name = "Railroad south descriptor")
private String southDesc;

@CsvField(name = "Notes", optional = true)
private String notes;

public String getStationId() {
return stationId;
}

public void setStationId(String stationId) {
this.stationId = stationId;
}

public String getGtfsStopId() {
return gtfsStopId;
}

public void setGtfsStopId(String gtfsStopId) {
this.gtfsStopId = gtfsStopId;
}

public String getLine() {
return line;
}

public void setLine(String line) {
this.line = line;
}

public String getStopName() {
return stopName;
}

public void setStopName(String stopName) {
this.stopName = stopName;
}

public String getDaytimeRoutes() {
return daytimeRoutes;
}

public void setDaytimeRoutes(String daytimeRoutes) {
this.daytimeRoutes = daytimeRoutes;
}

public String getNorthDesc() {
return northDesc;
}

public void setNorthDesc(String northDesc) {
this.northDesc = northDesc;
}

public String getSouthDesc() {
return southDesc;
}

public void setSouthDesc(String southDesc) {
this.southDesc = southDesc;
}

public String getNotes() {
return notes;
}

public void setNotes(String notes) {
this.notes = notes;
}
}
Loading