gtfs-realtime 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +14 -5
- data/gtfs-realtime.gemspec +1 -1
- data/lib/gtfs/realtime.rb +0 -175
- data/lib/gtfs/realtime/bootstrap.rb +178 -0
- data/lib/gtfs/realtime/configuration.rb +5 -1
- data/lib/gtfs/realtime/database.rb +8 -14
- data/lib/gtfs/realtime/nearby.rb +19 -7
- data/lib/gtfs/realtime/stop.rb +1 -1
- data/lib/gtfs/realtime/vehicle_position.rb +1 -1
- data/lib/gtfs/realtime/version.rb +1 -1
- metadata +16 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05148a6c6a4925c9072942c4ab6a57c1d8ddda4b
|
4
|
+
data.tar.gz: 072e0487c28f7f7ff2483bdeac72f006dc507f8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2bd4c6f34c66db13ddc5eb56f27aa7238c1dc68208ce8a7ba027fb542b1b907539ebef06fccc7b042450361a2ae15e486f64183e4eca6caabf900711ca7b7e2
|
7
|
+
data.tar.gz: 29ec92ae65ecbef01d633610eea3594669a32510985089f8e7675f9b82acdf37dd7b2953f3e11cfe9683eed5bf1b944df55f0ca0247e1171fb707b6ca64e80a0
|
data/bin/console
CHANGED
@@ -2,13 +2,22 @@
|
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "gtfs/realtime"
|
5
|
+
require "sqlite3"
|
5
6
|
|
6
|
-
#
|
7
|
-
|
7
|
+
# Load the RIPTA feed as an example, with a sqlite3 database
|
8
|
+
GTFS::Realtime.configure do |config|
|
9
|
+
config.static_feed = "http://www.ripta.com/googledata/current/google_transit.zip"
|
10
|
+
config.trip_updates_feed = "http://realtime.ripta.com:81/api/tripupdates"
|
11
|
+
config.vehicle_positions_feed = "http://realtime.ripta.com:81/api/vehiclepositions"
|
12
|
+
config.service_alerts_feed = "http://realtime.ripta.com:81/api/servicealerts"
|
13
|
+
config.database_path = "sqlite://database.db"
|
14
|
+
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
def reload!
|
17
|
+
files = $LOADED_FEATURES.select { |feat| feat =~ /\/gtfs-realtime\// }
|
18
|
+
files.each { |file| load file }
|
19
|
+
GTFS::Realtime.refresh_realtime_feed!
|
20
|
+
end
|
12
21
|
|
13
22
|
require "irb"
|
14
23
|
IRB.start
|
data/gtfs-realtime.gemspec
CHANGED
@@ -23,11 +23,11 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.13"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "sqlite3"
|
26
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
28
|
spec.add_development_dependency "webmock"
|
28
29
|
|
29
30
|
spec.add_dependency "gtfs-realtime-bindings"
|
30
31
|
spec.add_dependency "gtfs"
|
31
32
|
spec.add_dependency "sequel"
|
32
|
-
spec.add_dependency "sqlite3"
|
33
33
|
end
|
data/lib/gtfs/realtime.rb
CHANGED
@@ -1,24 +1,8 @@
|
|
1
1
|
require "google/transit/gtfs-realtime.pb"
|
2
2
|
require "gtfs"
|
3
3
|
require "sequel"
|
4
|
-
require "sqlite3"
|
5
4
|
|
6
|
-
# we must load our Sequel DB schema first
|
7
|
-
require "gtfs/realtime/database"
|
8
|
-
|
9
|
-
require "gtfs/gtfs_gem_patch"
|
10
|
-
require "gtfs/realtime/calendar_date"
|
11
5
|
require "gtfs/realtime/configuration"
|
12
|
-
require "gtfs/realtime/route"
|
13
|
-
require "gtfs/realtime/service_alert"
|
14
|
-
require "gtfs/realtime/shape"
|
15
|
-
require "gtfs/realtime/stop"
|
16
|
-
require "gtfs/realtime/stop_time"
|
17
|
-
require "gtfs/realtime/stop_time_update"
|
18
|
-
require "gtfs/realtime/trip"
|
19
|
-
require "gtfs/realtime/trip_update"
|
20
|
-
require "gtfs/realtime/vehicle_position"
|
21
|
-
require "gtfs/realtime/version"
|
22
6
|
|
23
7
|
module GTFS
|
24
8
|
class Realtime
|
@@ -36,165 +20,6 @@ module GTFS
|
|
36
20
|
load_static_feed!
|
37
21
|
refresh_realtime_feed!
|
38
22
|
end
|
39
|
-
|
40
|
-
def load_static_feed!(force: false)
|
41
|
-
return if !force && GTFS::Realtime::Route.count > 0
|
42
|
-
|
43
|
-
static_data = GTFS::Source.build(@configuration.static_feed)
|
44
|
-
return unless static_data
|
45
|
-
|
46
|
-
GTFS::Realtime::Model.db.transaction do
|
47
|
-
GTFS::Realtime::CalendarDate.dataset.delete
|
48
|
-
GTFS::Realtime::CalendarDate.multi_insert(
|
49
|
-
static_data.calendar_dates.collect do |calendar_date|
|
50
|
-
{
|
51
|
-
service_id: calendar_date.service_id.strip,
|
52
|
-
date: Date.strptime(calendar_date.date, "%Y%m%d"),
|
53
|
-
exception_type: calendar_date.exception_type
|
54
|
-
}
|
55
|
-
end
|
56
|
-
)
|
57
|
-
|
58
|
-
GTFS::Realtime::Route.dataset.delete
|
59
|
-
GTFS::Realtime::Route.multi_insert(
|
60
|
-
static_data.routes.collect do |route|
|
61
|
-
{
|
62
|
-
id: route.id.strip,
|
63
|
-
short_name: route.short_name,
|
64
|
-
long_name: route.long_name,
|
65
|
-
url: route.url
|
66
|
-
}
|
67
|
-
end
|
68
|
-
)
|
69
|
-
|
70
|
-
GTFS::Realtime::Shape.dataset.delete
|
71
|
-
GTFS::Realtime::Shape.multi_insert(
|
72
|
-
static_data.shapes.collect do |shape|
|
73
|
-
{
|
74
|
-
id: shape.id.strip,
|
75
|
-
sequence: shape.pt_sequence,
|
76
|
-
latitude: shape.pt_lat.to_f,
|
77
|
-
longitude: shape.pt_lon.to_f
|
78
|
-
}
|
79
|
-
end
|
80
|
-
)
|
81
|
-
|
82
|
-
GTFS::Realtime::Stop.dataset.delete
|
83
|
-
GTFS::Realtime::Stop.multi_insert(
|
84
|
-
static_data.stops.collect do |stop|
|
85
|
-
{
|
86
|
-
id: stop.id.strip,
|
87
|
-
name: stop.name,
|
88
|
-
latitude: stop.lat.to_f,
|
89
|
-
longitude: stop.lon.to_f
|
90
|
-
}
|
91
|
-
end
|
92
|
-
)
|
93
|
-
|
94
|
-
GTFS::Realtime::StopTime.dataset.delete
|
95
|
-
GTFS::Realtime::StopTime.multi_insert(
|
96
|
-
static_data.stop_times.collect do |stop_time|
|
97
|
-
{
|
98
|
-
stop_id: stop_time.stop_id.strip,
|
99
|
-
trip_id: stop_time.trip_id.strip,
|
100
|
-
arrival_time: stop_time.arrival_time,
|
101
|
-
departure_time: stop_time.departure_time,
|
102
|
-
stop_sequence: stop_time.stop_sequence.to_i
|
103
|
-
}
|
104
|
-
end
|
105
|
-
)
|
106
|
-
|
107
|
-
GTFS::Realtime::Trip.dataset.delete
|
108
|
-
GTFS::Realtime::Trip.multi_insert(
|
109
|
-
static_data.trips.collect do |trip|
|
110
|
-
{
|
111
|
-
id: trip.id.strip,
|
112
|
-
headsign: trip.headsign.strip,
|
113
|
-
route_id: trip.route_id.strip,
|
114
|
-
service_id: trip.service_id.strip,
|
115
|
-
shape_id: trip.shape_id.strip,
|
116
|
-
direction_id: trip.direction_id
|
117
|
-
}
|
118
|
-
end
|
119
|
-
)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def refresh_realtime_feed!
|
124
|
-
trip_updates = get_entities(@configuration.trip_updates_feed)
|
125
|
-
vehicle_positions = get_entities(@configuration.vehicle_positions_feed)
|
126
|
-
service_alerts = get_entities(@configuration.service_alerts_feed)
|
127
|
-
|
128
|
-
GTFS::Realtime::Model.db.transaction do
|
129
|
-
GTFS::Realtime::TripUpdate.dataset.delete
|
130
|
-
GTFS::Realtime::TripUpdate.multi_insert(
|
131
|
-
trip_updates.collect do |trip_update|
|
132
|
-
{
|
133
|
-
id: trip_update.id.strip,
|
134
|
-
trip_id: trip_update.trip_update.trip.trip_id.strip,
|
135
|
-
route_id: trip_update.trip_update.trip.route_id.strip
|
136
|
-
}
|
137
|
-
end
|
138
|
-
)
|
139
|
-
|
140
|
-
GTFS::Realtime::StopTimeUpdate.dataset.delete
|
141
|
-
GTFS::Realtime::StopTimeUpdate.multi_insert(
|
142
|
-
trip_updates.collect do |trip_update|
|
143
|
-
trip_update.trip_update.stop_time_update.collect do |stop_time_update|
|
144
|
-
{
|
145
|
-
trip_update_id: trip_update.id.strip,
|
146
|
-
stop_id: stop_time_update.stop_id.strip,
|
147
|
-
arrival_delay: stop_time_update.arrival ? stop_time_update.arrival.delay : nil,
|
148
|
-
arrival_time: stop_time_update.arrival ? stop_time_update.arrival.time : nil,
|
149
|
-
departure_delay: stop_time_update.departure ? stop_time_update.departure.delay : nil,
|
150
|
-
departure_time: stop_time_update.departure ? stop_time_update.departure.time : nil,
|
151
|
-
}
|
152
|
-
end
|
153
|
-
end.flatten
|
154
|
-
)
|
155
|
-
|
156
|
-
GTFS::Realtime::VehiclePosition.dataset.delete
|
157
|
-
GTFS::Realtime::VehiclePosition.multi_insert(
|
158
|
-
vehicle_positions.collect do |vehicle|
|
159
|
-
{
|
160
|
-
trip_id: vehicle.vehicle.trip.trip_id.strip,
|
161
|
-
stop_id: vehicle.vehicle.stop_id.strip,
|
162
|
-
latitude: vehicle.vehicle.position.latitude.to_f,
|
163
|
-
longitude: vehicle.vehicle.position.longitude.to_f,
|
164
|
-
bearing: vehicle.vehicle.position.bearing.to_f,
|
165
|
-
timestamp: vehicle.vehicle.timestamp
|
166
|
-
}
|
167
|
-
end
|
168
|
-
)
|
169
|
-
|
170
|
-
GTFS::Realtime::ServiceAlert.dataset.delete
|
171
|
-
GTFS::Realtime::ServiceAlert.multi_insert(
|
172
|
-
service_alerts.collect do |service_alert|
|
173
|
-
{
|
174
|
-
stop_id: service_alert.alert.informed_entity.first.stop_id.strip,
|
175
|
-
header_text: service_alert.alert.header_text.translation.first.text,
|
176
|
-
description_text: service_alert.alert.description_text.translation.first.text,
|
177
|
-
start_time: service_alert.alert.active_period.first.start,
|
178
|
-
end_time: service_alert.alert.active_period.first.end
|
179
|
-
}
|
180
|
-
end
|
181
|
-
)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
private
|
186
|
-
|
187
|
-
def get_entities(path)
|
188
|
-
return [] if path.nil?
|
189
|
-
|
190
|
-
if File.exists?(path)
|
191
|
-
data = File.open(path, 'r'){|f| f.read}
|
192
|
-
else
|
193
|
-
data = Net::HTTP.get(URI.parse(path))
|
194
|
-
end
|
195
|
-
feed = Transit_realtime::FeedMessage.decode(data)
|
196
|
-
feed.entity # array of entities
|
197
|
-
end
|
198
23
|
end
|
199
24
|
end
|
200
25
|
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require "gtfs/gtfs_gem_patch"
|
2
|
+
require "gtfs/realtime/calendar_date"
|
3
|
+
require "gtfs/realtime/route"
|
4
|
+
require "gtfs/realtime/service_alert"
|
5
|
+
require "gtfs/realtime/shape"
|
6
|
+
require "gtfs/realtime/stop"
|
7
|
+
require "gtfs/realtime/stop_time"
|
8
|
+
require "gtfs/realtime/stop_time_update"
|
9
|
+
require "gtfs/realtime/trip"
|
10
|
+
require "gtfs/realtime/trip_update"
|
11
|
+
require "gtfs/realtime/vehicle_position"
|
12
|
+
require "gtfs/realtime/version"
|
13
|
+
|
14
|
+
module GTFS
|
15
|
+
class Realtime
|
16
|
+
# This is a singleton object, so everything will be on the class level
|
17
|
+
class << self
|
18
|
+
def load_static_feed!(force: false)
|
19
|
+
return if !force && GTFS::Realtime::Route.count > 0
|
20
|
+
|
21
|
+
static_data = GTFS::Source.build(@configuration.static_feed)
|
22
|
+
return unless static_data
|
23
|
+
|
24
|
+
GTFS::Realtime::Model.db.transaction do
|
25
|
+
GTFS::Realtime::CalendarDate.dataset.delete
|
26
|
+
GTFS::Realtime::CalendarDate.multi_insert(
|
27
|
+
static_data.calendar_dates.collect do |calendar_date|
|
28
|
+
{
|
29
|
+
service_id: calendar_date.service_id.strip,
|
30
|
+
date: Date.strptime(calendar_date.date, "%Y%m%d"),
|
31
|
+
exception_type: calendar_date.exception_type
|
32
|
+
}
|
33
|
+
end
|
34
|
+
)
|
35
|
+
|
36
|
+
GTFS::Realtime::Route.dataset.delete
|
37
|
+
GTFS::Realtime::Route.multi_insert(
|
38
|
+
static_data.routes.collect do |route|
|
39
|
+
{
|
40
|
+
id: route.id.strip,
|
41
|
+
short_name: route.short_name,
|
42
|
+
long_name: route.long_name,
|
43
|
+
url: route.url
|
44
|
+
}
|
45
|
+
end
|
46
|
+
)
|
47
|
+
|
48
|
+
GTFS::Realtime::Shape.dataset.delete
|
49
|
+
GTFS::Realtime::Shape.multi_insert(
|
50
|
+
static_data.shapes.collect do |shape|
|
51
|
+
{
|
52
|
+
id: shape.id.strip,
|
53
|
+
sequence: shape.pt_sequence,
|
54
|
+
latitude: shape.pt_lat.to_f,
|
55
|
+
longitude: shape.pt_lon.to_f
|
56
|
+
}
|
57
|
+
end
|
58
|
+
)
|
59
|
+
|
60
|
+
GTFS::Realtime::Stop.dataset.delete
|
61
|
+
GTFS::Realtime::Stop.multi_insert(
|
62
|
+
static_data.stops.collect do |stop|
|
63
|
+
{
|
64
|
+
id: stop.id.strip,
|
65
|
+
name: stop.name.strip,
|
66
|
+
latitude: stop.lat.to_f,
|
67
|
+
longitude: stop.lon.to_f
|
68
|
+
}
|
69
|
+
end
|
70
|
+
)
|
71
|
+
|
72
|
+
GTFS::Realtime::StopTime.dataset.delete
|
73
|
+
GTFS::Realtime::StopTime.multi_insert(
|
74
|
+
static_data.stop_times.collect do |stop_time|
|
75
|
+
{
|
76
|
+
stop_id: stop_time.stop_id.strip,
|
77
|
+
trip_id: stop_time.trip_id.strip,
|
78
|
+
arrival_time: stop_time.arrival_time,
|
79
|
+
departure_time: stop_time.departure_time,
|
80
|
+
stop_sequence: stop_time.stop_sequence.to_i
|
81
|
+
}
|
82
|
+
end
|
83
|
+
)
|
84
|
+
|
85
|
+
GTFS::Realtime::Trip.dataset.delete
|
86
|
+
GTFS::Realtime::Trip.multi_insert(
|
87
|
+
static_data.trips.collect do |trip|
|
88
|
+
{
|
89
|
+
id: trip.id.strip,
|
90
|
+
headsign: trip.headsign.strip,
|
91
|
+
route_id: trip.route_id.strip,
|
92
|
+
service_id: trip.service_id.strip,
|
93
|
+
shape_id: trip.shape_id.strip,
|
94
|
+
direction_id: trip.direction_id
|
95
|
+
}
|
96
|
+
end
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def refresh_realtime_feed!
|
102
|
+
trip_updates = get_entities(@configuration.trip_updates_feed)
|
103
|
+
vehicle_positions = get_entities(@configuration.vehicle_positions_feed)
|
104
|
+
service_alerts = get_entities(@configuration.service_alerts_feed)
|
105
|
+
|
106
|
+
GTFS::Realtime::Model.db.transaction do
|
107
|
+
GTFS::Realtime::TripUpdate.dataset.delete
|
108
|
+
GTFS::Realtime::TripUpdate.multi_insert(
|
109
|
+
trip_updates.collect do |trip_update|
|
110
|
+
{
|
111
|
+
id: trip_update.id.strip,
|
112
|
+
trip_id: trip_update.trip_update.trip.trip_id.strip,
|
113
|
+
route_id: trip_update.trip_update.trip.route_id.strip
|
114
|
+
}
|
115
|
+
end
|
116
|
+
)
|
117
|
+
|
118
|
+
GTFS::Realtime::StopTimeUpdate.dataset.delete
|
119
|
+
GTFS::Realtime::StopTimeUpdate.multi_insert(
|
120
|
+
trip_updates.collect do |trip_update|
|
121
|
+
trip_update.trip_update.stop_time_update.collect do |stop_time_update|
|
122
|
+
{
|
123
|
+
trip_update_id: trip_update.id.strip,
|
124
|
+
stop_id: stop_time_update.stop_id.strip,
|
125
|
+
arrival_delay: stop_time_update.arrival ? stop_time_update.arrival.delay : nil,
|
126
|
+
arrival_time: stop_time_update.arrival ? Time.at(stop_time_update.arrival.time) : nil,
|
127
|
+
departure_delay: stop_time_update.departure ? stop_time_update.departure.delay : nil,
|
128
|
+
departure_time: stop_time_update.departure ? Time.at(stop_time_update.departure.time) : nil,
|
129
|
+
}
|
130
|
+
end
|
131
|
+
end.flatten
|
132
|
+
)
|
133
|
+
|
134
|
+
GTFS::Realtime::VehiclePosition.dataset.delete
|
135
|
+
GTFS::Realtime::VehiclePosition.multi_insert(
|
136
|
+
vehicle_positions.collect do |vehicle|
|
137
|
+
{
|
138
|
+
trip_id: vehicle.vehicle.trip.trip_id.strip,
|
139
|
+
stop_id: vehicle.vehicle.stop_id.strip,
|
140
|
+
latitude: vehicle.vehicle.position.latitude.to_f,
|
141
|
+
longitude: vehicle.vehicle.position.longitude.to_f,
|
142
|
+
bearing: vehicle.vehicle.position.bearing.to_f,
|
143
|
+
timestamp: Time.at(vehicle.vehicle.timestamp)
|
144
|
+
}
|
145
|
+
end
|
146
|
+
)
|
147
|
+
|
148
|
+
GTFS::Realtime::ServiceAlert.dataset.delete
|
149
|
+
GTFS::Realtime::ServiceAlert.multi_insert(
|
150
|
+
service_alerts.collect do |service_alert|
|
151
|
+
{
|
152
|
+
stop_id: service_alert.alert.informed_entity.first.stop_id.strip,
|
153
|
+
header_text: service_alert.alert.header_text.translation.first.text,
|
154
|
+
description_text: service_alert.alert.description_text.translation.first.text,
|
155
|
+
start_time: Time.at(service_alert.alert.active_period.first.start),
|
156
|
+
end_time: Time.at(service_alert.alert.active_period.first.end)
|
157
|
+
}
|
158
|
+
end
|
159
|
+
)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
private
|
164
|
+
|
165
|
+
def get_entities(path)
|
166
|
+
return [] if path.nil?
|
167
|
+
|
168
|
+
if File.exists?(path)
|
169
|
+
data = File.open(path, 'r'){|f| f.read}
|
170
|
+
else
|
171
|
+
data = Net::HTTP.get(URI.parse(path))
|
172
|
+
end
|
173
|
+
feed = Transit_realtime::FeedMessage.decode(data)
|
174
|
+
feed.entity # array of entities
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -6,8 +6,12 @@ module GTFS
|
|
6
6
|
def database_path=(new_path)
|
7
7
|
@database_path = new_path
|
8
8
|
|
9
|
-
#
|
9
|
+
# now that we know the DB path, we can initialize the database
|
10
|
+
require 'gtfs/realtime/database'
|
10
11
|
GTFS::Realtime::Database.path = database_path
|
12
|
+
|
13
|
+
# now that we have a database, initialize all the other models
|
14
|
+
require 'gtfs/realtime/bootstrap'
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
@@ -14,12 +14,10 @@ module GTFS
|
|
14
14
|
|
15
15
|
# Set up all database tables
|
16
16
|
db.create_table? :gtfs_realtime_calendar_dates do
|
17
|
-
Integer :id, primary_key: true
|
18
17
|
String :service_id
|
19
18
|
Date :date
|
20
19
|
Integer :exception_type
|
21
20
|
|
22
|
-
index :id
|
23
21
|
index :service_id
|
24
22
|
end
|
25
23
|
|
@@ -35,8 +33,8 @@ module GTFS
|
|
35
33
|
db.create_table? :gtfs_realtime_shapes do
|
36
34
|
String :id
|
37
35
|
Integer :sequence
|
38
|
-
|
39
|
-
|
36
|
+
Float :latitude
|
37
|
+
Float :longitude
|
40
38
|
|
41
39
|
index :id
|
42
40
|
end
|
@@ -44,8 +42,8 @@ module GTFS
|
|
44
42
|
db.create_table? :gtfs_realtime_stops do
|
45
43
|
String :id, primary_key: true
|
46
44
|
String :name
|
47
|
-
|
48
|
-
|
45
|
+
Float :latitude
|
46
|
+
Float :longitude
|
49
47
|
|
50
48
|
index :id
|
51
49
|
end
|
@@ -96,9 +94,9 @@ module GTFS
|
|
96
94
|
db.create_table? :gtfs_realtime_vehicle_positions do
|
97
95
|
String :trip_id
|
98
96
|
String :stop_id
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
Float :latitude
|
98
|
+
Float :longitude
|
99
|
+
Float :bearing
|
102
100
|
Time :timestamp
|
103
101
|
|
104
102
|
index :trip_id
|
@@ -129,14 +127,10 @@ module GTFS
|
|
129
127
|
end
|
130
128
|
end
|
131
129
|
|
132
|
-
# If we have not defined our model parent class yet, initialize it.
|
133
|
-
# load any other model files, we must have some sort of database set up, so we
|
134
|
-
# use an in-memory database for now. Later on, we can change this if we wish by
|
135
|
-
# setting `database_path` in a `GTFS::Realtime.configure` block.
|
130
|
+
# If we have not defined our model parent class yet, initialize it.
|
136
131
|
if !defined?(GTFS::Realtime::Model)
|
137
132
|
GTFS::Realtime::Model = Class.new(Sequel::Model)
|
138
133
|
GTFS::Realtime::Model.plugin :many_through_many
|
139
|
-
GTFS::Realtime::Database.path = nil
|
140
134
|
|
141
135
|
class GTFS::Realtime::Model
|
142
136
|
def self.implicit_table_name
|
data/lib/gtfs/realtime/nearby.rb
CHANGED
@@ -1,14 +1,26 @@
|
|
1
1
|
module GTFS
|
2
2
|
class Realtime
|
3
3
|
module Nearby
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def self.included(base)
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
def distance(latitude, longitude)
|
11
|
+
Math::sqrt((latitude - self.latitude)**2 + (longitude - self.longitude)**2)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def nearby(latitude, longitude)
|
17
|
+
# TODO: this math is terrible! It'll fail for various edge cases.
|
18
|
+
# (e.g. close to the poles, overlapping to the prime meridian)
|
19
|
+
# That said, it's an okay approximation away from the poles/meridian.
|
8
20
|
|
9
|
-
|
10
|
-
|
11
|
-
|
21
|
+
all.select do |item|
|
22
|
+
item.distance(latitude, longitude) < 0.01
|
23
|
+
end
|
12
24
|
end
|
13
25
|
end
|
14
26
|
end
|
data/lib/gtfs/realtime/stop.rb
CHANGED
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Laughlin
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,20 +122,6 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: sqlite3
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
125
|
description: A gem to interact with realtime transit data presented in the GTFS Realtime
|
126
126
|
format (https://developers.google.com/transit/gtfs-realtime/).
|
127
127
|
email:
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- gtfs-realtime.gemspec
|
144
144
|
- lib/gtfs/gtfs_gem_patch.rb
|
145
145
|
- lib/gtfs/realtime.rb
|
146
|
+
- lib/gtfs/realtime/bootstrap.rb
|
146
147
|
- lib/gtfs/realtime/calendar_date.rb
|
147
148
|
- lib/gtfs/realtime/configuration.rb
|
148
149
|
- lib/gtfs/realtime/database.rb
|