Code Monkey home page Code Monkey logo

gtfs's Introduction

GTFS Ruby

Run CI Tasks

A Ruby wrapper for the General Transit Feed Specification

Getting started

Initialize a new GTFS source:

# Defaults to strict checking of required columns
source = GTFS::Source.build(<URI or Path to GTFS zip file>)

# Relax the column checks, useful for sources that don't conform to standard
source = GTFS::Source.build(<URI or Path to GTFS zip file>, {strict: false})

Accessing GTFS data from the source:

source.agencies
source.stops
source.routes
source.trips
source.stop_times
source.calendars
source.calendar_dates     
source.fare_attributes    
source.fare_rules         
source.shapes
source.frequencies        
source.transfers          

Alternatively:

source.each_agency {|agency| puts agency}
...
source.each_transfer {|transfer| puts transfer}

License

This project is licensed under the terms of the MIT license.

See this license at LICENSE.

gtfs's People

Contributors

alwold avatar drewda avatar eikes avatar hkjasf687261gh avatar jdurand avatar jloup avatar mikepfirrmann avatar nerded avatar qiheme avatar rrishabh avatar stephenyeargin avatar stuwil avatar timclipsham avatar xionon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gtfs's Issues

cannot load such file -- zip/zip

When simply adding gtfs to my gemfile I can't launch my app due to this error:

`require': cannot load such file -- zip/zip (LoadError)
/gems/gtfs-0.2.1/lib/gtfs/source.rb:3

It appears the gtfs gem depends on a very old rubyzip implementation. I made it work by adding zip-zip to my dependencies, but it should either be documented or maybe updated the source.rb to use zip only...

support of directory for GTFS#build?

Currently, GTFS supports loading through URL, or Zip files.

How about supporting loading data from directory also? In this case, the directory is just the unzip from the zip file.

rubyzip 2

I would like to see rubyzip 2 support. I have created a fork for that. But I am unable to create a PR:

Pull request creation failed. Validation failed: must be a collaborator

I am not sure if that's intentional. But anyways, here is the branch. The tests pass:

https://github.com/eikes/gtfs/tree/rubyzip-v2

agency.email return NoMethodError

agencies = source.agencies

[27] pry(main)> agencies[1].email
NoMethodError: undefined method `email' for #GTFS::Agency:0x007f918c8b9b40
[28] pry(main)> agencies[1]
=> #<GTFS::Agency:0x007f918c8b9b40
@id="2",
@lang="EN",
@name="Massport",
@phone="1-800-23-LOGAN",
@Timezone="America/New_York",
@url="http://www.massport.com">
[29] pry(main)> agencies[1].fare_url
=> nil

pry(main)> GTFS::Agency.attrs
=> [:name, :url, :timezone, :id, :lang, :phone, :fare_url]

As you can see the agency in question does not have a fare_url or an email, but calling #fare_url => nil, whereas #email => NoMethodError

GTFS::InvalidSourceException: Zip end of central directory signature not found

When trying to load Boston's MBTA's feed:

irb(main):002:0> source = GTFS::Source.build('http://developer.mbta.com/lib/gtrtfs/Passages.pb')
GTFS::InvalidSourceException: Zip end of central directory signature not found
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/gtfs-0.2.1/lib/gtfs/url_source.rb:18:in `rescue in load_archive'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/gtfs-0.2.1/lib/gtfs/url_source.rb:8:in `load_archive'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/gtfs-0.2.1/lib/gtfs/source.rb:25:in `initialize'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/gtfs-0.2.1/lib/gtfs/source.rb:48:in `new'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/gtfs-0.2.1/lib/gtfs/source.rb:48:in `build'
    from (irb):2
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands/console.rb:90:in `start'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands/console.rb:9:in `start'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.1.0.rc1/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:247:in `require'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:247:in `require'
    from /Users/jacob/code/transit/bin/rails:8:in `<top (required)>'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:241:in `load'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:241:in `block in load'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:241:in `load'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/jacob/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

More details about their feed here:
http://realtime.mbta.com/portal
http://realtime.mbta.com/Portal/Content/Documents/MBTA-realtime_DeveloperDocumentation_v1.0.4_2013-11-05.pdf

Add context for gtfs entity properties into the classes

Several classes have standard values which carry extra meaning "1" = 1 transfer, nil = unlimited transfers. There's currently no way of getting that information without consulting the spec, add helpers that will provide detailed values for fields where appropriate.

empty routes

the source builder isn't recognizing routes data from the routes.txt file.

the source builds without errors, and all other data is available, but for some reason routes are empty.

this applies for both LocalSource and UrlSource.

not sure why this is happening.

@trip_id returns nil

The variable trip_id from stop_times comes nil everytime its called.

I dont know why, because the content of the class is:

<GTFS::StopTime:0x99bffc4 @trip_id="SA00100310", @arrival_time="13:19:00", @departure_time="13:19:00", @stop_id="4514", @stop_sequence="1", @stop_headsign=nil, @pickup_type=nil, @drop_off_type=nil, @shape_dist_traveled="0">

And row.trip_id returns 'nil'

Either route_short_name or route_long_name is required but not both

According to the spec:

At least one of route_short_name or route_long_name must be specified, or potentially both if
appropriate. If the route does not have a short name, please specify a route_long_name and use an
empty string as the value for this field.

The current validation on a Route requires both short_name and long_name and so those missing one of the values will be excluded from the data returned.

https://developers.google.com/transit/gtfs/reference#routes_fields

Streaming forEach of stop_times?

I'm trying to loop through the stop_times collection in a gtfs zipfile which has a large number of rows. Here is the number of lines of the contained files:

$ wc -l *.txt
      54 agency.txt
     284 calendar.txt
   24481 calendar_dates.txt
       2 feed_info.txt
    4010 routes.txt
 5708658 stop_times.txt
   50162 stops.txt
   50720 transfers.txt
  233480 trips.txt

When I try to loop through the stop_times collection on my source, my laptop starts swapping after a few minutes and I get nowhere. I think the problem is that gtfs parses the whole file and builds an array of it before my code is invoked. It would be nice if the lib could parse the lines and pass them to my code one row at a time as they are parsed. That way the whole file doesn't have to be kept in memory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.