gtfs-realtime 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +4 -2
- data/lib/gtfs/realtime.rb +14 -3
- data/lib/gtfs/realtime/configuration.rb +8 -1
- data/lib/gtfs/realtime/database.rb +135 -0
- data/lib/gtfs/realtime/shape.rb +14 -0
- data/lib/gtfs/realtime/version.rb +1 -1
- metadata +3 -2
- data/lib/gtfs/realtime/db_schema.rb +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93c88ec86fdf9817120942d1a1d303a3713a96d9
|
4
|
+
data.tar.gz: 37da22bb5fb75d046689dcd1154f15b062e53f8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 390cab27e23ef7f3adbf72be6dc1d73fd22008ca324e13b13275d5c976bb4a6ae7c57207faa6928e4ceb43b51c5816a9bd9dee684893bd5d0f6c827c7a928dcc
|
7
|
+
data.tar.gz: 5620d60d1f92ec842935d7e310e2ca6d9a42f4bba2ddf5e8867b3a254c76badb2333026d5dde52a6f2a4d53c74023f841c0905e289e864167930aa57b0118413
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -26,17 +26,19 @@ Basic functionality currently works like this:
|
|
26
26
|
require 'gtfs-realtime'
|
27
27
|
|
28
28
|
GTFS::Realtime.configure do |config|
|
29
|
-
config.static_feed = "http://www.ripta.com/googledata/current/google_transit.zip"
|
29
|
+
config.static_feed = "http://www.ripta.com/googledata/current/google_transit.zip" # File path or URL
|
30
30
|
config.trip_updates_feed = "http://realtime.ripta.com:81/api/tripupdates"
|
31
31
|
config.vehicle_positions_feed = "http://realtime.ripta.com:81/api/vehiclepositions"
|
32
32
|
config.service_alerts_feed = "http://realtime.ripta.com:81/api/servicealerts"
|
33
|
+
config.database_path = "sqlite://database.db" # leave unset to use an in-memory database
|
33
34
|
end
|
34
35
|
|
35
36
|
# After calling 'configure', the gem loads all relevant GTFS info into a database.
|
36
37
|
# This may take some time (up to a minute) depending on the size of the input data.
|
37
38
|
# By default, gtfs-realtime uses an in-memory database, which requires reloading all
|
38
39
|
# data from scratch on each launch. If you'd like to use a persistent database instead,
|
39
|
-
# set
|
40
|
+
# set 'config.database_path' above, and include a scheme/protocol path for the DB type
|
41
|
+
# that you would like to use. gtfs-realtime will generate the relevant tables.
|
40
42
|
|
41
43
|
@nearby = GTFS::Realtime::Stop.nearby(41.834521, -71.396906)
|
42
44
|
stop = @nearby.first
|
data/lib/gtfs/realtime.rb
CHANGED
@@ -4,12 +4,13 @@ require "sequel"
|
|
4
4
|
require "sqlite3"
|
5
5
|
|
6
6
|
# we must load our Sequel DB schema first
|
7
|
-
require "gtfs/realtime/
|
7
|
+
require "gtfs/realtime/database"
|
8
8
|
|
9
9
|
require "gtfs/gtfs_gem_patch"
|
10
10
|
require "gtfs/realtime/configuration"
|
11
11
|
require "gtfs/realtime/route"
|
12
12
|
require "gtfs/realtime/service_alert"
|
13
|
+
require "gtfs/realtime/shape"
|
13
14
|
require "gtfs/realtime/stop"
|
14
15
|
require "gtfs/realtime/stop_time"
|
15
16
|
require "gtfs/realtime/stop_time_update"
|
@@ -53,6 +54,18 @@ module GTFS
|
|
53
54
|
end
|
54
55
|
)
|
55
56
|
|
57
|
+
GTFS::Realtime::Shape.dataset.delete
|
58
|
+
GTFS::Realtime::Shape.multi_insert(
|
59
|
+
static_data.shapes.collect do |shape|
|
60
|
+
{
|
61
|
+
id: shape.id.strip,
|
62
|
+
sequence: shape.pt_sequence,
|
63
|
+
latitude: shape.pt_lat.to_f,
|
64
|
+
longitude: shape.pt_lon.to_f
|
65
|
+
}
|
66
|
+
end
|
67
|
+
)
|
68
|
+
|
56
69
|
GTFS::Realtime::Stop.dataset.delete
|
57
70
|
GTFS::Realtime::Stop.multi_insert(
|
58
71
|
static_data.stops.collect do |stop|
|
@@ -90,8 +103,6 @@ module GTFS
|
|
90
103
|
}
|
91
104
|
end
|
92
105
|
)
|
93
|
-
|
94
|
-
# TODO: load shapes
|
95
106
|
end
|
96
107
|
end
|
97
108
|
|
@@ -1,7 +1,14 @@
|
|
1
1
|
module GTFS
|
2
2
|
class Realtime
|
3
3
|
class Configuration
|
4
|
-
attr_accessor :static_feed, :trip_updates_feed, :vehicle_positions_feed, :service_alerts_feed
|
4
|
+
attr_accessor :static_feed, :trip_updates_feed, :vehicle_positions_feed, :service_alerts_feed, :database_path
|
5
|
+
|
6
|
+
def database_path=(new_path)
|
7
|
+
@database_path = new_path
|
8
|
+
|
9
|
+
# reinitialize the database with the new path
|
10
|
+
GTFS::Realtime::Database.path = database_path
|
11
|
+
end
|
5
12
|
end
|
6
13
|
end
|
7
14
|
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module GTFS
|
2
|
+
class Realtime
|
3
|
+
class Database
|
4
|
+
class << self
|
5
|
+
attr_writer :database_path
|
6
|
+
|
7
|
+
def path=(new_path)
|
8
|
+
@path = new_path
|
9
|
+
|
10
|
+
# This script sets up an in-memory DB so that it can be used by this gem.
|
11
|
+
# It also extends Sequel::Model so that Sequel may be used independently by
|
12
|
+
# the parent project if desired.
|
13
|
+
db = Sequel.connect(new_path || "sqlite://")
|
14
|
+
|
15
|
+
# Set up all database tables
|
16
|
+
db.create_table? :gtfs_realtime_routes do
|
17
|
+
String :id, primary_key: true
|
18
|
+
String :short_name
|
19
|
+
String :long_name
|
20
|
+
String :url
|
21
|
+
|
22
|
+
index :id
|
23
|
+
end
|
24
|
+
|
25
|
+
db.create_table? :gtfs_realtime_shapes do
|
26
|
+
String :id
|
27
|
+
Integer :sequence
|
28
|
+
Double :latitude
|
29
|
+
Double :longitude
|
30
|
+
|
31
|
+
index :id
|
32
|
+
end
|
33
|
+
|
34
|
+
db.create_table? :gtfs_realtime_stops do
|
35
|
+
String :id, primary_key: true
|
36
|
+
String :name
|
37
|
+
Double :latitude
|
38
|
+
Double :longitude
|
39
|
+
|
40
|
+
index :id
|
41
|
+
end
|
42
|
+
|
43
|
+
db.create_table? :gtfs_realtime_stop_times do
|
44
|
+
String :trip_id
|
45
|
+
String :stop_id
|
46
|
+
String :arrival_time
|
47
|
+
String :departure_time
|
48
|
+
Integer :stop_sequence
|
49
|
+
|
50
|
+
index :trip_id
|
51
|
+
index :stop_id
|
52
|
+
end
|
53
|
+
|
54
|
+
db.create_table? :gtfs_realtime_trips do
|
55
|
+
String :id, primary_key: true
|
56
|
+
String :headsign
|
57
|
+
String :route_id
|
58
|
+
String :service_id
|
59
|
+
String :shape_id
|
60
|
+
|
61
|
+
index :id
|
62
|
+
index :route_id
|
63
|
+
end
|
64
|
+
|
65
|
+
db.create_table? :gtfs_realtime_trip_updates do
|
66
|
+
String :id, primary_key: true
|
67
|
+
String :trip_id
|
68
|
+
String :route_id
|
69
|
+
|
70
|
+
index :id
|
71
|
+
end
|
72
|
+
|
73
|
+
db.create_table? :gtfs_realtime_stop_time_updates do
|
74
|
+
String :trip_update_id
|
75
|
+
String :stop_id
|
76
|
+
Integer :arrival_delay
|
77
|
+
Time :arrival_time
|
78
|
+
Integer :departure_delay
|
79
|
+
Time :departure_time
|
80
|
+
|
81
|
+
index :trip_update_id
|
82
|
+
index :stop_id
|
83
|
+
end
|
84
|
+
|
85
|
+
db.create_table? :gtfs_realtime_vehicle_positions do
|
86
|
+
String :trip_id
|
87
|
+
String :stop_id
|
88
|
+
Double :latitude
|
89
|
+
Double :longitude
|
90
|
+
Double :bearing
|
91
|
+
Time :timestamp
|
92
|
+
|
93
|
+
index :trip_id
|
94
|
+
index :stop_id
|
95
|
+
end
|
96
|
+
|
97
|
+
db.create_table? :gtfs_realtime_service_alerts do
|
98
|
+
String :stop_id
|
99
|
+
String :header_text
|
100
|
+
Text :description_text
|
101
|
+
Time :start_time
|
102
|
+
Time :end_time
|
103
|
+
|
104
|
+
index :stop_id
|
105
|
+
end
|
106
|
+
|
107
|
+
# Set up all gtfs-realtime models to use this database
|
108
|
+
model_classes.each do |model_class|
|
109
|
+
model_class.db = db
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def model_classes
|
114
|
+
ObjectSpace.each_object(::Class).select{|klass| klass <= GTFS::Realtime::Model}
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# If we have not defined our model parent class yet, initialize it. Before we can
|
122
|
+
# load any other model files, we must have some sort of database set up, so we
|
123
|
+
# use an in-memory database for now. Later on, we can change this if we wish by
|
124
|
+
# setting `database_path` in a `GTFS::Realtime.configure` block.
|
125
|
+
if !defined?(GTFS::Realtime::Model)
|
126
|
+
GTFS::Realtime::Model = Class.new(Sequel::Model)
|
127
|
+
GTFS::Realtime::Model.plugin :many_through_many
|
128
|
+
GTFS::Realtime::Database.path = nil
|
129
|
+
|
130
|
+
class GTFS::Realtime::Model
|
131
|
+
def self.implicit_table_name
|
132
|
+
"gtfs_realtime_#{super}".to_sym
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtfs-realtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Laughlin
|
@@ -130,10 +130,11 @@ files:
|
|
130
130
|
- lib/gtfs/gtfs_gem_patch.rb
|
131
131
|
- lib/gtfs/realtime.rb
|
132
132
|
- lib/gtfs/realtime/configuration.rb
|
133
|
-
- lib/gtfs/realtime/
|
133
|
+
- lib/gtfs/realtime/database.rb
|
134
134
|
- lib/gtfs/realtime/nearby.rb
|
135
135
|
- lib/gtfs/realtime/route.rb
|
136
136
|
- lib/gtfs/realtime/service_alert.rb
|
137
|
+
- lib/gtfs/realtime/shape.rb
|
137
138
|
- lib/gtfs/realtime/stop.rb
|
138
139
|
- lib/gtfs/realtime/stop_time.rb
|
139
140
|
- lib/gtfs/realtime/stop_time_update.rb
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# This script sets up an in-memory DB so that it can be used by this gem.
|
2
|
-
# It also extends Sequel::Model so that Sequel may be used independently by
|
3
|
-
# the parent project if desired.
|
4
|
-
db = Sequel.sqlite(ENV["GTFS_DATABASE_PATH"])
|
5
|
-
|
6
|
-
# Set up all database tables
|
7
|
-
db.create_table? :routes do
|
8
|
-
String :id, primary_key: true
|
9
|
-
String :short_name
|
10
|
-
String :long_name
|
11
|
-
String :url
|
12
|
-
|
13
|
-
index :id
|
14
|
-
end
|
15
|
-
|
16
|
-
db.create_table? :stops do
|
17
|
-
String :id, primary_key: true
|
18
|
-
String :name
|
19
|
-
Double :latitude
|
20
|
-
Double :longitude
|
21
|
-
|
22
|
-
index :id
|
23
|
-
end
|
24
|
-
|
25
|
-
db.create_table? :stop_times do
|
26
|
-
String :trip_id
|
27
|
-
String :stop_id
|
28
|
-
String :arrival_time
|
29
|
-
String :departure_time
|
30
|
-
Integer :stop_sequence
|
31
|
-
|
32
|
-
index :trip_id
|
33
|
-
index :stop_id
|
34
|
-
end
|
35
|
-
|
36
|
-
db.create_table? :trips do
|
37
|
-
String :id, primary_key: true
|
38
|
-
String :headsign
|
39
|
-
String :route_id
|
40
|
-
String :service_id
|
41
|
-
String :shape_id
|
42
|
-
|
43
|
-
index :id
|
44
|
-
index :route_id
|
45
|
-
end
|
46
|
-
|
47
|
-
db.create_table? :trip_updates do
|
48
|
-
String :id, primary_key: true
|
49
|
-
String :trip_id
|
50
|
-
String :route_id
|
51
|
-
|
52
|
-
index :id
|
53
|
-
end
|
54
|
-
|
55
|
-
db.create_table? :stop_time_updates do
|
56
|
-
String :trip_update_id
|
57
|
-
String :stop_id
|
58
|
-
Integer :arrival_delay
|
59
|
-
Time :arrival_time
|
60
|
-
Integer :departure_delay
|
61
|
-
Time :departure_time
|
62
|
-
|
63
|
-
index :trip_update_id
|
64
|
-
index :stop_id
|
65
|
-
end
|
66
|
-
|
67
|
-
db.create_table? :vehicle_positions do
|
68
|
-
String :trip_id
|
69
|
-
String :stop_id
|
70
|
-
Double :latitude
|
71
|
-
Double :longitude
|
72
|
-
Double :bearing
|
73
|
-
Time :timestamp
|
74
|
-
|
75
|
-
index :trip_id
|
76
|
-
index :stop_id
|
77
|
-
end
|
78
|
-
|
79
|
-
db.create_table? :service_alerts do
|
80
|
-
String :stop_id
|
81
|
-
String :header_text
|
82
|
-
Text :description_text
|
83
|
-
Time :start_time
|
84
|
-
Time :end_time
|
85
|
-
|
86
|
-
index :stop_id
|
87
|
-
end
|
88
|
-
|
89
|
-
# Set up all gtfs-realtime models to use this database
|
90
|
-
GTFS::Realtime::Model = Class.new(Sequel::Model)
|
91
|
-
GTFS::Realtime::Model.db = db
|
92
|
-
GTFS::Realtime::Model.plugin :many_through_many
|