Skip to content

Commit

Permalink
Merge pull request #179 from transitland/refactor-gtfs
Browse files Browse the repository at this point in the history
Refactor GTFS
  • Loading branch information
drewda committed Sep 24, 2015
2 parents fdb08ed + b647689 commit 1632b78
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 262 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ gem 'whenever', require: false # to manage crontab
# data model
gem 'squeel'
gem 'enumerize'
gem 'gtfs'
gem 'gtfs', github: 'transitland/gtfs', tag: 'v1.0.0rc1'
gem 'rgeo-geojson'
gem 'c_geohash', require: 'geohash'
gem 'json-schema'
Expand Down
18 changes: 12 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
GIT
remote: git://github.com/transitland/gtfs.git
revision: 21453060861b955ca63a06aec12fba34f677dfa3
tag: v1.0.0rc1
specs:
gtfs (0.2.5)
multi_json
rake
rubyzip (~> 1.1)

GIT
remote: git://github.com/transitland/transitland-ruby-client.git
revision: 3adc5991adcee9f41f862ebc30524ce204e42157
Expand All @@ -10,7 +20,7 @@ GIT
PATH
remote: components
specs:
datastore_admin (0.0.1)
datastore_admin (1.0.0rc2)
sinatra

GEM
Expand Down Expand Up @@ -128,10 +138,6 @@ GEM
git (1.2.9.1)
globalid (0.3.6)
activesupport (>= 4.1.0)
gtfs (0.2.4)
multi_json
rake
rubyzip (~> 1.1)
hashie (3.4.2)
hitimes (1.2.2)
http-cookie (1.0.2)
Expand Down Expand Up @@ -359,7 +365,7 @@ DEPENDENCIES
ffaker
figaro
foreman
gtfs
gtfs!
json-schema
mock_redis
oj
Expand Down
18 changes: 9 additions & 9 deletions app/models/operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def self.from_gtfs(entity, stops)
raise ArgumentError.new('Need at least one Stop') if stops.empty?
geohash = GeohashHelpers.fit(stops.map { |i| i[:geometry] })
geometry = Operator.convex_hull(stops, as: :wkt, projected: false)
name = [entity.name, entity.id, "unknown"]
name = [entity.agency_name, entity.id, "unknown"]
.select(&:present?)
.first
.first
onestop_id = OnestopId.new(
entity_prefix: 'o',
geohash: geohash,
entity_prefix: 'o',
geohash: geohash,
name: name
)
operator = Operator.new(
Expand All @@ -132,12 +132,12 @@ def self.from_gtfs(entity, stops)
operator[:geometry] = geometry
# Copy over GTFS attributes to tags
operator.tags ||= {}
operator.tags[:agency_phone] = entity.phone
operator.tags[:agency_lang] = entity.lang
operator.tags[:agency_fare_url] = entity.fare_url
operator.tags[:agency_phone] = entity.agency_phone
operator.tags[:agency_lang] = entity.agency_lang
operator.tags[:agency_fare_url] = entity.agency_fare_url
operator.tags[:agency_id] = entity.id
operator.timezone = entity.timezone
operator.website = entity.url
operator.timezone = entity.agency_timezone
operator.website = entity.agency_url
operator
end

Expand Down
16 changes: 8 additions & 8 deletions app/models/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def self.from_gtfs(entity, stops)
# GTFS Constructor
raise ArgumentError.new('Need at least one Stop') if stops.empty?
geohash = GeohashHelpers.fit(stops.map { |i| i[:geometry] })
name = [entity.short_name, entity.long_name, entity.id, "unknown"]
name = [entity.route_short_name, entity.route_long_name, entity.id, "unknown"]
.select(&:present?)
.first
.first
onestop_id = OnestopId.new(
entity_prefix: 'r',
geohash: geohash,
Expand All @@ -144,12 +144,12 @@ def self.from_gtfs(entity, stops)
# Copy over GTFS attributes to tags
vehicles = ['tram', 'metro', 'rail', 'bus', 'ferry', 'cablecar', 'gondola', 'funicalar']
route.tags ||= {}
route.tags[:vehicle_type] = vehicles[entity.type.to_i]
route.tags[:route_long_name] = entity.long_name
route.tags[:route_desc] = entity.desc
route.tags[:route_url] = entity.url
route.tags[:route_color] = entity.color
route.tags[:route_text_color] = entity.text_color
route.tags[:vehicle_type] = vehicles[entity.route_type.to_i]
route.tags[:route_long_name] = entity.route_long_name
route.tags[:route_desc] = entity.route_desc
route.tags[:route_url] = entity.route_url
route.tags[:route_color] = entity.route_color
route.tags[:route_text_color] = entity.route_text_color
route
end

Expand Down
16 changes: 8 additions & 8 deletions app/models/stop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ def conflate_with_osm
include FromGTFS
def self.from_gtfs(entity)
# GTFS Constructor
point = Stop::GEOFACTORY.point(entity.lon, entity.lat)
point = Stop::GEOFACTORY.point(entity.stop_lon, entity.stop_lat)
geohash = GeohashHelpers.encode(point, precision=GEOHASH_PRECISION)
name = [entity.name, entity.id, "unknown"]
name = [entity.stop_name, entity.id, "unknown"]
.select(&:present?)
.first
.first
onestop_id = OnestopId.new(
entity_prefix: 's',
geohash: geohash,
entity_prefix: 's',
geohash: geohash,
name: name
)
stop = Stop.new(
Expand All @@ -242,10 +242,10 @@ def self.from_gtfs(entity)
# Copy over GTFS attributes to tags
stop.tags ||= {}
stop.tags[:wheelchair_boarding] = entity.wheelchair_boarding
stop.tags[:stop_desc] = entity.desc
stop.tags[:stop_url] = entity.url
stop.tags[:stop_desc] = entity.stop_desc
stop.tags[:stop_url] = entity.stop_url
stop.tags[:zone_id] = entity.zone_id
stop.timezone = entity.timezone
stop.timezone = entity.stop_timezone
stop
end

Expand Down
1 change: 0 additions & 1 deletion app/workers/feed_eater_feed_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def perform(feed_onestop_id, import_level=0)
graph = nil
begin
graph = GTFSGraph.new(feed.file_path, feed)
graph.load_gtfs
operators = graph.load_tl
graph.create_changeset operators, import_level
rescue Exception => e
Expand Down
22 changes: 0 additions & 22 deletions config/initializers/gtfs.rb

This file was deleted.

Loading

0 comments on commit 1632b78

Please sign in to comment.