Class: CTA::Bus
- Inherits:
-
Trip
- Object
- Sequel::Model
- Trip
- CTA::Bus
show all
- Defined in:
- lib/cta_redux/models/bus.rb
Overview
Note:
Current columns: [:route_id, :service_id, :trip_id, :direction_id, :block_id, :shape_id, :direction, :wheelchair_accessible, :schd_trip_id]
A Sequel::Model, inherited from Trip This corresponds to trips.txt in the GTFS feed, though the CTA does not fully implement the standard.
Defined Under Namespace
Classes: Live, Prediction
Constant Summary
Constants inherited
from Trip
Trip::BUS_ROUTES, Trip::L_ROUTES
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Trip
#calendar, #route, #shapes, #stop_times, #stops
Instance Attribute Details
Returns the Live data associated with this CTA::Bus, if available.
9
10
11
|
# File 'lib/cta_redux/models/bus.rb', line 9
def live
@live
end
|
Class Method Details
.find_active_run(run, timestamp, fuzz = false, direction = nil) ⇒ Object
Find a Trip that should be happening, given a timestamp and a route or run. The CTA does not return GTFS trip_id information in either the BusTracker or TrainTracker API, so it is actually somewhat difficult to associate an API response to a Trip. However, we know what should be happening at any given time. This method attempts a fuzzy find - internally, we often first try to find the exact Trip that should be happening according to the schedule, and then failing that we assume that the CTA is running late and look for trips that should have ended within the past 90 minutes. This almost always finds something. That said, however, it means we may sometimes find a Trip that’s incorrect. In practical usage however, that doesn’t matter too much - most Trips for a run service the same stops. However, to be safe, your program may wish to compare certain other bits of the API responses to ensure we found something valid. For example, almost all Brown line trains service the same stops, so finding the wrong Trip doesn’t matter too much. However, a handful of Brown line runs throughout the dat actually change to Orange line trains at Midway - so, you may wish to verify that the destination of the Trip matches the reported destination of the API. Suggestions on how to approach this problem are most welcome (as are patches for better behavior).
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/cta_redux/models/bus.rb', line 51
def self.find_active_run(run, timestamp, fuzz = false, direction = nil)
d = timestamp.is_a?(DateTime) ? timestamp : DateTime.parse(timestamp)
wday = d.strftime("%A").downcase
end_ts = (fuzz ? (d.to_time + (60 * 60 * 6) - (90 * 60)) : d).strftime("%H:%M:%S")
Trip.with_sql(" SELECT t.*\n FROM trips t\n JOIN stop_times st ON t.trip_id = st.trip_id\n JOIN calendar c ON t.service_id = c.service_id\n WHERE t.route_id = '\#{run}'\n \#{direction ? \" AND t.direction = '\#{direction.gsub(\"bound\", \"\")}'\" : '' }\n AND c.start_date <= '\#{d.to_s}'\n AND c.end_date >= '\#{d.to_s}'\n AND c.\#{wday}\n GROUP BY t.trip_id, st.departure_time\n HAVING MAX(st.departure_time) >= '\#{end_ts}'\n SQL\nend\n")
|
Instance Method Details
#block_id ⇒ Integer
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|
#direction ⇒ String
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|
#direction_id ⇒ Integer
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|
81
82
83
84
|
# File 'lib/cta_redux/models/bus.rb', line 81
def predictions!(options = {})
opts = (self.vehicle_id ? { :vehicles => self.vehicle_id } : { :routes => self.route_id })
CTA::BusTracker.predictions!(options.merge(opts))
end
|
#route_id ⇒ String
Also known as:
id
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|
#schd_trip_id ⇒ String
Also known as:
scheduled_trip_id, run
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|
#service_id ⇒ Integer
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|
#shape_id ⇒ Integer
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|
#trip_id ⇒ Integer
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|
#wheelchair_accessible ⇒ true, false
29
|
# File 'lib/cta_redux/models/bus.rb', line 29
alias_method :id, :route_id
|