Skip to content

Commit

Permalink
Merge pull request #2 from by-implication/headsign-timetable
Browse files Browse the repository at this point in the history
Generate headsigns, update data
  • Loading branch information
ahelpingchip authored Jul 30, 2018
2 parents b19059f + 9a3c55f commit 2ccd20d
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 99 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Philippine National Railways GTFS data

This project generates a [GTFS][1] feed for the [PNR][2]. This is current as of
July 1, 2017.
July 30, 2018.

## Sources

* route description - [Wikipedia][3]
* timetable - PNR [northbound][4] and [southbound][5]
* timetable - PNR [northbound][4] and [southbound][5] (last updated July 2018, data as of Aug 2017)
* ![northbound](images/nb081517.jpg)
* ![southbound](images/sb081517.jpg)
* fares - [PNR][6]
* stops - [OpenStreetMap][7]
* shapes - [OpenStreetMap][7]

[1]: http://gtfs.org
[2]: http://pnr.gov.ph
[3]: https://en.wikipedia.org/wiki/PNR_Metro_South_Commuter_Line
[4]: http://pnr.gov.ph/images/Timetable/nb2017.jpg
[5]: http://pnr.gov.ph/images/Timetable/sb2017.jpg
[4]: http://www.pnr.gov.ph/images/Timetable/nb081517.jpg
[5]: http://www.pnr.gov.ph/images/Timetable/sb081517.jpg
[6]: http://pnr.gov.ph/images/banners/fare_increase_aircon.jpg
[7]: https://www.openstreetmap.org/relation/660480
15 changes: 13 additions & 2 deletions build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$trips = CSV.open("gtfs/trips.txt", "wb")
$stop_times = CSV.open("gtfs/stop_times.txt", "wb")

$trips << ["trip_id", "route_id", "service_id", "shape_id"]
$trips << ["trip_id", "route_id", "service_id", "shape_id", "trip_headsign"]
$stop_times << ["trip_id", "stop_sequence", "stop_id", "arrival_time", "departure_time"]

def parse_timetable(timetable, dir)
Expand All @@ -53,16 +53,27 @@ def parse_timetable(timetable, dir)

def parse_trip(timetable, i, dir)
trip_id = timetable[0][i]
$trips << [trip_id, $route_id, $service_id, dir]
last_stop_name = nil
timetable
.drop(2)
.reject { |r| r[i] == nil }
.each.with_index do |r, index|
stop_id = r[1]
arrival_time = r[i]
departure_time = r[i+1]
last_stop_name = r[0]
$stop_times << [trip_id, index+1, stop_id, arrival_time, departure_time]
end
dir_expanded = case dir
when 'NB'
'Northbound'
when 'SB'
'Southbound'
else
''
end
headsign = $route_id+' to '+last_stop_name+' ('+dir_expanded+')'
$trips << [trip_id, $route_id, $service_id, dir, headsign]
end

parse_timetable(timetable_nb, 'NB')
Expand Down
102 changes: 68 additions & 34 deletions gtfs/stop_times.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,40 @@ MSC 1300,14,SPÑ,13:59:00,14:00:00
MSC 1300,15,LLN,14:02:00,14:03:00
MSC 1300,16,BLU,14:06:00,14:07:00
MSC 1300,17,TU,14:12:00,14:12:00
MSC 1430,1,AA,14:30:00,14:30:00
MSC 1430,2,SU,14:36:00,14:37:00
MSC 1430,3,BIC,14:45:00,14:46:00
MSC 1430,4,FTI,14:50:00,14:51:00
MSC 1430,5,NIC,14:54:00,14:55:00
MSC 1430,6,EDS,15:01:00,15:02:00
MSC 1430,7,PRD,15:04:00,15:05:00
MSC 1430,8,DIA,15:07:00,15:08:00
MSC 1430,9,VTC,15:11:00,15:12:00
MSC 1430,10,SAN,15:13:00,15:14:00
MSC 1430,11,PC,15:16:00,15:17:00
MSC 1430,12,PD,15:20:00,15:21:00
MSC 1430,13,SA,15:24:00,15:25:00
MSC 1430,14,SPÑ,15:29:00,15:30:00
MSC 1430,15,LLN,15:32:00,15:33:00
MSC 1430,16,BLU,15:36:00,15:37:00
MSC 1430,17,TU,15:42:00,15:42:00
MSC 1400,1,AA,14:00:00 ,14:00:00
MSC 1400,2,SU,14:06:00 ,14:07:00
MSC 1400,3,BIC,14:15:00 ,14:16:00
MSC 1400,4,FTI,14:20:00 ,14:21:00
MSC 1400,5,NIC,14:24:00 ,14:25:00
MSC 1400,6,EDS,14:31:00 ,14:32:00
MSC 1400,7,PRD,14:34:00 ,14:35:00
MSC 1400,8,DIA,14:37:00 ,14:38:00
MSC 1400,9,VTC,14:41:00 ,14:42:00
MSC 1400,10,SAN,14:43:00 ,14:44:00
MSC 1400,11,PC,14:46:00 ,14:47:00
MSC 1400,12,PD,14:50:00 ,14:51:00
MSC 1400,13,SA,14:54:00 ,14:55:00
MSC 1400,14,SPÑ,14:59:00 ,15:00:00
MSC 1400,15,LLN,15:02:00 ,15:03:00
MSC 1400,16,BLU,15:06:00 ,15:07:00
MSC 1400,17,TU,15:12:00 ,15:12:00
MSC 1500,1,AA,15:00:00 ,15:00:00
MSC 1500,2,SU,15:06:00 ,15:07:00
MSC 1500,3,BIC,15:15:00 ,15:16:00
MSC 1500,4,FTI,15:20:00 ,15:21:00
MSC 1500,5,NIC,15:24:00 ,15:25:00
MSC 1500,6,EDS,15:31:00 ,15:32:00
MSC 1500,7,PRD,15:34:00 ,15:35:00
MSC 1500,8,DIA,15:37:00 ,15:38:00
MSC 1500,9,VTC,15:41:00 ,15:42:00
MSC 1500,10,SAN,15:43:00 ,15:44:00
MSC 1500,11,PC,15:46:00 ,15:47:00
MSC 1500,12,PD,15:50:00 ,15:51:00
MSC 1500,13,SA,15:54:00 ,15:55:00
MSC 1500,14,SPÑ,15:59:00 ,16:00:00
MSC 1500,15,LLN,16:02:00 ,16:03:00
MSC 1500,16,BLU,16:06:00 ,16:07:00
MSC 1500,17,TU,16:12:00 ,16:12:00
MSC 1600,1,AA,16:00:00,16:00:00
MSC 1600,2,SU,16:06:00,16:07:00
MSC 1600,3,BIC,16:15:00,16:16:00
Expand Down Expand Up @@ -509,23 +526,40 @@ MSC 1137,14,FTI,12:28:00,12:29:00
MSC 1137,15,BIC,12:33:00,12:34:00
MSC 1137,16,SU,12:42:00,12:43:00
MSC 1137,17,AA,12:49:00,12:49:00
MSC 1307,1,TU,13:07:00,13:07:00
MSC 1307,2,BLU,13:12:00,13:13:00
MSC 1307,3,LLN,13:16:00,13:17:00
MSC 1307,4,SPÑ,13:19:00,13:20:00
MSC 1307,5,SA,13:24:00,13:25:00
MSC 1307,6,PD,13:28:00,13:29:00
MSC 1307,7,PC,13:32:00,13:33:00
MSC 1307,8,SAN,13:35:00,13:36:00
MSC 1307,9,VTC,13:37:00,13:38:00
MSC 1307,10,DIA,13:41:00,13:42:00
MSC 1307,11,PRD,13:44:00,13:45:00
MSC 1307,12,EDS,13:47:00,13:48:00
MSC 1307,13,NIC,13:54:00,13:55:00
MSC 1307,14,FTI,13:58:00,13:59:00
MSC 1307,15,BIC,14:03:00,14:04:00
MSC 1307,16,SU,14:12:00,14:13:00
MSC 1307,17,AA,14:19:00,14:19:00
MSC 1237,1,TU,12:37:00 ,12:37:00
MSC 1237,2,BLU,12:42:00 ,12:43:00
MSC 1237,3,LLN,12:46:00 ,12:47:00
MSC 1237,4,SPÑ,12:49:00 ,12:50:00
MSC 1237,5,SA,12:54:00 ,12:55:00
MSC 1237,6,PD,12:58:00 ,12:59:00
MSC 1237,7,PC,13:02:00 ,13:03:00
MSC 1237,8,SAN,13:05:00 ,13:06:00
MSC 1237,9,VTC,13:07:00 ,13:08:00
MSC 1237,10,DIA,13:11:00 ,13:12:00
MSC 1237,11,PRD,13:14:00 ,13:15:00
MSC 1237,12,EDS,13:17:00 ,13:18:00
MSC 1237,13,NIC,13:24:00 ,13:25:00
MSC 1237,14,FTI,13:28:00 ,13:29:00
MSC 1237,15,BIC,13:33:00 ,13:34:00
MSC 1237,16,SU,13:42:00 ,13:43:00
MSC 1237,17,AA,13:49:00 ,13:49:00
MSC 1337,1,TU,13:37:00 ,13:37:00
MSC 1337,2,BLU,13:42:00 ,13:43:00
MSC 1337,3,LLN,13:46:00 ,13:47:00
MSC 1337,4,SPÑ,13:49:00 ,13:50:00
MSC 1337,5,SA,13:54:00 ,13:55:00
MSC 1337,6,PD,13:58:00 ,13:59:00
MSC 1337,7,PC,14:02:00 ,14:03:00
MSC 1337,8,SAN,14:05:00 ,14:06:00
MSC 1337,9,VTC,14:07:00 ,14:08:00
MSC 1337,10,DIA,14:11:00 ,14:12:00
MSC 1337,11,PRD,14:14:00 ,14:15:00
MSC 1337,12,EDS,14:17:00 ,14:18:00
MSC 1337,13,NIC,14:24:00 ,14:25:00
MSC 1337,14,FTI,14:28:00 ,14:29:00
MSC 1337,15,BIC,14:33:00 ,14:34:00
MSC 1337,16,SU,14:42:00 ,14:43:00
MSC 1337,17,AA,14:49:00 ,14:49:00
MSC 1437,1,TU,14:37:00,14:37:00
MSC 1437,2,BLU,14:42:00,14:43:00
MSC 1437,3,LLN,14:46:00,14:47:00
Expand Down
8 changes: 5 additions & 3 deletions gtfs/trips.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ MSC 1000,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1100,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1200,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1300,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1430,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1400,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1500,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1600,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1700,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1730,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
Expand All @@ -20,15 +21,16 @@ MSC 1830,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1900,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 1930,MSC,EVERYDAY,NB,MSC to Tutuban (Northbound)
MSC 507,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 607,MSC,EVERYDAY,SB,MSC to Sucat (Southbound)
MSC 607,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 707,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 737,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 807,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 837,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 937,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 1037,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 1137,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 1307,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 1237,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 1337,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 1437,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 1537,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
MSC 1607,MSC,EVERYDAY,SB,MSC to Alabang (Southbound)
Expand Down
Binary file added images/nb081517.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sb081517.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2ccd20d

Please sign in to comment.