├── requirements.txt ├── tests ├── fixtures │ ├── empty │ │ ├── calendar.txt │ │ ├── fare_rules.txt │ │ ├── trips.txt │ │ ├── stops.txt │ │ ├── agency.txt │ │ ├── calendar_dates.txt │ │ ├── transfers.txt │ │ ├── frequencies.txt │ │ ├── feed_info.txt │ │ ├── routes.txt │ │ ├── shapes.txt │ │ ├── fare_attributes.txt │ │ └── stop_times.txt │ ├── amazon-2017-08-06 │ │ ├── calendar_dates.txt │ │ ├── agency.txt │ │ ├── calendar.txt │ │ ├── stops.txt │ │ └── routes.txt │ ├── region-nord-v2 │ │ ├── stops.txt │ │ ├── agency.txt │ │ ├── calendar_dates.txt │ │ └── routes.txt │ ├── trimet-vermont-2018-02-06 │ │ ├── calendar.txt │ │ ├── routes.txt │ │ ├── feed_info.txt │ │ ├── agency.txt │ │ ├── transfers.txt │ │ ├── calendar_dates.txt │ │ └── trips.txt │ ├── caltrain-2017-07-24 │ │ ├── calendar_attributes.txt │ │ ├── agency.txt │ │ ├── realtime_routes.txt │ │ ├── farezone_attributes.txt │ │ ├── routes.txt │ │ ├── calendar.txt │ │ ├── fare_attributes.txt │ │ ├── directions.txt │ │ ├── stop_attributes.txt │ │ ├── fare_rules.txt │ │ ├── stops.txt │ │ └── realtime_trips.txt │ ├── israel-public-transportation-route-2126 │ │ ├── agency.txt │ │ ├── routes.txt │ │ ├── calendar.txt │ │ ├── trips.txt │ │ ├── stops.txt │ │ ├── stop_times.txt │ │ └── shapes.txt │ ├── nested │ │ └── a │ │ │ └── b │ │ │ └── c │ │ │ └── caltrain-2017-07-24 │ │ │ ├── agency.txt │ │ │ ├── calendar_attributes.txt │ │ │ ├── realtime_routes.txt │ │ │ ├── farezone_attributes.txt │ │ │ ├── routes.txt │ │ │ ├── calendar.txt │ │ │ ├── fare_attributes.txt │ │ │ ├── directions.txt │ │ │ ├── stop_attributes.txt │ │ │ ├── fare_rules.txt │ │ │ ├── stops.txt │ │ │ └── realtime_trips.txt │ └── seattle-area-2017-11-16 │ │ ├── calendar.txt │ │ ├── agency.txt │ │ ├── routes.txt │ │ └── calendar_dates.txt ├── __init__.py ├── helpers.py ├── test_parsers.py ├── test_utilities.py ├── test_writers.py ├── test_readers.py └── test_feed.py ├── docs ├── history.rst ├── readme.rst ├── contributing.rst ├── .gitignore ├── usage.rst ├── index.rst ├── installation.rst ├── Makefile ├── make.bat └── conf.py ├── partridge ├── __version__.py ├── types.py ├── __init__.py ├── parsers.py ├── geo.py ├── writers.py ├── utilities.py ├── gtfs.py ├── readers.py └── config.py ├── .readthedocs.yml ├── dependency-graph.png ├── setup.cfg ├── .flake8 ├── requirements_dev.txt ├── MANIFEST.in ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE.md └── workflows │ └── python-package.yml ├── .travis.yml ├── LICENSE ├── .gitignore ├── RELEASING.rst ├── dependency-graph.dot ├── setup.py ├── Makefile ├── CONTRIBUTING.rst ├── HISTORY.rst └── README.rst /requirements.txt: -------------------------------------------------------------------------------- 1 | . -------------------------------------------------------------------------------- /tests/fixtures/empty/calendar.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../HISTORY.rst 2 | -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/fare_rules.txt: -------------------------------------------------------------------------------- 1 | fare_id 2 | -------------------------------------------------------------------------------- /partridge/__version__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.1.2" 2 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/trips.txt: -------------------------------------------------------------------------------- 1 | route_id,service_id,trip_id 2 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | /partridge.rst 2 | /partridge.*.rst 3 | /modules.rst 4 | -------------------------------------------------------------------------------- /tests/fixtures/empty/stops.txt: -------------------------------------------------------------------------------- 1 | stop_id,stop_name,stop_lat,stop_lon 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/agency.txt: -------------------------------------------------------------------------------- 1 | agency_name,agency_url,agency_timezone 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/calendar_dates.txt: -------------------------------------------------------------------------------- 1 | service_id,date,exception_type 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/transfers.txt: -------------------------------------------------------------------------------- 1 | from_stop_id,to_stop_id,transfer_type 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/frequencies.txt: -------------------------------------------------------------------------------- 1 | trip_id,start_time,end_time,headway_secs 2 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | build: 2 | image: latest 3 | 4 | python: 5 | version: 3.6 6 | -------------------------------------------------------------------------------- /tests/fixtures/empty/feed_info.txt: -------------------------------------------------------------------------------- 1 | feed_publisher_name,feed_publisher_url,feed_lang 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/routes.txt: -------------------------------------------------------------------------------- 1 | route_id,route_short_name,route_long_name,route_type 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/shapes.txt: -------------------------------------------------------------------------------- 1 | shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence 2 | -------------------------------------------------------------------------------- /dependency-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/remix/partridge/HEAD/dependency-graph.png -------------------------------------------------------------------------------- /partridge/types.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Dict 2 | 3 | View = Dict[str, Dict[str, Any]] 4 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """Unit test package for partridge.""" 4 | -------------------------------------------------------------------------------- /tests/fixtures/empty/fare_attributes.txt: -------------------------------------------------------------------------------- 1 | fare_id,price,currency_type,payment_method,transfers 2 | -------------------------------------------------------------------------------- /tests/fixtures/empty/stop_times.txt: -------------------------------------------------------------------------------- 1 | trip_id,arrival_time,departure_time,stop_id,stop_sequence 2 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ===== 2 | Usage 3 | ===== 4 | 5 | To use partridge in a project:: 6 | 7 | import partridge 8 | -------------------------------------------------------------------------------- /tests/fixtures/amazon-2017-08-06/calendar_dates.txt: -------------------------------------------------------------------------------- 1 | service_id,date,exception_type 2 | 1,20170806,1 3 | 1,20170806,2 -------------------------------------------------------------------------------- /tests/fixtures/region-nord-v2/stops.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/remix/partridge/HEAD/tests/fixtures/region-nord-v2/stops.txt -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | 4 | [flake8] 5 | exclude = docs 6 | 7 | [aliases] 8 | test = pytest 9 | # Define setup.py command aliases here 10 | -------------------------------------------------------------------------------- /tests/fixtures/trimet-vermont-2018-02-06/calendar.txt: -------------------------------------------------------------------------------- 1 | service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date 2 | unknown,0,1,1,1,1,0,0,20171120,20180309 3 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | exclude = 3 | .eggs 4 | .git 5 | __pycache__ 6 | build 7 | dist 8 | docs 9 | scratch 10 | venv 11 | 12 | max-line-length = 100 13 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/calendar_attributes.txt: -------------------------------------------------------------------------------- 1 | service_id,service_description 2 | CT-17JUL-Caltrain-Saturday-03,Saturday 3 | CT-17JUL-Caltrain-Sunday-01,Sunday 4 | CT-17JUL-Combo-Weekday-01,Weekday 5 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | pip 2 | bumpversion 3 | wheel 4 | watchdog 5 | flake8 6 | coverage 7 | Sphinx 8 | cryptography 9 | PyYAML 10 | pytest 11 | pytest-runner 12 | networkx 13 | sphinx-autodoc-annotation 14 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/agency.txt: -------------------------------------------------------------------------------- 1 | agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_id 2 | "Caltrain","http://www.caltrain.com",America/Los_Angeles,en,800-660-4287,caltrain-ca-us 3 | -------------------------------------------------------------------------------- /tests/fixtures/region-nord-v2/agency.txt: -------------------------------------------------------------------------------- 1 | agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url 2 | 160,AtB,https://www.atb.no/,Europe/Oslo,nb,02820,https://www.atb.no/priser/ 3 | -------------------------------------------------------------------------------- /tests/fixtures/amazon-2017-08-06/agency.txt: -------------------------------------------------------------------------------- 1 | agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url 2 | 81,"Welcome to Amazon SLU Shuttle",http://sea-shuttles.com,America/Los_Angeles,en,, 3 | -------------------------------------------------------------------------------- /tests/fixtures/israel-public-transportation-route-2126/agency.txt: -------------------------------------------------------------------------------- 1 | agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url 2 | 4,אגד תעבורה,http://www.egged-taavura.co.il,Asia/Jerusalem,he,, 3 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/agency.txt: -------------------------------------------------------------------------------- 1 | agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_id 2 | "Caltrain","http://www.caltrain.com",America/Los_Angeles,en,800-660-4287,caltrain-ca-us 3 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/calendar_attributes.txt: -------------------------------------------------------------------------------- 1 | service_id,service_description 2 | CT-17JUL-Caltrain-Saturday-03,Saturday 3 | CT-17JUL-Caltrain-Sunday-01,Sunday 4 | CT-17JUL-Combo-Weekday-01,Weekday 5 | -------------------------------------------------------------------------------- /tests/fixtures/israel-public-transportation-route-2126/routes.txt: -------------------------------------------------------------------------------- 1 | route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_color 2 | 2126,4,6א,הרימון/השיקמה-נתניה<->תחנה מרכזית נתניה/הורדה-נתניה-2ה,21006-2-ה,3, 3 | -------------------------------------------------------------------------------- /tests/fixtures/trimet-vermont-2018-02-06/routes.txt: -------------------------------------------------------------------------------- 1 | route_id,agency_id,route_short_name,route_long_name,route_type,route_url,route_color,route_text_color,route_sort_order 2 | 1,TRIMET,1,Vermont,3,http://trimet.org//schedules/r001.htm,,,400 3 | -------------------------------------------------------------------------------- /tests/fixtures/amazon-2017-08-06/calendar.txt: -------------------------------------------------------------------------------- 1 | service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date 2 | 0,1,1,1,1,1,0,0,20170801,20170807 3 | 1,1,1,1,1,1,1,0,20170801,20170807 4 | 2,0,0,0,0,0,0,1,20170801,20170807 -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/realtime_routes.txt: -------------------------------------------------------------------------------- 1 | route_id,realtime_enabled,realtime_routename,realtime_routecode 2 | Bu-129,1,Baby Bullet,Baby Bullet 3 | Li-129,1,Limited,Limited 4 | Lo-129,1,Local,Local 5 | TaSj-129,0,TaSJ-Shuttle,TaSJ-Shuttle 6 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/realtime_routes.txt: -------------------------------------------------------------------------------- 1 | route_id,realtime_enabled,realtime_routename,realtime_routecode 2 | Bu-129,1,Baby Bullet,Baby Bullet 3 | Li-129,1,Limited,Limited 4 | Lo-129,1,Local,Local 5 | TaSj-129,0,TaSJ-Shuttle,TaSJ-Shuttle 6 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/farezone_attributes.txt: -------------------------------------------------------------------------------- 1 | zone_id,zone_name 2 | 1,CT Zone 1-SF to San Bruno 3 | 2,CT Zone 2-Millbrae to RWC 4 | 3,CT Zone 3-Atherton to Sunnyvale 5 | 4,CT Zone 4-Lawrence to Tamien 6 | 5,CT Zone 5-Capitol & Blossom Hill 7 | 6,CT Zone 6- Morgan Hill to Gilroy 8 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/routes.txt: -------------------------------------------------------------------------------- 1 | route_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color 2 | Bu-129,Baby Bullet,Bullet,,2,,E31837 3 | Li-129,Limited,Limited,,2,,FEF0B5 4 | Lo-129,Local,Local,,2,,77787B 5 | TaSj-129,TaSJ-Shuttle,TaSJ-Shuttle,,3,,41AD49 6 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include CONTRIBUTING.rst 2 | include HISTORY.rst 3 | include LICENSE 4 | include README.rst 5 | 6 | recursive-exclude tests * 7 | recursive-exclude * __pycache__ 8 | recursive-exclude * *.py[co] 9 | 10 | recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif 11 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/farezone_attributes.txt: -------------------------------------------------------------------------------- 1 | zone_id,zone_name 2 | 1,CT Zone 1-SF to San Bruno 3 | 2,CT Zone 2-Millbrae to RWC 4 | 3,CT Zone 3-Atherton to Sunnyvale 5 | 4,CT Zone 4-Lawrence to Tamien 6 | 5,CT Zone 5-Capitol & Blossom Hill 7 | 6,CT Zone 6- Morgan Hill to Gilroy 8 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/routes.txt: -------------------------------------------------------------------------------- 1 | route_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color 2 | Bu-129,Baby Bullet,Bullet,,2,,E31837 3 | Li-129,Limited,Limited,,2,,FEF0B5 4 | Lo-129,Local,Local,,2,,77787B 5 | TaSj-129,TaSJ-Shuttle,TaSJ-Shuttle,,3,,41AD49 6 | -------------------------------------------------------------------------------- /tests/fixtures/trimet-vermont-2018-02-06/feed_info.txt: -------------------------------------------------------------------------------- 1 | feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version,feed_id,feed_contact_url 2 | TriMet,http://trimet.org/,en,20180128,20180602,20180128-20180206-0148,TriMet,https://groups.google.com/forum/#!forum/transit-developers-pdx 3 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/calendar.txt: -------------------------------------------------------------------------------- 1 | service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date 2 | CT-17JUL-Caltrain-Saturday-03,1,1,1,1,1,1,1,20170715,20190720 3 | CT-17JUL-Caltrain-Sunday-01,0,0,0,0,0,0,1,20170716,20190714 4 | CT-17JUL-Combo-Weekday-01,1,1,1,1,1,0,0,20170717,20190719 5 | -------------------------------------------------------------------------------- /tests/fixtures/israel-public-transportation-route-2126/calendar.txt: -------------------------------------------------------------------------------- 1 | service_id,sunday,monday,tuesday,wednesday,thursday,friday,saturday,start_date,end_date 2 | 56449751,0,0,0,0,1,0,0,20180301,20180301 3 | 56449760,1,1,1,1,1,0,0,20180223,20180227 4 | 56449767,0,0,0,1,0,0,0,20180228,20180228 5 | 56449780,1,1,1,1,1,0,0,20180304,20180424 6 | -------------------------------------------------------------------------------- /tests/fixtures/israel-public-transportation-route-2126/trips.txt: -------------------------------------------------------------------------------- 1 | route_id,service_id,trip_id,trip_headsign,direction_id,shape_id 2 | 2126,56449760,435227_230218,תחנה מרכזית,1,93890 3 | 2126,56449780,435227_040318,תחנה מרכזית,1,93890 4 | 2126,56449751,3528905_010318,תחנה מרכזית,1,93890 5 | 2126,56449767,4679602_280218,תחנה מרכזית,1,93890 6 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/fare_attributes.txt: -------------------------------------------------------------------------------- 1 | fare_id,price,currency_type,payment_method,transfers,transfer_duration 2 | OW_1_20160228,3.75,USD,1,,14400 3 | OW_2_20160228,5.75,USD,1,,14400 4 | OW_3_20160228,7.75,USD,1,,14400 5 | OW_4_20160228,9.75,USD,1,,14400 6 | OW_5_20160228,11.75,USD,1,,14400 7 | OW_6_20160228,13.75,USD,1,,14400 8 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/calendar.txt: -------------------------------------------------------------------------------- 1 | service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date 2 | CT-17JUL-Caltrain-Saturday-03,1,1,1,1,1,1,1,20170715,20190720 3 | CT-17JUL-Caltrain-Sunday-01,0,0,0,0,0,0,1,20170716,20190714 4 | CT-17JUL-Combo-Weekday-01,1,1,1,1,1,0,0,20170717,20190719 5 | -------------------------------------------------------------------------------- /tests/fixtures/trimet-vermont-2018-02-06/agency.txt: -------------------------------------------------------------------------------- 1 | agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url,agency_email,bikes_policy_url 2 | TRIMET,TriMet,http://trimet.org/,America/Los_Angeles,en,503-238-RIDE,http://trimet.org/fares/,customerservice@trimet.org,http://trimet.org/howtoride/bikes/bikepolicies.htm 3 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/fare_attributes.txt: -------------------------------------------------------------------------------- 1 | fare_id,price,currency_type,payment_method,transfers,transfer_duration 2 | OW_1_20160228,3.75,USD,1,,14400 3 | OW_2_20160228,5.75,USD,1,,14400 4 | OW_3_20160228,7.75,USD,1,,14400 5 | OW_4_20160228,9.75,USD,1,,14400 6 | OW_5_20160228,11.75,USD,1,,14400 7 | OW_6_20160228,13.75,USD,1,,14400 8 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to partridge's documentation! 2 | ====================================== 3 | 4 | Contents: 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | readme 10 | installation 11 | usage 12 | modules 13 | contributing 14 | history 15 | 16 | Indices and tables 17 | ================== 18 | 19 | * :ref:`genindex` 20 | * :ref:`modindex` 21 | * :ref:`search` 22 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 4 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | charset = utf-8 11 | end_of_line = lf 12 | 13 | [*.bat] 14 | indent_style = tab 15 | end_of_line = crlf 16 | 17 | [LICENSE] 18 | insert_final_newline = false 19 | 20 | [Makefile] 21 | indent_style = tab 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * partridge version: 2 | * Python version: 3 | * Operating System: 4 | 5 | ### Description 6 | 7 | Describe what you were trying to get done. 8 | Tell us what happened, what went wrong, and what you expected to happen. 9 | 10 | ### What I Did 11 | 12 | ``` 13 | Paste the command(s) you ran and the output. 14 | If there was a crash, please include the traceback here. 15 | ``` 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | # This file will be regenerated if you run travis_pypi_setup.py 3 | 4 | language: python 5 | python: 6 | - 3.6 7 | 8 | # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors 9 | install: python setup.py install && pip install -U black flake8 mypy geopandas 10 | 11 | # command to run tests, e.g. python setup.py test 12 | script: make test 13 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/directions.txt: -------------------------------------------------------------------------------- 1 | route_id,direction_id,direction 2 | Lo-129,0,North 3 | Bu-129,0,North 4 | Lo-129,1,South 5 | Bu-129,1,South 6 | TaSj-129,0,North 7 | TaSj-129,1,South 8 | Lo-129,0,North 9 | Lo-129,1,South 10 | Bu-129,0,North 11 | Bu-129,1,South 12 | TaSj-129,0,North 13 | TaSj-129,1,South 14 | Bu-129,0,North 15 | Bu-129,1,South 16 | Li-129,0,North 17 | Li-129,1,South 18 | Lo-129,1,South 19 | Lo-129,0,North 20 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/directions.txt: -------------------------------------------------------------------------------- 1 | route_id,direction_id,direction 2 | Lo-129,0,North 3 | Bu-129,0,North 4 | Lo-129,1,South 5 | Bu-129,1,South 6 | TaSj-129,0,North 7 | TaSj-129,1,South 8 | Lo-129,0,North 9 | Lo-129,1,South 10 | Bu-129,0,North 11 | Bu-129,1,South 12 | TaSj-129,0,North 13 | TaSj-129,1,South 14 | Bu-129,0,North 15 | Bu-129,1,South 16 | Li-129,0,North 17 | Li-129,1,South 18 | Lo-129,1,South 19 | Lo-129,0,North 20 | -------------------------------------------------------------------------------- /tests/helpers.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | 5 | fixtures_dir = os.path.join(os.path.dirname(__file__), "fixtures") 6 | 7 | 8 | def fixture(filename): 9 | """ 10 | Get the handle / path to the test data folder. 11 | """ 12 | return os.path.join(fixtures_dir, filename) 13 | 14 | 15 | def zip_file(scenario): 16 | """ 17 | Get the file handle / path to the zip file. 18 | """ 19 | scenario_dir = os.path.join(fixtures_dir, scenario) 20 | return shutil.make_archive(scenario_dir, "zip", scenario_dir) 21 | -------------------------------------------------------------------------------- /tests/fixtures/seattle-area-2017-11-16/calendar.txt: -------------------------------------------------------------------------------- 1 | service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date 2 | 86972,0,1,1,0,1,0,0,20171120,20180309 3 | 85068,0,1,1,0,0,0,0,20171120,20180309 4 | 71310,0,1,1,0,0,0,0,20171120,20180308 5 | 18623,0,0,0,0,0,0,1,20171119,20180304 6 | 17730,0,0,0,0,0,0,1,20171119,20180304 7 | 17133,0,0,0,0,0,1,0,20171118,20180303 8 | 16001,0,0,0,0,0,0,1,20171119,20180304 9 | 15662,0,0,0,0,1,0,0,20171201,20180309 10 | 14336,0,0,0,0,0,1,0,20171118,20180303 11 | 893,0,0,0,0,0,0,0,20180115,20180219 12 | -------------------------------------------------------------------------------- /tests/fixtures/seattle-area-2017-11-16/agency.txt: -------------------------------------------------------------------------------- 1 | agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url 2 | ST,Sound Transit,http://www.soundtransit.org/,America/Los_Angeles,EN,1-888-889-6368,http://www.soundtransit.org/Fares-and-Passes.xml 3 | KMD,Kingcounty Marine Divison,http://www.kingcounty.gov/transportation/kcdot/Marine.aspx,America/Los_Angeles,EN,206-684-1515,http://www.kingcounty.gov/transportation/kcdot/Marine.aspx/ 4 | EOS,City of Seattle,http://www.seattle.gov,America/Los_Angeles,EN,206-684-7623,http://www.seattlestreetcar.org/ 5 | -------------------------------------------------------------------------------- /partridge/__init__.py: -------------------------------------------------------------------------------- 1 | from .__version__ import __version__ 2 | from .readers import ( 3 | load_feed, 4 | load_geo_feed, 5 | load_raw_feed, 6 | read_busiest_date, 7 | read_busiest_week, 8 | read_service_ids_by_date, 9 | read_dates_by_service_ids, 10 | read_trip_counts_by_date, 11 | ) 12 | from .writers import extract_feed 13 | 14 | 15 | __all__ = [ 16 | "__version__", 17 | "extract_feed", 18 | "load_feed", 19 | "load_geo_feed", 20 | "load_raw_feed", 21 | "read_busiest_date", 22 | "read_busiest_week", 23 | "read_service_ids_by_date", 24 | "read_dates_by_service_ids", 25 | "read_trip_counts_by_date", 26 | ] 27 | -------------------------------------------------------------------------------- /tests/fixtures/trimet-vermont-2018-02-06/transfers.txt: -------------------------------------------------------------------------------- 1 | from_stop_id,to_stop_id,transfer_type 2 | 172,172,0 3 | 172,173,0 4 | 173,172,0 5 | 173,173,0 6 | 191,191,0 7 | 191,193,0 8 | 193,191,0 9 | 193,193,0 10 | 199,199,0 11 | 199,11211,0 12 | 654,7588,0 13 | 965,965,0 14 | 965,966,0 15 | 966,965,0 16 | 966,966,0 17 | 7588,7588,0 18 | 7591,7591,0 19 | 7612,7612,0 20 | 7612,7765,0 21 | 7616,7616,0 22 | 7625,7625,0 23 | 7631,7631,0 24 | 7631,7782,0 25 | 7765,7612,0 26 | 7765,7765,0 27 | 7772,7772,0 28 | 7782,7631,0 29 | 7782,7782,0 30 | 7782,13170,0 31 | 7807,7807,0 32 | 9033,1051,0 33 | 9033,9033,0 34 | 10491,10491,0 35 | 11211,199,0 36 | 11211,11211,0 37 | 13170,7782,0 38 | 13170,13170,0 39 | -------------------------------------------------------------------------------- /partridge/parsers.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | from functools import lru_cache 3 | import numpy as np 4 | 5 | DATE_FORMAT = "%Y%m%d" 6 | 7 | 8 | # Why 2^17? See https://git.io/vxB2P. 9 | @lru_cache(maxsize=2 ** 17) 10 | def parse_time(val: str) -> np.float64: 11 | if val is np.nan: 12 | return val 13 | 14 | val = val.strip() 15 | 16 | if val == "": 17 | return np.nan 18 | 19 | h, m, s = val.split(":") 20 | ssm = int(h) * 3600 + int(m) * 60 + int(s) 21 | 22 | # pandas doesn't have a NaN int, use floats 23 | return np.float64(ssm) 24 | 25 | 26 | def parse_date(val: str) -> datetime.date: 27 | return datetime.datetime.strptime(val, DATE_FORMAT).date() 28 | 29 | 30 | vparse_date = np.vectorize(parse_date) 31 | vparse_time = np.vectorize(parse_time) 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | MIT License 3 | 4 | Copyright (c) 2017, Remix 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | tests/fixtures/*.zip 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | 56 | # Sphinx documentation 57 | docs/_build/ 58 | 59 | # PyBuilder 60 | target/ 61 | 62 | # pyenv python configuration file 63 | .python-version 64 | 65 | # virtual environment 66 | venv/ 67 | .venv/ 68 | 69 | scratch/ 70 | .DS_Store 71 | .pytest_cache 72 | .ipynb_checkpoints/* 73 | *.ipynb 74 | .mypy_cache 75 | -------------------------------------------------------------------------------- /partridge/geo.py: -------------------------------------------------------------------------------- 1 | from typing import Dict, List 2 | 3 | import pandas as pd 4 | 5 | try: 6 | import geopandas as gpd 7 | from shapely.geometry import LineString, Point 8 | except ImportError as impexc: 9 | print(impexc) 10 | print("You must install GeoPandas to use this module.") 11 | raise 12 | 13 | 14 | DEFAULT_CRS = {"init": "EPSG:4326"} 15 | 16 | 17 | def build_shapes(df: pd.DataFrame) -> gpd.GeoDataFrame: 18 | if df.empty: 19 | return gpd.GeoDataFrame({"shape_id": [], "geometry": []}, crs=DEFAULT_CRS) 20 | 21 | data: Dict[str, List] = {"shape_id": [], "geometry": []} 22 | for shape_id, shape in df.sort_values("shape_pt_sequence").groupby("shape_id"): 23 | data["shape_id"].append(shape_id) 24 | data["geometry"].append( 25 | LineString(list(zip(shape.shape_pt_lon, shape.shape_pt_lat))) 26 | ) 27 | 28 | return gpd.GeoDataFrame(data, crs=DEFAULT_CRS) 29 | 30 | 31 | def build_stops(df: pd.DataFrame) -> gpd.GeoDataFrame: 32 | if df.empty: 33 | return gpd.GeoDataFrame(df, geometry=[], crs=DEFAULT_CRS) 34 | 35 | df["geometry"] = df.apply(lambda s: Point(s.stop_lon, s.stop_lat), axis=1) 36 | 37 | df.drop(["stop_lon", "stop_lat"], axis=1, inplace=True) 38 | 39 | return gpd.GeoDataFrame(df, crs={"init": "EPSG:4326"}) 40 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: shell 2 | 3 | ============ 4 | Installation 5 | ============ 6 | 7 | 8 | Stable release 9 | -------------- 10 | 11 | To install partridge, run this command in your terminal: 12 | 13 | .. code-block:: console 14 | 15 | $ pip install partridge 16 | 17 | This is the preferred method to install partridge, as it will always install the most recent stable release. 18 | 19 | If you don't have `pip`_ installed, this `Python installation guide`_ can guide 20 | you through the process. 21 | 22 | .. _pip: https://pip.pypa.io 23 | .. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/ 24 | 25 | 26 | From sources 27 | ------------ 28 | 29 | The sources for partridge can be downloaded from the `Github repo`_. 30 | 31 | You can either clone the public repository: 32 | 33 | .. code-block:: console 34 | 35 | $ git clone git://github.com/remix/partridge 36 | 37 | Or download the `tarball`_: 38 | 39 | .. code-block:: console 40 | 41 | $ curl -OL https://github.com/remix/partridge/tarball/master 42 | 43 | Once you have a copy of the source, you can install it with: 44 | 45 | .. code-block:: console 46 | 47 | $ python setup.py install 48 | 49 | 50 | .. _Github repo: https://github.com/remix/partridge 51 | .. _tarball: https://github.com/remix/partridge/tarball/master 52 | -------------------------------------------------------------------------------- /.github/workflows/python-package.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python 3 | 4 | name: Python package 5 | 6 | on: 7 | push: 8 | branches: [ "master" ] 9 | pull_request: 10 | branches: [ "master" ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | python-version: ["3.8", "3.9", "3.10", "3.11"] 20 | 21 | steps: 22 | - uses: actions/checkout@v3 23 | - name: Set up Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@v3 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | - name: Install dependencies 28 | run: | 29 | python -m pip install --upgrade pip 30 | python -m pip install flake8 pytest 31 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 32 | - name: Lint with flake8 33 | run: | 34 | # stop the build if there are Python syntax errors or undefined names 35 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 36 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 37 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 38 | - name: Test with pytest 39 | run: | 40 | pytest 41 | -------------------------------------------------------------------------------- /RELEASING.rst: -------------------------------------------------------------------------------- 1 | ======================== 2 | Publishing a new release 3 | ======================== 4 | 5 | Based on https://packaging.python.org/en/latest/tutorials/packaging-projects 6 | 7 | Prerequisites 8 | ~~~~~~~~~~~~~ 9 | 10 | * Update ``HISTORY.rst`` 11 | * Tag Git release, e.g.:: 12 | 13 | $ git tag v1.2.3 14 | $ git push --tags 15 | 16 | * If needed, create an account on TestPyPI: https://test.pypi.org/account/register/ 17 | * Generate a test API token: https://test.pypi.org/manage/account/token/ 18 | * Generate a real API token: https://pypi.org/manage/account/token/ 19 | * Install deployment tools:: 20 | 21 | $ pip install --upgrade build twine 22 | 23 | Process 24 | ~~~~~~~ 25 | 26 | * Build the package:: 27 | 28 | $ python -m build 29 | 30 | * Check package validity (optional):: 31 | 32 | $ python -m twine check dist/* 33 | 34 | * Upload the package to TestPyPI (username is ``__token__``, password is your API token):: 35 | 36 | $ python -m twine upload --repository testpypi dist/* 37 | 38 | * Verify the test release can be installed:: 39 | 40 | $ python -m venv testing 41 | $ testing/bin/pip install --index-url https://test.pypi.org/simple/ --no-deps partridge== 42 | 43 | Note: we use ``--no-deps`` because not all dependencies are present in 44 | TestPyPI. For more comprehensive testing, manually install deps from the real 45 | PyPI. 46 | 47 | * Upload the package to PyPI (username is ``__token__``, password is your API token):: 48 | 49 | $ python -m twine upload dist/* 50 | -------------------------------------------------------------------------------- /tests/test_parsers.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import numpy as np 3 | import pytest 4 | 5 | from partridge.parsers import parse_time, parse_date, vparse_time, vparse_date 6 | 7 | 8 | def test_parse_date(): 9 | assert parse_date("20990101") == datetime.date(2099, 1, 1) 10 | 11 | 12 | def test_parse_date_with_invalid_month(): 13 | with pytest.raises(ValueError, match=r"unconverted data remains: 01"): 14 | parse_date("20991401") 15 | 16 | 17 | def test_parse_date_with_invalid_day(): 18 | with pytest.raises(ValueError, match=r"unconverted data remains: 3"): 19 | parse_date("20990133") 20 | 21 | 22 | def test_vparse_date(): 23 | datestrs = ["20990101", "20990102"] 24 | dateobjs = [datetime.date(2099, 1, 1), datetime.date(2099, 1, 2)] 25 | 26 | assert np.array_equal(vparse_date(np.array(datestrs)), dateobjs) 27 | 28 | 29 | def test_parse_time(): 30 | assert parse_time(np.nan) is np.nan 31 | assert parse_time("") is np.nan 32 | assert parse_time(" ") is np.nan 33 | assert parse_time("00:00:00") == 0 34 | assert parse_time("0:00:00") == 0 35 | assert parse_time("01:02:03") == 3723 36 | assert parse_time("1:02:03") == 3723 37 | assert parse_time("25:24:23") == 91463 38 | assert parse_time("250:24:23") == 901463 39 | 40 | 41 | def test_parse_time_with_invalid_input(): 42 | with pytest.raises(ValueError, match=r"invalid literal for int()"): 43 | parse_time("10:15:00am") 44 | 45 | 46 | def test_vparse_time(): 47 | timestrs = ["00:00:00", "250:24:23"] 48 | timeints = [0, 901463] 49 | 50 | assert np.array_equal(vparse_time(np.array(timestrs)), timeints) 51 | -------------------------------------------------------------------------------- /tests/fixtures/seattle-area-2017-11-16/routes.txt: -------------------------------------------------------------------------------- 1 | route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color 2 | 100232,ST,522,,Woodinville - Seattle,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/522,, 3 | 100235,ST,540,,Kirkland - University District,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/540,, 4 | 100236,ST,545,,Redmond - Seattle,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/545,, 5 | 100239,ST,550,,Bellevue - Seattle,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/550,, 6 | 100240,ST,554,,Issaquah - Seattle,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/554,, 7 | 100241,ST,555,,Issaquah - Northgate,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/555,, 8 | 100336,KMD,973,,Water Taxi: West Seattle - Downtown Seattle,4,http://www.kingcounty.gov/transportation/kcdot/WaterTaxi.aspx,, 9 | 100337,KMD,975,,Water Taxi: Vashon Island - Downtown Seattle,4,http://www.kingcounty.gov/transportation/kcdot/WaterTaxi.aspx,, 10 | 100340,EOS,South Lake Union Streetcar,,Streetcar: Fairview/Aloha - Westlake/McGraw,0,http://www.seattlestreetcar.org/slu.htm,, 11 | 100451,ST,556,,Issaquah - University District - Northgate,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/556,, 12 | 100479,ST,Link,,LINK: Sea Tac - Dowtown Seattle - UW/Husky Stadium,0,http://www.soundtransit.org/Schedules/ST-Express-Bus/599,, 13 | 100511,ST,542,,Redmond - University District,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/542,, 14 | 102638,EOS,First Hill Streetcar,,Streetcar: Pioneer Square - Capital Hill,0,http://www.seattlestreetcar.org/slu.htm,, 15 | 102640,ST,541,,Overlake P&R - University District,3,http://www.soundtransit.org/Schedules/ST-Express-Bus/541,, 16 | -------------------------------------------------------------------------------- /partridge/writers.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | import tempfile 4 | from multiprocessing.pool import ThreadPool 5 | from typing import Collection, Optional 6 | 7 | import networkx as nx 8 | 9 | from .config import default_config 10 | from .gtfs import Feed 11 | from .readers import load_feed 12 | from .types import View 13 | from .utilities import remove_node_attributes 14 | 15 | 16 | DEFAULT_NODES = frozenset(default_config().nodes()) 17 | 18 | 19 | def extract_feed( 20 | inpath: str, outpath: str, view: View, config: nx.DiGraph = None 21 | ) -> str: 22 | """Extract a subset of a GTFS zip into a new file""" 23 | config = default_config() if config is None else config 24 | config = remove_node_attributes(config, "converters") 25 | feed = load_feed(inpath, view, config) 26 | return write_feed_dangerously(feed, outpath) 27 | 28 | 29 | def write_feed_dangerously( 30 | feed: Feed, outpath: str, nodes: Optional[Collection[str]] = None 31 | ) -> str: 32 | """Naively write a feed to a zipfile 33 | 34 | This function provides no sanity checks. Use it at 35 | your own risk. 36 | """ 37 | nodes = DEFAULT_NODES if nodes is None else nodes 38 | with tempfile.TemporaryDirectory() as tmpdir: 39 | 40 | def write_node(node): 41 | df = feed.get(node) 42 | if not df.empty: 43 | path = os.path.join(tmpdir, node) 44 | df.to_csv(path, index=False) 45 | 46 | pool = ThreadPool(len(nodes)) 47 | try: 48 | pool.map(write_node, nodes) 49 | finally: 50 | pool.terminate() 51 | 52 | if outpath.endswith(".zip"): 53 | outpath, _ = os.path.splitext(outpath) 54 | 55 | outpath = shutil.make_archive(outpath, "zip", tmpdir) 56 | 57 | return outpath 58 | -------------------------------------------------------------------------------- /dependency-graph.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | dpi=200; 3 | rankdir=BT; 4 | "agency.txt"; 5 | "stops.txt"; 6 | subgraph { 7 | rank="same"; 8 | "trips.txt"; 9 | } 10 | subgraph { 11 | rank="same"; 12 | "calendar.txt"; 13 | "calendar_dates.txt"; 14 | "stop_times.txt"; 15 | "frequencies.txt"; 16 | "shapes.txt"; 17 | "routes.txt"; 18 | } 19 | subgraph { 20 | rank="same"; 21 | "fare_rules.txt"; 22 | "transfers.txt"; 23 | } 24 | "fare_attributes.txt"; 25 | "agency.txt" -> "routes.txt" [key=0, label="routes.agency_id\nagency.agency_id"]; 26 | "routes.txt" -> "trips.txt" [key=0, label="trips.route_id\nroutes.route_id"]; 27 | "calendar.txt" -> "trips.txt" [key=0, label="trips.service_id\ncalendar.service_id"]; 28 | "calendar_dates.txt" -> "trips.txt" [key=0, label="trips.service_id\ncalendar_dates.service_id"]; 29 | "fare_attributes.txt" -> "fare_rules.txt" [key=0, label="fare_rules.fare_id\nfare_attributes.fare_id"]; 30 | "fare_rules.txt" -> "stops.txt" [key=0, label="stops.zone_id\nfare_rules.origin_id"]; 31 | "fare_rules.txt" -> "stops.txt" [key=1, label="stops.zone_id\nfare_rules.destination_id"]; 32 | "fare_rules.txt" -> "stops.txt" [key=2, label="stops.zone_id\nfare_rules.contains_id"]; 33 | "fare_rules.txt" -> "routes.txt" [key=0, label="routes.route_id\nfare_rules.route_id"]; 34 | "stops.txt" -> "stop_times.txt" [key=0, label="stop_times.stop_id\nstops.stop_id"]; 35 | "stop_times.txt" -> "trips.txt" [key=0, label="trips.trip_id\nstop_times.trip_id"]; 36 | "frequencies.txt" -> "trips.txt" [key=0, label="trips.trip_id\nfrequencies.trip_id"]; 37 | "shapes.txt" -> "trips.txt" [key=0, label="trips.shape_id\nshapes.shape_id"]; 38 | "transfers.txt" -> "stops.txt" [key=0, label="stops.stop_id\ntransfers.from_stop_id"]; 39 | "transfers.txt" -> "stops.txt" [key=1, label="stops.stop_id\ntransfers.to_stop_id"]; 40 | } 41 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/stop_attributes.txt: -------------------------------------------------------------------------------- 1 | stop_id,accessibility_id,cardinal_direction,relative_position,stop_city 2 | 70011,2,EA,,San Francisco 3 | 70012,2,WE,,San Francisco 4 | 70021,2,EA,,San Francisco 5 | 70022,2,WE,,San Francisco 6 | 70031,2,EA,,San Francisco 7 | 70032,2,WE,,San Francisco 8 | 70041,2,EA,,South San Francisco 9 | 70042,2,WE,,South San Francisco 10 | 70051,2,EA,,San Bruno 11 | 70052,2,WE,,San Bruno 12 | 70061,2,EA,,Millbrae 13 | 70062,2,WE,,Millbrae 14 | 70071,2,EA,,Burlingame 15 | 70072,2,WE,,Burlingame 16 | 70081,2,EA,,Burlingame 17 | 70082,2,WE,,Burlingame 18 | 70091,2,EA,,San Mateo 19 | 70092,2,WE,,San Mateo 20 | 70101,2,EA,,San Mateo 21 | 70102,2,WE,,San Mateo 22 | 70111,2,EA,,San Mateo 23 | 70112,2,WE,,San Mateo 24 | 70121,2,EA,,Belmont 25 | 70122,2,WE,,Belmont 26 | 70131,2,EA,,San Carlos 27 | 70132,2,WE,,San Carlos 28 | 70141,2,EA,,Redwood City 29 | 70142,2,WE,,Redwood City 30 | 70151,2,EA,,Atherton 31 | 70152,2,WE,,Atherton 32 | 70161,2,EA,,Menlo Park 33 | 70162,2,WE,,Menlo Park 34 | 70171,2,EA,,Palo Alto 35 | 70172,2,WE,,Palo Alto 36 | 70191,2,EA,,Palo Alto 37 | 70192,2,WE,,Palo Alto 38 | 70201,2,EA,,Mountain View (Santa Clara) 39 | 70202,2,WE,,Mountain View (Santa Clara) 40 | 70211,2,EA,,Mountain View (Santa Clara) 41 | 70212,2,WE,,Mountain View (Santa Clara) 42 | 70221,2,EA,,Sunnyvale 43 | 70222,2,WE,,Sunnyvale 44 | 70231,2,EA,,Sunnyvale 45 | 70232,2,WE,,Sunnyvale 46 | 70241,2,EA,,Santa Clara 47 | 70242,2,WE,,Santa Clara 48 | 70251,2,EA,,San Jose 49 | 70252,2,WE,,San Jose 50 | 70261,2,EA,,San Jose 51 | 70262,2,WE,,San Jose 52 | 70271,2,EA,,San Jose 53 | 70272,2,WE,,San Jose 54 | 70281,2,EA,,San Jose 55 | 70282,2,WE,,San Jose 56 | 70291,2,EA,,San Jose 57 | 70292,2,WE,,San Jose 58 | 70301,2,EA,,Morgan Hill 59 | 70302,2,WE,,Morgan Hill 60 | 70311,2,EA,,San Martin 61 | 70312,2,WE,,San Martin 62 | 70321,2,EA,,Gilroy 63 | 70322,2,WE,,Gilroy 64 | 777402,2,,,San Jose 65 | 777403,2,,,San Jose 66 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/stop_attributes.txt: -------------------------------------------------------------------------------- 1 | stop_id,accessibility_id,cardinal_direction,relative_position,stop_city 2 | 70011,2,EA,,San Francisco 3 | 70012,2,WE,,San Francisco 4 | 70021,2,EA,,San Francisco 5 | 70022,2,WE,,San Francisco 6 | 70031,2,EA,,San Francisco 7 | 70032,2,WE,,San Francisco 8 | 70041,2,EA,,South San Francisco 9 | 70042,2,WE,,South San Francisco 10 | 70051,2,EA,,San Bruno 11 | 70052,2,WE,,San Bruno 12 | 70061,2,EA,,Millbrae 13 | 70062,2,WE,,Millbrae 14 | 70071,2,EA,,Burlingame 15 | 70072,2,WE,,Burlingame 16 | 70081,2,EA,,Burlingame 17 | 70082,2,WE,,Burlingame 18 | 70091,2,EA,,San Mateo 19 | 70092,2,WE,,San Mateo 20 | 70101,2,EA,,San Mateo 21 | 70102,2,WE,,San Mateo 22 | 70111,2,EA,,San Mateo 23 | 70112,2,WE,,San Mateo 24 | 70121,2,EA,,Belmont 25 | 70122,2,WE,,Belmont 26 | 70131,2,EA,,San Carlos 27 | 70132,2,WE,,San Carlos 28 | 70141,2,EA,,Redwood City 29 | 70142,2,WE,,Redwood City 30 | 70151,2,EA,,Atherton 31 | 70152,2,WE,,Atherton 32 | 70161,2,EA,,Menlo Park 33 | 70162,2,WE,,Menlo Park 34 | 70171,2,EA,,Palo Alto 35 | 70172,2,WE,,Palo Alto 36 | 70191,2,EA,,Palo Alto 37 | 70192,2,WE,,Palo Alto 38 | 70201,2,EA,,Mountain View (Santa Clara) 39 | 70202,2,WE,,Mountain View (Santa Clara) 40 | 70211,2,EA,,Mountain View (Santa Clara) 41 | 70212,2,WE,,Mountain View (Santa Clara) 42 | 70221,2,EA,,Sunnyvale 43 | 70222,2,WE,,Sunnyvale 44 | 70231,2,EA,,Sunnyvale 45 | 70232,2,WE,,Sunnyvale 46 | 70241,2,EA,,Santa Clara 47 | 70242,2,WE,,Santa Clara 48 | 70251,2,EA,,San Jose 49 | 70252,2,WE,,San Jose 50 | 70261,2,EA,,San Jose 51 | 70262,2,WE,,San Jose 52 | 70271,2,EA,,San Jose 53 | 70272,2,WE,,San Jose 54 | 70281,2,EA,,San Jose 55 | 70282,2,WE,,San Jose 56 | 70291,2,EA,,San Jose 57 | 70292,2,WE,,San Jose 58 | 70301,2,EA,,Morgan Hill 59 | 70302,2,WE,,Morgan Hill 60 | 70311,2,EA,,San Martin 61 | 70312,2,WE,,San Martin 62 | 70321,2,EA,,Gilroy 63 | 70322,2,WE,,Gilroy 64 | 777402,2,,,San Jose 65 | 777403,2,,,San Jose 66 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """The setup script.""" 5 | import io 6 | 7 | from setuptools import setup, find_packages 8 | 9 | with open("README.rst") as readme_file: 10 | readme = readme_file.read() 11 | 12 | with open("HISTORY.rst") as history_file: 13 | history = history_file.read() 14 | 15 | # About dict to store version and package info 16 | about = dict() 17 | with io.open("partridge/__version__.py", "r", encoding="utf-8") as f: 18 | exec(f.read(), about) 19 | 20 | requirements = [ 21 | "charset_normalizer", 22 | 'functools32;python_version<"3"', 23 | "networkx>=2.0", 24 | "pandas", 25 | "isoweek", 26 | ] 27 | 28 | setup_requirements = ["pytest-runner"] 29 | 30 | test_requirements = ["black", "flake8", "pytest"] 31 | 32 | setup( 33 | name="partridge", 34 | version=about["__version__"], 35 | description="Partridge is a python library for working with GTFS " 36 | "feeds using pandas DataFrames.", 37 | long_description=readme + "\n\n" + history, 38 | long_description_content_type="text/x-rst", 39 | author="Danny Whalen", 40 | author_email="daniel.r.whalen@gmail.com", 41 | url="https://github.com/remix/partridge", 42 | packages=find_packages(include=["partridge"]), 43 | include_package_data=True, 44 | install_requires=requirements, 45 | license="MIT license", 46 | zip_safe=False, 47 | keywords="partridge", 48 | classifiers=[ 49 | "Intended Audience :: Developers", 50 | "License :: OSI Approved :: MIT License", 51 | "Natural Language :: English", 52 | "Programming Language :: Python :: 3", 53 | "Programming Language :: Python :: 3.6", 54 | "Programming Language :: Python :: 3.7", 55 | ], 56 | python_requires=">=3.6, <4", 57 | test_suite="tests", 58 | tests_require=test_requirements, 59 | setup_requires=setup_requirements, 60 | extras_require={"full": ["geopandas"]}, 61 | ) 62 | -------------------------------------------------------------------------------- /partridge/utilities.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Dict, Iterable, Optional, Set, BinaryIO, Union 2 | 3 | from charset_normalizer import detect 4 | import networkx as nx 5 | import pandas as pd 6 | from pandas.core.common import flatten 7 | 8 | 9 | def setwrap(value: Any) -> Set[str]: 10 | """ 11 | Returns a flattened and stringified set from the given object or iterable. 12 | 13 | For use in public functions which accept argmuents or kwargs that can be 14 | one object or a list of objects. 15 | """ 16 | return set(map(str, set(flatten([value])))) 17 | 18 | 19 | def remove_node_attributes(G: nx.DiGraph, attributes: Union[str, Iterable[str]]): 20 | """ 21 | Return a copy of the graph with the given attributes 22 | deleted from all nodes. 23 | """ 24 | G = G.copy() 25 | for _, data in G.nodes(data=True): 26 | for attribute in setwrap(attributes): 27 | if attribute in data: 28 | del data[attribute] 29 | return G 30 | 31 | 32 | def detect_encoding(f: BinaryIO, limit: int = 2500) -> str: 33 | """ 34 | Return encoding of provided input stream. 35 | 36 | Most of the time it's unicode, but if we are unable to decode the input 37 | natively, use `chardet` to determine the encoding heuristically. 38 | """ 39 | unicode_decodable = True 40 | 41 | for line_no, line in enumerate(f): 42 | try: 43 | line.decode("utf-8") 44 | except UnicodeDecodeError: 45 | unicode_decodable = False 46 | break 47 | 48 | if line_no > limit: 49 | break 50 | 51 | if unicode_decodable: 52 | return "utf-8" 53 | 54 | f.seek(0) 55 | return detect(f.read())["encoding"] 56 | 57 | 58 | def empty_df(columns: Optional[Iterable[str]] = None) -> pd.DataFrame: 59 | columns = [] if columns is None else columns 60 | empty: Dict = {col: [] for col in columns} 61 | return pd.DataFrame(empty, columns=columns, dtype=str) 62 | -------------------------------------------------------------------------------- /tests/test_utilities.py: -------------------------------------------------------------------------------- 1 | import io 2 | import networkx as nx 3 | import pytest 4 | 5 | import pandas as pd 6 | from partridge.utilities import ( 7 | detect_encoding, 8 | empty_df, 9 | remove_node_attributes, 10 | setwrap, 11 | ) 12 | 13 | 14 | def test_setwrap(): 15 | assert setwrap("a") == {"a"} 16 | assert setwrap(["a"]) == {"a"} 17 | assert setwrap({"a"}) == {"a"} 18 | assert setwrap({1}) == {"1"} 19 | assert setwrap(1) == {"1"} 20 | 21 | 22 | def test_remove_node_attributes(): 23 | G = nx.Graph() 24 | G.add_node(1, label="foo", hello="world") 25 | G.add_node(2, label="bar", welcome=1) 26 | 27 | X = remove_node_attributes(G, "label") 28 | Y = remove_node_attributes(G, ["label", "welcome"]) 29 | 30 | assert G.nodes[1] == {"label": "foo", "hello": "world"} 31 | assert G.nodes[2] == {"label": "bar", "welcome": 1} 32 | 33 | assert id(X) != id(G) 34 | assert X.nodes[1] == {"hello": "world"} 35 | assert X.nodes[2] == {"welcome": 1} 36 | 37 | assert id(Y) != id(G) 38 | assert Y.nodes[1] == {"hello": "world"} 39 | assert Y.nodes[2] == {} 40 | 41 | 42 | def test_empty_df(): 43 | actual = empty_df(["foo", "bar"]) 44 | 45 | expected = pd.DataFrame( 46 | {"foo": [], "bar": []}, columns=["foo", "bar"], dtype=str 47 | ) 48 | 49 | assert actual.equals(expected) 50 | 51 | 52 | def test_detect_encoding(): 53 | # straight up ascii is a subset of unicode 54 | assert detect_encoding(io.BytesIO(b"abcde")) == "utf-8" 55 | 56 | # actual unicode 57 | assert detect_encoding(io.BytesIO(b"Eyjafjallaj\xc3\xb6kull")) == "utf-8" 58 | 59 | # non-unicode, ISO characterset 60 | # 61 | # (Note: we don't assert a specific characterset, because we don't want 62 | # tests to break as changes are made in charset-normalizer. See: 63 | # https://github.com/remix/partridge/pull/84) 64 | enc = detect_encoding(io.BytesIO(b"\xC4pple")) 65 | assert enc and enc != "utf-8" 66 | -------------------------------------------------------------------------------- /tests/fixtures/israel-public-transportation-route-2126/stops.txt: -------------------------------------------------------------------------------- 1 | stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,location_type,parent_station,zone_id 2 | 354,39269,ויצמן/הרצל,רחוב:שדרות חיים וייצמן 5 עיר: נתניה רציף: קומה:,32.328953,34.858496,0,,7400 3 | 356,39271,ויצמן/ששת הימים,רחוב:שדרות חיים וייצמן עיר: נתניה רציף: קומה:,32.331154,34.858841,0,,7400 4 | 366,39281,י.ח. ברנר/שד. חיים וייצמן,רחוב:שדרות חיים וייצמן 53 עיר: נתניה רציף: קומה:,32.334658,34.859208,0,,7400 5 | 368,39283,שדרות וייצמן/יהודה הנשיא,רחוב:שדרות חיים וייצמן עיר: נתניה רציף: קומה:,32.337669,34.859541,0,,7400 6 | 371,39286,וייצמן/איכילוב,רחוב:שדרות חיים וייצמן 95 עיר: נתניה רציף: קומה:,32.339836,34.859845,0,,7400 7 | 372,39287,הרב הרצוג/שדרות חיים וייצמן,רחוב:שדרות חיים וייצמן 109 עיר: נתניה רציף: קומה:,32.341324,34.860090,0,,7400 8 | 374,39289,בית הבאר/נחום סוקולוב,רחוב:נחום סוקולוב 19 עיר: נתניה רציף: קומה:,32.342087,34.860981,0,,7400 9 | 381,39296,בית חולים לניאדו,רחוב:הרב מיימון 4 עיר: נתניה רציף: קומה:,32.346220,34.857721,0,,7400 10 | 382,39297,הגדוד העברי/דברי חיים,רחוב:דברי חיים 47 עיר: נתניה רציף: קומה:,32.347980,34.857421,0,,7400 11 | 385,39300,הרב מיימון/מוריה,רחוב:הרב מיימון 30 עיר: נתניה רציף: קומה:,32.345629,34.860975,0,,7400 12 | 387,39302,הגפן\הגדוד העבר,רחוב:הגפן 3 עיר: נתניה רציף: קומה:,32.348002,34.861079,0,,7400 13 | 389,39304,הגפן/שד. עין התכלת,רחוב:הגפן 19 עיר: נתניה רציף: קומה:,32.349772,34.861387,0,,7400 14 | 396,39311,הגפן/השקד,רחוב:השקד 38 עיר: נתניה רציף: קומה:,32.351904,34.862728,0,,7400 15 | 599,39522,תחנה מרכזית נתניה/הורדה,רחוב:פינסקר עיר: נתניה רציף: קומה:,32.327128,34.858390,0,,7400 16 | 606,39529,הרימון/השיקמה,רחוב:השיקמה 8 עיר: נתניה רציף: קומה:,32.352174,34.865703,0,,7400 17 | 639,39566,הרימון/התמר,רחוב:הרימון 27 עיר: נתניה רציף: קומה:,32.352440,34.864109,0,,7400 18 | 724,39657,בלפור/קמיל הויסמנס,רחוב:קמיל הויסמנס 29 עיר: נתניה רציף: קומה:,32.344502,34.862316,0,,7400 19 | 25438,38544,בית גיל הזהב/השקד,רחוב:השקד 50 עיר: נתניה רציף: קומה:,32.352105,34.858411,0,,7400 20 | -------------------------------------------------------------------------------- /tests/fixtures/amazon-2017-08-06/stops.txt: -------------------------------------------------------------------------------- 1 | stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,stop_timezone,wheelchair_boarding 2 | 2567372,,"Otter (SEA55)","",47.616426,-122.343915,,,,,, 3 | 2557444,,"Arizona (SEA29)","",47.620072,-122.335861,,,,,, 4 | 2406032,,"Staples Lot","",47.760497,-122.175448,,,,,, 5 | 2409190,,"Overlake Church","",47.689037,-122.146506,,,,,, 6 | 2757445,64,"Lander Hall","",47.655997,-122.314686,,,,,, 7 | 2563031,,"7th & Pike","",47.612579,-122.334199,,,,,, 8 | 2403864,,"Sunset North","",47.580944,-122.15492,,,,,, 9 | 2403866,39,"Doppler (SEA40)","",47.614796,-122.338952,,,,,, 10 | 2567373,42,"Varzea (SEA30)","",47.618224,-122.338863,,,,,, 11 | 2557443,67,"Blackfoot (SEA33)","",47.615472,-122.33616,,,,,, 12 | 2557445,80,"Cricket (SEA20)","",47.62319,-122.336653,,,,,, 13 | 2558047,,"Houston/Roxanne (SEA49/SEA37)","",47.620866,-122.338076,,,,,, 14 | 2607247,22,"Spacelabs","",47.525875,-121.868758,,,,,, 15 | 2558190,,"Dawson (SEA27)","",47.62152,-122.335851,,,,,, 16 | 2558192,,"Apollo (SEA54)","",47.620873,-122.339988,,,,,, 17 | 2807676,72,"Island Synagogue","",47.5616304668264,-122.223718464375,,,,,, 18 | 2403865,70,"Brazil (SEA53)","",47.623196,-122.339679,,,,,, 19 | 2407509,,"Everest Building","",47.674322,-122.193489,,,,,, 20 | 2557442,,"TRB","",47.578869,-122.298606,,,,,, 21 | 2558046,,"Bus Tunnel/Train Station","",47.597505,-122.326342,,,,,, 22 | 2560318,30,"Prime (SEA36)","",47.6244756305297,-122.331718938658,,,,,, 23 | 2558182,,"Colman Dock","",47.603129,-122.337699,,,,,, 24 | 2563030,,"Convention Place","",47.613921,-122.331128,,,,,, 25 | 2560378,,"Galaxy (SEA69)","",47.625887,-122.367604,,,,,, 26 | 2411491,,"Sammamish Parking","",47.554438,-122.045893,,,,,, 27 | 2636558,36,"Everest","",47.614367,-122.199137,,,,,, 28 | 2558183,,"Coral (SEA68)","",47.615915,-122.343046,,,,,, 29 | 2560377,,"Alexandria (SEA18)","",47.616153,-122.335342,,,,,, 30 | 2558191,,"Brazil/Bigfoot/Nessie/Delight (SEA53/SEA38/SEA39/SEA59)","",47.623207,-122.339697,,,,,, 31 | 2567287,,"4th & Lenora","",47.613946,-122.341213,,,,,, 32 | 2562941,,"Mayday (SEA51)","",47.617327,-122.331394,,,,,, 33 | 2563400,,"6th & Union (WAC)","",47.610349,-122.333078,,,,,, 34 | 2562942,,"Kumo (SEA58)","",47.616615,-122.334097,,,,,, 35 | 2807677,73,"Boys & Girls Club","",47.5852225669064,-122.250044345856,,,,,, 36 | 2607248,23,"Eastridge Church","",47.557006,-122.015864,,,,,, 37 | -------------------------------------------------------------------------------- /tests/fixtures/trimet-vermont-2018-02-06/calendar_dates.txt: -------------------------------------------------------------------------------- 1 | service_id,date,exception_type 2 | unknown,20180601,1 3 | W.504,20180601,1 4 | W.504,20180531,1 5 | W.504,20180530,1 6 | W.504,20180529,1 7 | W.504,20180528,1 8 | W.504,20180525,1 9 | W.504,20180524,1 10 | W.504,20180523,1 11 | W.504,20180522,1 12 | W.504,20180521,1 13 | W.504,20180518,1 14 | W.504,20180517,1 15 | W.504,20180516,1 16 | W.504,20180515,1 17 | W.504,20180514,1 18 | W.504,20180511,1 19 | W.504,20180510,1 20 | W.504,20180509,1 21 | W.504,20180508,1 22 | W.504,20180507,1 23 | W.504,20180504,1 24 | W.504,20180503,1 25 | W.504,20180502,1 26 | W.504,20180501,1 27 | W.504,20180430,1 28 | W.504,20180427,1 29 | W.504,20180426,1 30 | W.504,20180425,1 31 | W.504,20180424,1 32 | W.504,20180423,1 33 | W.504,20180420,1 34 | W.504,20180419,1 35 | W.504,20180418,1 36 | W.504,20180417,1 37 | W.504,20180416,1 38 | W.504,20180413,1 39 | W.504,20180412,1 40 | W.504,20180411,1 41 | W.504,20180410,1 42 | W.504,20180409,1 43 | W.504,20180406,1 44 | W.504,20180405,1 45 | W.504,20180404,1 46 | W.504,20180403,1 47 | W.504,20180402,1 48 | W.504,20180330,1 49 | W.504,20180329,1 50 | W.504,20180328,1 51 | W.504,20180327,1 52 | W.504,20180326,1 53 | W.504,20180323,1 54 | W.504,20180322,1 55 | W.504,20180321,1 56 | W.504,20180320,1 57 | W.504,20180319,1 58 | W.504,20180316,1 59 | W.504,20180315,1 60 | W.504,20180314,1 61 | W.504,20180313,1 62 | W.504,20180312,1 63 | W.504,20180309,1 64 | W.504,20180308,1 65 | W.504,20180307,1 66 | W.504,20180306,1 67 | W.504,20180305,1 68 | W.507,20180302,1 69 | W.507,20180301,1 70 | W.507,20180228,1 71 | W.507,20180227,1 72 | W.507,20180226,1 73 | W.507,20180223,1 74 | W.507,20180222,1 75 | W.507,20180221,1 76 | W.507,20180220,1 77 | W.507,20180219,1 78 | W.507,20180216,1 79 | W.507,20180215,1 80 | W.507,20180214,1 81 | W.507,20180213,1 82 | W.507,20180212,1 83 | k.507,20180302,1 84 | k.507,20180301,1 85 | k.507,20180228,1 86 | k.507,20180227,1 87 | k.507,20180226,1 88 | k.507,20180223,1 89 | k.507,20180222,1 90 | k.507,20180221,1 91 | k.507,20180220,1 92 | k.507,20180216,1 93 | k.507,20180215,1 94 | k.507,20180214,1 95 | k.507,20180213,1 96 | k.507,20180212,1 97 | W.506,20180209,1 98 | W.506,20180208,1 99 | W.506,20180207,1 100 | W.506,20180206,1 101 | W.506,20180205,1 102 | W.506,20180202,1 103 | W.506,20180201,1 104 | W.506,20180131,1 105 | W.506,20180130,1 106 | W.506,20180129,1 107 | k.506,20180209,1 108 | k.506,20180208,1 109 | k.506,20180207,1 110 | k.506,20180206,1 111 | k.506,20180205,1 112 | k.506,20180202,1 113 | k.506,20180201,1 114 | k.506,20180131,1 115 | k.506,20180130,1 116 | -------------------------------------------------------------------------------- /tests/fixtures/trimet-vermont-2018-02-06/trips.txt: -------------------------------------------------------------------------------- 1 | route_id,service_id,trip_id,direction_id,block_id,shape_id,trip_type 2 | 1,W.504,7882446,1,103,358756, 3 | 1,W.504,7882445,1,102,358756, 4 | 1,W.504,7882444,1,101,358756, 5 | 1,W.504,7882443,1,103,358756, 6 | 1,W.504,7882442,1,102,358756, 7 | 1,W.504,7882441,1,102,358757, 8 | 1,W.504,7882440,1,101,358757, 9 | 1,W.504,7882439,1,103,358757, 10 | 1,W.504,7882438,1,102,358757, 11 | 1,W.504,7882437,1,101,358757, 12 | 1,W.504,7882436,1,104,358757, 13 | 1,W.504,7882435,1,103,358757, 14 | 1,W.504,7882434,1,102,358757, 15 | 1,W.504,7882433,1,101,358757, 16 | 1,W.504,7882432,0,103,358754, 17 | 1,W.504,7882431,0,102,358754, 18 | 1,W.504,7882430,0,101,358754, 19 | 1,W.504,7882429,0,103,358754, 20 | 1,W.504,7882428,0,102,358754, 21 | 1,W.504,7882427,0,6602,358754, 22 | 1,W.504,7882426,0,101,358754, 23 | 1,W.504,7882425,0,102,358755, 24 | 1,W.504,7882424,0,101,358755, 25 | 1,W.504,7882423,0,103,358755, 26 | 1,W.504,7882422,0,102,358755, 27 | 1,W.504,7882421,0,101,358755, 28 | 1,W.507,7943346,1,103,361829, 29 | 1,W.507,7943345,1,102,361829, 30 | 1,W.507,7943344,1,101,361829, 31 | 1,W.507,7943343,1,103,361829, 32 | 1,W.507,7943342,1,102,361829, 33 | 1,W.507,7943341,1,102,361830, 34 | 1,W.507,7943340,1,101,361830, 35 | 1,W.507,7943339,1,103,361830, 36 | 1,W.507,7943338,1,102,361830, 37 | 1,W.507,7943337,1,101,361830, 38 | 1,W.507,7943336,1,103,361830, 39 | 1,W.507,7943335,1,102,361830, 40 | 1,W.507,7943334,1,101,361830, 41 | 1,W.507,7943332,0,103,361826, 42 | 1,W.507,7943331,0,102,361826, 43 | 1,W.507,7943330,0,101,361826, 44 | 1,W.507,7943329,0,103,361826, 45 | 1,W.507,7943328,0,102,361826, 46 | 1,W.507,7943327,0,101,361828, 47 | 1,W.507,7943326,0,102,361827, 48 | 1,W.507,7943325,0,101,361827, 49 | 1,W.507,7943324,0,103,361827, 50 | 1,W.507,7943323,0,102,361827, 51 | 1,W.507,7943322,0,101,361827, 52 | 1,k.507,7943347,1,104,361830, 53 | 1,k.507,7943333,0,104,361828, 54 | 1,W.506,7925575,1,103,360811, 55 | 1,W.506,7925574,1,102,360811, 56 | 1,W.506,7925573,1,101,360811, 57 | 1,W.506,7925572,1,103,360811, 58 | 1,W.506,7925571,1,102,360811, 59 | 1,W.506,7925570,1,102,360812, 60 | 1,W.506,7925569,1,101,360812, 61 | 1,W.506,7925568,1,103,360812, 62 | 1,W.506,7925567,1,102,360812, 63 | 1,W.506,7925566,1,101,360812, 64 | 1,W.506,7925565,1,103,360812, 65 | 1,W.506,7925564,1,102,360812, 66 | 1,W.506,7925563,1,101,360812, 67 | 1,W.506,7925561,0,103,360808, 68 | 1,W.506,7925560,0,102,360808, 69 | 1,W.506,7925559,0,101,360808, 70 | 1,W.506,7925558,0,103,360808, 71 | 1,W.506,7925557,0,102,360808, 72 | 1,W.506,7925556,0,101,360810, 73 | 1,W.506,7925555,0,102,360809, 74 | 1,W.506,7925554,0,101,360809, 75 | 1,W.506,7925553,0,103,360809, 76 | 1,W.506,7925552,0,102,360809, 77 | 1,W.506,7925551,0,101,360809, 78 | 1,k.506,7925576,1,104,360812, 79 | 1,k.506,7925562,0,104,360810, 80 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean clean-test clean-pyc clean-build docs help 2 | .DEFAULT_GOAL := help 3 | define BROWSER_PYSCRIPT 4 | import os, webbrowser, sys 5 | try: 6 | from urllib import pathname2url 7 | except: 8 | from urllib.request import pathname2url 9 | 10 | webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) 11 | endef 12 | export BROWSER_PYSCRIPT 13 | 14 | define PRINT_HELP_PYSCRIPT 15 | import re, sys 16 | 17 | for line in sys.stdin: 18 | match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) 19 | if match: 20 | target, help = match.groups() 21 | print("%-20s %s" % (target, help)) 22 | endef 23 | export PRINT_HELP_PYSCRIPT 24 | BROWSER := python -c "$$BROWSER_PYSCRIPT" 25 | 26 | help: 27 | @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) 28 | 29 | clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts 30 | 31 | 32 | clean-build: ## remove build artifacts 33 | rm -fr build/ 34 | rm -fr dist/ 35 | rm -fr .eggs/ 36 | find . -name '*.egg-info' -exec rm -fr {} + 37 | find . -name '*.egg' -exec rm -fr {} + 38 | 39 | clean-pyc: ## remove Python file artifacts 40 | find . -name '*.pyc' -exec rm -f {} + 41 | find . -name '*.pyo' -exec rm -f {} + 42 | find . -name '*~' -exec rm -f {} + 43 | find . -name '__pycache__' -exec rm -fr {} + 44 | 45 | clean-test: ## remove test and coverage artifacts 46 | rm -fr .tox/ 47 | rm -f .coverage 48 | rm -fr htmlcov/ 49 | rm tests/fixtures/*.zip || true 50 | 51 | dependency-graph.png: 52 | dot -Tpng dependency-graph.dot -o dependency-graph.png 53 | 54 | dot: dependency-graph.png 55 | 56 | black: 57 | black partridge tests 58 | 59 | lint: ## check style with black 60 | black --check --diff partridge tests 61 | flake8 62 | 63 | type-check: 64 | mypy partridge --ignore-missing-imports 65 | 66 | ## run tests quickly with the default Python 67 | test: lint type-check 68 | py.test 69 | 70 | coverage: ## check code coverage quickly with the default Python 71 | coverage run --source partridge -m pytest 72 | coverage report -m 73 | coverage html 74 | $(BROWSER) htmlcov/index.html 75 | 76 | docs: ## generate Sphinx HTML documentation, including API docs 77 | rm -f docs/partridge.rst 78 | rm -f docs/modules.rst 79 | sphinx-apidoc -o docs/ partridge 80 | $(MAKE) -C docs clean 81 | $(MAKE) -C docs html 82 | $(BROWSER) docs/_build/html/index.html 83 | 84 | servedocs: docs ## compile the docs watching for changes 85 | watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . 86 | 87 | release: clean ## package and upload a release 88 | python setup.py sdist upload 89 | python setup.py bdist_wheel upload 90 | 91 | dist: clean ## builds source and wheel package 92 | python setup.py sdist 93 | python setup.py bdist_wheel 94 | ls -l dist 95 | 96 | install: clean ## install the package to the active Python's site-packages 97 | python setup.py install 98 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: shell 2 | 3 | ============ 4 | Contributing 5 | ============ 6 | 7 | Contributions are welcome, and they are greatly appreciated! Every 8 | little bit helps, and credit will always be given. 9 | 10 | You can contribute in many ways: 11 | 12 | Types of Contributions 13 | ---------------------- 14 | 15 | Report Bugs 16 | ~~~~~~~~~~~ 17 | 18 | Report bugs at https://github.com/remix/partridge/issues. 19 | 20 | If you are reporting a bug, please include: 21 | 22 | * Your operating system name and version. 23 | * Any details about your local setup that might be helpful in troubleshooting. 24 | * Detailed steps to reproduce the bug. 25 | 26 | Fix Bugs 27 | ~~~~~~~~ 28 | 29 | Look through the GitHub issues for bugs. Anything tagged with "bug" 30 | and "help wanted" is open to whoever wants to implement it. 31 | 32 | Implement Features 33 | ~~~~~~~~~~~~~~~~~~ 34 | 35 | Look through the GitHub issues for features. Anything tagged with "enhancement" 36 | and "help wanted" is open to whoever wants to implement it. 37 | 38 | Write Documentation 39 | ~~~~~~~~~~~~~~~~~~~ 40 | 41 | partridge could always use more documentation, whether as part of the 42 | official partridge docs, in docstrings, or even on the web in blog posts, 43 | articles, and such. 44 | 45 | Submit Feedback 46 | ~~~~~~~~~~~~~~~ 47 | 48 | The best way to send feedback is to file an issue at https://github.com/remix/partridge/issues. 49 | 50 | If you are proposing a feature: 51 | 52 | * Explain in detail how it would work. 53 | * Keep the scope as narrow as possible, to make it easier to implement. 54 | * Remember that this is a volunteer-driven project, and that contributions 55 | are welcome :) 56 | 57 | Get Started! 58 | ------------ 59 | 60 | Ready to contribute? Here's how to set up `partridge` for local development. 61 | 62 | 1. Fork the `partridge` repo on GitHub. 63 | 2. Clone your fork locally:: 64 | 65 | $ git clone git@github.com:your_name_here/partridge.git 66 | 67 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 68 | 69 | $ mkvirtualenv partridge 70 | $ cd partridge/ 71 | $ python setup.py develop 72 | 73 | 4. Create a branch for local development:: 74 | 75 | $ git checkout -b name-of-your-bugfix-or-feature 76 | 77 | Now you can make your changes locally. 78 | 79 | 5. When you're done making changes, check that your changes pass flake8 and the tests:: 80 | 81 | $ flake8 partridge tests 82 | $ python setup.py test or py.test 83 | $ tox 84 | 85 | To get flake8, just pip install it into your virtualenv. 86 | 87 | 6. Commit your changes and push your branch to GitHub:: 88 | 89 | $ git add . 90 | $ git commit -m "Your detailed description of your changes." 91 | $ git push origin name-of-your-bugfix-or-feature 92 | 93 | 7. Submit a pull request through the GitHub website. 94 | 95 | Pull Request Guidelines 96 | ----------------------- 97 | 98 | Before you submit a pull request, check that it meets these guidelines: 99 | 100 | 1. The pull request should include tests. 101 | 2. If the pull request adds functionality, the docs should be updated. Put 102 | your new functionality into a function with a docstring, and add the 103 | feature to the list in README.rst. 104 | 3. The pull request should work for Python 3.6+. Check 105 | https://travis-ci.org/remix/partridge/pull_requests 106 | and make sure that the tests pass for all supported Python versions. 107 | 108 | Tips 109 | ---- 110 | 111 | To run a subset of tests:: 112 | 113 | $ py.test tests.test_feed 114 | 115 | -------------------------------------------------------------------------------- /tests/test_writers.py: -------------------------------------------------------------------------------- 1 | import os 2 | import tempfile 3 | 4 | import partridge as ptg 5 | import pytest 6 | 7 | from .helpers import fixture, zip_file 8 | 9 | 10 | @pytest.mark.parametrize( 11 | "path", [zip_file("seattle-area-2017-11-16"), fixture("seattle-area-2017-11-16")] 12 | ) 13 | def test_extract_agencies(path): 14 | fd = ptg.load_feed(path) 15 | 16 | agencies = fd.agency 17 | assert len(agencies) == 3 18 | 19 | routes = fd.routes 20 | assert len(routes) == 14 21 | 22 | agency_ids = [agencies.iloc[0].agency_id] 23 | route_ids = set(fd.routes[fd.routes.agency_id.isin(agency_ids)].route_id) 24 | trip_ids = set(fd.trips[fd.trips.route_id.isin(route_ids)].trip_id) 25 | stop_ids = set(fd.stop_times[fd.stop_times.trip_id.isin(trip_ids)].stop_id) 26 | 27 | assert len(route_ids) 28 | assert len(trip_ids) 29 | assert len(stop_ids) 30 | 31 | with tempfile.TemporaryDirectory() as tmpdir: 32 | outfile = os.path.join(tmpdir, "test.zip") 33 | 34 | result = ptg.extract_feed( 35 | path, outfile, {"routes.txt": {"agency_id": agency_ids}} 36 | ) 37 | assert result == outfile 38 | 39 | new_fd = ptg.load_feed(outfile) 40 | assert list(new_fd.agency.agency_id) == agency_ids 41 | assert set(new_fd.routes.route_id) == route_ids 42 | assert set(new_fd.trips.trip_id) == trip_ids 43 | assert set(new_fd.stop_times.trip_id) == trip_ids 44 | assert set(new_fd.stops.stop_id) == stop_ids 45 | 46 | nodes = [] 47 | for node in fd._config.nodes(): 48 | df = fd.get(node) 49 | if not df.empty: 50 | nodes.append(node) 51 | 52 | assert len(nodes) 53 | 54 | for node in nodes: 55 | original_df = fd.get(node) 56 | new_df = new_fd.get(node) 57 | assert set(original_df.columns) == set(new_df.columns) 58 | 59 | 60 | @pytest.mark.parametrize( 61 | "path", [zip_file("seattle-area-2017-11-16"), fixture("seattle-area-2017-11-16")] 62 | ) 63 | def test_extract_routes(path): 64 | fd = ptg.load_feed(path) 65 | 66 | agencies = fd.agency 67 | assert len(agencies) == 3 68 | 69 | routes = fd.routes 70 | assert len(routes) == 14 71 | 72 | route_ids = [routes.iloc[0].route_id] 73 | agency_ids = set(fd.routes[fd.routes.route_id.isin(route_ids)].agency_id) 74 | trip_ids = set(fd.trips[fd.trips.route_id.isin(route_ids)].trip_id) 75 | stop_ids = set(fd.stop_times[fd.stop_times.trip_id.isin(trip_ids)].stop_id) 76 | 77 | assert len(agency_ids) 78 | assert len(trip_ids) 79 | assert len(stop_ids) 80 | 81 | with tempfile.TemporaryDirectory() as tmpdir: 82 | outfile = os.path.join(tmpdir, "test.zip") 83 | 84 | result = ptg.extract_feed(path, outfile, {"trips.txt": {"route_id": route_ids}}) 85 | assert result == outfile 86 | 87 | new_fd = ptg.load_feed(outfile) 88 | assert list(new_fd.routes.route_id) == route_ids 89 | assert set(new_fd.agency.agency_id) == agency_ids 90 | assert set(new_fd.trips.trip_id) == trip_ids 91 | assert set(new_fd.stop_times.trip_id) == trip_ids 92 | assert set(new_fd.stops.stop_id) == stop_ids 93 | 94 | nodes = [] 95 | for node in fd._config.nodes(): 96 | df = fd.get(node) 97 | if not df.empty: 98 | nodes.append(node) 99 | 100 | assert len(nodes) 101 | 102 | for node in nodes: 103 | original_df = fd.get(node) 104 | new_df = new_fd.get(node) 105 | assert set(original_df.columns) == set(new_df.columns) 106 | -------------------------------------------------------------------------------- /tests/fixtures/israel-public-transportation-route-2126/stop_times.txt: -------------------------------------------------------------------------------- 1 | trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_type,shape_dist_traveled 2 | 435227_230218,05:10:00,05:10:00,606,1,0,1,0 3 | 435227_230218,05:10:56,05:10:56,639,2,0,0,164 4 | 435227_230218,05:11:41,05:11:41,396,3,0,0,351 5 | 435227_230218,05:13:20,05:13:20,25438,4,0,0,764 6 | 435227_230218,05:16:03,05:16:03,389,5,0,0,1444 7 | 435227_230218,05:16:51,05:16:51,387,6,0,0,1642 8 | 435227_230218,05:17:46,05:17:46,382,7,0,0,2069 9 | 435227_230218,05:19:00,05:19:00,381,8,0,0,2338 10 | 435227_230218,05:20:18,05:20:18,385,9,0,0,2663 11 | 435227_230218,05:21:10,05:21:10,724,10,0,0,2880 12 | 435227_230218,05:22:44,05:22:44,374,11,0,0,3262 13 | 435227_230218,05:23:18,05:23:18,372,12,0,0,3420 14 | 435227_230218,05:23:40,05:23:40,371,13,0,0,3586 15 | 435227_230218,05:24:28,05:24:28,368,14,0,0,3828 16 | 435227_230218,05:25:21,05:25:21,366,15,0,0,4164 17 | 435227_230218,05:26:36,05:26:36,356,16,0,0,4554 18 | 435227_230218,05:27:25,05:27:25,354,17,0,0,4802 19 | 435227_230218,05:28:54,05:28:54,599,18,1,0,5089 20 | 435227_040318,05:10:00,05:10:00,606,1,0,1,0 21 | 435227_040318,05:10:56,05:10:56,639,2,0,0,164 22 | 435227_040318,05:11:41,05:11:41,396,3,0,0,351 23 | 435227_040318,05:13:20,05:13:20,25438,4,0,0,764 24 | 435227_040318,05:16:03,05:16:03,389,5,0,0,1444 25 | 435227_040318,05:16:51,05:16:51,387,6,0,0,1642 26 | 435227_040318,05:17:46,05:17:46,382,7,0,0,2069 27 | 435227_040318,05:19:00,05:19:00,381,8,0,0,2338 28 | 435227_040318,05:20:18,05:20:18,385,9,0,0,2663 29 | 435227_040318,05:21:10,05:21:10,724,10,0,0,2880 30 | 435227_040318,05:22:44,05:22:44,374,11,0,0,3262 31 | 435227_040318,05:23:18,05:23:18,372,12,0,0,3420 32 | 435227_040318,05:23:40,05:23:40,371,13,0,0,3586 33 | 435227_040318,05:24:28,05:24:28,368,14,0,0,3828 34 | 435227_040318,05:25:21,05:25:21,366,15,0,0,4164 35 | 435227_040318,05:26:36,05:26:36,356,16,0,0,4554 36 | 435227_040318,05:27:25,05:27:25,354,17,0,0,4802 37 | 435227_040318,05:28:54,05:28:54,599,18,1,0,5089 38 | 4679602_280218,05:10:00,05:10:00,606,1,0,1,0 39 | 4679602_280218,05:10:56,05:10:56,639,2,0,0,164 40 | 4679602_280218,05:11:41,05:11:41,396,3,0,0,351 41 | 4679602_280218,05:13:20,05:13:20,25438,4,0,0,764 42 | 4679602_280218,05:16:03,05:16:03,389,5,0,0,1444 43 | 4679602_280218,05:16:51,05:16:51,387,6,0,0,1642 44 | 4679602_280218,05:17:46,05:17:46,382,7,0,0,2069 45 | 4679602_280218,05:19:00,05:19:00,381,8,0,0,2338 46 | 4679602_280218,05:20:18,05:20:18,385,9,0,0,2663 47 | 4679602_280218,05:21:10,05:21:10,724,10,0,0,2880 48 | 4679602_280218,05:22:44,05:22:44,374,11,0,0,3262 49 | 4679602_280218,05:23:18,05:23:18,372,12,0,0,3420 50 | 4679602_280218,05:23:40,05:23:40,371,13,0,0,3586 51 | 4679602_280218,05:24:28,05:24:28,368,14,0,0,3828 52 | 4679602_280218,05:25:21,05:25:21,366,15,0,0,4164 53 | 4679602_280218,05:26:36,05:26:36,356,16,0,0,4554 54 | 4679602_280218,05:27:25,05:27:25,354,17,0,0,4802 55 | 4679602_280218,05:28:54,05:28:54,599,18,1,0,5089 56 | 3528905_010318,05:10:00,05:10:00,606,1,0,1,0 57 | 3528905_010318,05:10:56,05:10:56,639,2,0,0,164 58 | 3528905_010318,05:11:41,05:11:41,396,3,0,0,351 59 | 3528905_010318,05:13:20,05:13:20,25438,4,0,0,764 60 | 3528905_010318,05:16:03,05:16:03,389,5,0,0,1444 61 | 3528905_010318,05:16:51,05:16:51,387,6,0,0,1642 62 | 3528905_010318,05:17:46,05:17:46,382,7,0,0,2069 63 | 3528905_010318,05:19:00,05:19:00,381,8,0,0,2338 64 | 3528905_010318,05:20:18,05:20:18,385,9,0,0,2663 65 | 3528905_010318,05:21:10,05:21:10,724,10,0,0,2880 66 | 3528905_010318,05:22:44,05:22:44,374,11,0,0,3262 67 | 3528905_010318,05:23:18,05:23:18,372,12,0,0,3420 68 | 3528905_010318,05:23:40,05:23:40,371,13,0,0,3586 69 | 3528905_010318,05:24:28,05:24:28,368,14,0,0,3828 70 | 3528905_010318,05:25:21,05:25:21,366,15,0,0,4164 71 | 3528905_010318,05:26:36,05:26:36,356,16,0,0,4554 72 | 3528905_010318,05:27:25,05:27:25,354,17,0,0,4802 73 | 3528905_010318,05:28:54,05:28:54,599,18,1,0,5089 74 | -------------------------------------------------------------------------------- /tests/fixtures/amazon-2017-08-06/routes.txt: -------------------------------------------------------------------------------- 1 | route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color 2 | 2204,81,"BSAM","Bellevue South AM",,700,,000000,000000 3 | 2205,81,"BSPM","Bellevue South PM",,700,,FFFFFF,FFFFFF 4 | 2206,81,"","Bothell/Kenmore AM",,700,,000000,FFFFFF 5 | 2207,81,"","Bothell/Kenmore PM",,700,,000000,FFFFFF 6 | 2208,81,"","Kirkland AM",,700,,000000,FFFFFF 7 | 2209,81,"","Kirkland PM",,700,,000000,FFFFFF 8 | 2210,81,"","Kirkland Redmond Sweeper",,700,,000000,FFFFFF 9 | 2211,81,"","Redmond AM",,700,,000000,FFFFFF 10 | 2212,81,"","Redmond PM",,700,,000000,FFFFFF 11 | 2213,81,""," Samm/Issaquah AM",,700,,000000,FFFFFF 12 | 2214,81,""," Samm/Issaquah PM",,700,,000000,FFFFFF 13 | 2400,81,"Route 1 AM","Route 1 AM - TRB/Blackfoot/Cricket",,700,,383838,FFFFFF 14 | 2402,81,"Route 2/7","Route 2/7 - Bus Tunnel/Train/Cricket",,700,,1F43F2,FFFFFF 15 | 2403,81,"Route 4 AM","Route 4 AM - Colman/North Campus",,700,,FF1212,FFFFFF 16 | 2407,81,"Route 28","Route 28 - Prime/Cricket/Doppler/Dawson CallOut",,700,,F1FF30,FFFFFF 17 | 2408,81,"Route 26","Route 26 -Cricket/Doppler",,700,,5E5E5E,FFFFFF 18 | 2409,81,"Route 25","Route 25 - Galaxy/Doppler/Alexandria/Cricket",,700,,1D87CF,FFFFFF 19 | 2410,81,"Route 12","Route 12 - Cricket/Blackfoot",,700,,69AAFF,FFFFFF 20 | 2411,81,"Route 9/16/27 AM","Route 9/16/27 AM - Bus Tunnel/Train/Blackfoot/Doppler",,700,,1CD9FF,FFFFFF 21 | 2413,81,"Route 11 AM","Route 11 AM - Campus/Convention Place/7th + Pike",,700,,B3B3B3,080808 22 | 2418,81,"Route 5/6 PM","Route 5/6 PM - Dawson/Arizona/Cricket/Train",,700,,1985FF,FFFFFF 23 | 2419,81,"Route 8 AM","Route 8 AM - Colman/Campus call-outs",,700,,12820A,FFFFFF 24 | 2421,81,"Route 15 AM","Route 15 AM - Train/Colman/Galaxy",,700,,FF0A0A,FFFFFF 25 | 2422,81,"Route 17 AM","Route 17 AM - Bus Tunnel/Train/Campus",,700,,AD1C1C,FFFFFF 26 | 2424,81,"Route 19 AM","Route 19 AM - Colman/South Campus",,700,,5F0FFF,FFFFFF 27 | 2444,81,"Route 20","Route 20 - Galaxy/Cricket",,700,,11A6D4,FFFFFF 28 | 2445,81,"Route 21","Route 21 - Train/Colman/Campus Call-Outs",,700,,11A6D4,FFFFFF 29 | 2464,81,"Snoqualmie/Eastridge AM","Snoqualmie/Eastridge AM",,700,,FFFFFF,FFFFFF 30 | 2482,81,"Snoqualmie/Eastridge AM","Snoqualmie/Eastridge PM",,700,,FF7700,000000 31 | 2525,81,"425AM","Bellevue 425 AM",,700,,FF7700,FFFFFF 32 | 2526,81,"425PM","Bellevue 425 PM",,700,,FF7700,FFFFFF 33 | 2544,81,"Route 1 PM","Route 1 PM - Blackfoot/Cricket/TRB",,700,,000000,FFFFFF 34 | 2546,81,"Route 4 PM","Route 4 PM - Houston/Cricket/Arizona/Colman",,700,,FF0808,FFFFFF 35 | 2547,81,"Route 5/6 AM","Route 5/6 AM - Bus Tunnel/Train/Dawson/Arizona",,700,,0808FF,FFFFFF 36 | 2548,81,"Route 8 PM","Route 8 PM - North/South Campus/Colman",,700,,0B8F10,FFFFFF 37 | 2549,81,"Route 9/16 PM","Route 9/16 PM - Blackfoot/Doppler/Train",,700,,1CD9FF,FFFFFF 38 | 2550,81,"Route 11 PM ","Route 11 PM - Campus/Convention Place/7th + Pike",,700,,C4C4C4,FFFFFF 39 | 2553,81,"Route 15 PM","Route 15 PM - Galaxy/Colman/Train",,700,,FF170F,FFFFFF 40 | 2554,81,"Route 17 PM","Route 17 PM - Varzea/Otter/Coral/Colman/Train",,700,,B01D0C,FFFFFF 41 | 2555,81,"Route 19 PM","Route 19 PM - Blackfoot/Doppler/Colman",,700,,C21199,FFFFFF 42 | 2623,81,"Route 22 AM - Intern","Route 22 - Intern Route 1 AM",,700,,307CFF,FFFFFF 43 | 2624,81,"Route 23 AM - Intern","Route 23 - Intern Route 2 AM",,700,,307CFF,FFFFFF 44 | 2625,81,"Route 24 AM - Intern","Route 24 - Intern Route 3 AM",,700,,307CFF,FFFFFF 45 | 2626,81,"Route 22 PM - Intern","Route 22 - Intern Route 1 PM",,700,,307CFF,FFFFFF 46 | 2627,81,"Route 23 PM - Intern","Route 23 - Intern Route 2 PM",,700,,307CFF,FFFFFF 47 | 2628,81,"Route 24 PM - Intern","Route 24 - Intern Route 3 PM",,700,,307CFF,FFFFFF 48 | 2673,81,"Tracking","Bus Tracking Only",,700,,000000,FFFFFF 49 | 2675,81,"Mercer AM","Mercer AM",,700,,FF7700,FFFFFF 50 | 2680,81,"Route 30","Route 30 - Cricket/Everest",,700,,4785FF,FFFFFF 51 | 2683,81,"Mercer PM","Mercer PM",,700,,FF7700,FFFFFF 52 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/fare_rules.txt: -------------------------------------------------------------------------------- 1 | fare_id,route_id,origin_id,destination_id 2 | OW_1_20160228,Bu-129,1,1 3 | OW_2_20160228,Bu-129,1,2 4 | OW_3_20160228,Bu-129,1,3 5 | OW_4_20160228,Bu-129,1,4 6 | OW_5_20160228,Bu-129,1,5 7 | OW_6_20160228,Bu-129,1,6 8 | OW_2_20160228,Bu-129,2,1 9 | OW_1_20160228,Bu-129,2,2 10 | OW_2_20160228,Bu-129,2,3 11 | OW_3_20160228,Bu-129,2,4 12 | OW_4_20160228,Bu-129,2,5 13 | OW_5_20160228,Bu-129,2,6 14 | OW_3_20160228,Bu-129,3,1 15 | OW_2_20160228,Bu-129,3,2 16 | OW_1_20160228,Bu-129,3,3 17 | OW_2_20160228,Bu-129,3,4 18 | OW_3_20160228,Bu-129,3,5 19 | OW_4_20160228,Bu-129,3,6 20 | OW_4_20160228,Bu-129,4,1 21 | OW_3_20160228,Bu-129,4,2 22 | OW_2_20160228,Bu-129,4,3 23 | OW_1_20160228,Bu-129,4,4 24 | OW_2_20160228,Bu-129,4,5 25 | OW_3_20160228,Bu-129,4,6 26 | OW_5_20160228,Bu-129,5,1 27 | OW_4_20160228,Bu-129,5,2 28 | OW_3_20160228,Bu-129,5,3 29 | OW_2_20160228,Bu-129,5,4 30 | OW_1_20160228,Bu-129,5,5 31 | OW_2_20160228,Bu-129,5,6 32 | OW_6_20160228,Bu-129,6,1 33 | OW_5_20160228,Bu-129,6,2 34 | OW_4_20160228,Bu-129,6,3 35 | OW_3_20160228,Bu-129,6,4 36 | OW_2_20160228,Bu-129,6,5 37 | OW_1_20160228,Bu-129,6,6 38 | OW_1_20160228,Li-129,1,1 39 | OW_2_20160228,Li-129,1,2 40 | OW_3_20160228,Li-129,1,3 41 | OW_4_20160228,Li-129,1,4 42 | OW_5_20160228,Li-129,1,5 43 | OW_6_20160228,Li-129,1,6 44 | OW_2_20160228,Li-129,2,1 45 | OW_1_20160228,Li-129,2,2 46 | OW_2_20160228,Li-129,2,3 47 | OW_3_20160228,Li-129,2,4 48 | OW_4_20160228,Li-129,2,5 49 | OW_5_20160228,Li-129,2,6 50 | OW_3_20160228,Li-129,3,1 51 | OW_2_20160228,Li-129,3,2 52 | OW_1_20160228,Li-129,3,3 53 | OW_2_20160228,Li-129,3,4 54 | OW_3_20160228,Li-129,3,5 55 | OW_4_20160228,Li-129,3,6 56 | OW_4_20160228,Li-129,4,1 57 | OW_3_20160228,Li-129,4,2 58 | OW_2_20160228,Li-129,4,3 59 | OW_1_20160228,Li-129,4,4 60 | OW_2_20160228,Li-129,4,5 61 | OW_3_20160228,Li-129,4,6 62 | OW_5_20160228,Li-129,5,1 63 | OW_4_20160228,Li-129,5,2 64 | OW_3_20160228,Li-129,5,3 65 | OW_2_20160228,Li-129,5,4 66 | OW_1_20160228,Li-129,5,5 67 | OW_2_20160228,Li-129,5,6 68 | OW_6_20160228,Li-129,6,1 69 | OW_5_20160228,Li-129,6,2 70 | OW_4_20160228,Li-129,6,3 71 | OW_3_20160228,Li-129,6,4 72 | OW_2_20160228,Li-129,6,5 73 | OW_1_20160228,Li-129,6,6 74 | OW_1_20160228,Lo-129,1,1 75 | OW_2_20160228,Lo-129,1,2 76 | OW_3_20160228,Lo-129,1,3 77 | OW_4_20160228,Lo-129,1,4 78 | OW_5_20160228,Lo-129,1,5 79 | OW_6_20160228,Lo-129,1,6 80 | OW_2_20160228,Lo-129,2,1 81 | OW_1_20160228,Lo-129,2,2 82 | OW_2_20160228,Lo-129,2,3 83 | OW_3_20160228,Lo-129,2,4 84 | OW_4_20160228,Lo-129,2,5 85 | OW_5_20160228,Lo-129,2,6 86 | OW_3_20160228,Lo-129,3,1 87 | OW_2_20160228,Lo-129,3,2 88 | OW_1_20160228,Lo-129,3,3 89 | OW_2_20160228,Lo-129,3,4 90 | OW_3_20160228,Lo-129,3,5 91 | OW_4_20160228,Lo-129,3,6 92 | OW_4_20160228,Lo-129,4,1 93 | OW_3_20160228,Lo-129,4,2 94 | OW_2_20160228,Lo-129,4,3 95 | OW_1_20160228,Lo-129,4,4 96 | OW_2_20160228,Lo-129,4,5 97 | OW_3_20160228,Lo-129,4,6 98 | OW_5_20160228,Lo-129,5,1 99 | OW_4_20160228,Lo-129,5,2 100 | OW_3_20160228,Lo-129,5,3 101 | OW_2_20160228,Lo-129,5,4 102 | OW_1_20160228,Lo-129,5,5 103 | OW_2_20160228,Lo-129,5,6 104 | OW_6_20160228,Lo-129,6,1 105 | OW_5_20160228,Lo-129,6,2 106 | OW_4_20160228,Lo-129,6,3 107 | OW_3_20160228,Lo-129,6,4 108 | OW_2_20160228,Lo-129,6,5 109 | OW_1_20160228,Lo-129,6,6 110 | OW_1_20160228,TaSj-129,1,1 111 | OW_2_20160228,TaSj-129,1,2 112 | OW_3_20160228,TaSj-129,1,3 113 | OW_4_20160228,TaSj-129,1,4 114 | OW_5_20160228,TaSj-129,1,5 115 | OW_6_20160228,TaSj-129,1,6 116 | OW_2_20160228,TaSj-129,2,1 117 | OW_1_20160228,TaSj-129,2,2 118 | OW_2_20160228,TaSj-129,2,3 119 | OW_3_20160228,TaSj-129,2,4 120 | OW_4_20160228,TaSj-129,2,5 121 | OW_5_20160228,TaSj-129,2,6 122 | OW_3_20160228,TaSj-129,3,1 123 | OW_2_20160228,TaSj-129,3,2 124 | OW_1_20160228,TaSj-129,3,3 125 | OW_2_20160228,TaSj-129,3,4 126 | OW_3_20160228,TaSj-129,3,5 127 | OW_4_20160228,TaSj-129,3,6 128 | OW_4_20160228,TaSj-129,4,1 129 | OW_3_20160228,TaSj-129,4,2 130 | OW_2_20160228,TaSj-129,4,3 131 | OW_1_20160228,TaSj-129,4,4 132 | OW_2_20160228,TaSj-129,4,5 133 | OW_3_20160228,TaSj-129,4,6 134 | OW_5_20160228,TaSj-129,5,1 135 | OW_4_20160228,TaSj-129,5,2 136 | OW_3_20160228,TaSj-129,5,3 137 | OW_2_20160228,TaSj-129,5,4 138 | OW_1_20160228,TaSj-129,5,5 139 | OW_2_20160228,TaSj-129,5,6 140 | OW_6_20160228,TaSj-129,6,1 141 | OW_5_20160228,TaSj-129,6,2 142 | OW_4_20160228,TaSj-129,6,3 143 | OW_3_20160228,TaSj-129,6,4 144 | OW_2_20160228,TaSj-129,6,5 145 | OW_1_20160228,TaSj-129,6,6 146 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/fare_rules.txt: -------------------------------------------------------------------------------- 1 | fare_id,route_id,origin_id,destination_id 2 | OW_1_20160228,Bu-129,1,1 3 | OW_2_20160228,Bu-129,1,2 4 | OW_3_20160228,Bu-129,1,3 5 | OW_4_20160228,Bu-129,1,4 6 | OW_5_20160228,Bu-129,1,5 7 | OW_6_20160228,Bu-129,1,6 8 | OW_2_20160228,Bu-129,2,1 9 | OW_1_20160228,Bu-129,2,2 10 | OW_2_20160228,Bu-129,2,3 11 | OW_3_20160228,Bu-129,2,4 12 | OW_4_20160228,Bu-129,2,5 13 | OW_5_20160228,Bu-129,2,6 14 | OW_3_20160228,Bu-129,3,1 15 | OW_2_20160228,Bu-129,3,2 16 | OW_1_20160228,Bu-129,3,3 17 | OW_2_20160228,Bu-129,3,4 18 | OW_3_20160228,Bu-129,3,5 19 | OW_4_20160228,Bu-129,3,6 20 | OW_4_20160228,Bu-129,4,1 21 | OW_3_20160228,Bu-129,4,2 22 | OW_2_20160228,Bu-129,4,3 23 | OW_1_20160228,Bu-129,4,4 24 | OW_2_20160228,Bu-129,4,5 25 | OW_3_20160228,Bu-129,4,6 26 | OW_5_20160228,Bu-129,5,1 27 | OW_4_20160228,Bu-129,5,2 28 | OW_3_20160228,Bu-129,5,3 29 | OW_2_20160228,Bu-129,5,4 30 | OW_1_20160228,Bu-129,5,5 31 | OW_2_20160228,Bu-129,5,6 32 | OW_6_20160228,Bu-129,6,1 33 | OW_5_20160228,Bu-129,6,2 34 | OW_4_20160228,Bu-129,6,3 35 | OW_3_20160228,Bu-129,6,4 36 | OW_2_20160228,Bu-129,6,5 37 | OW_1_20160228,Bu-129,6,6 38 | OW_1_20160228,Li-129,1,1 39 | OW_2_20160228,Li-129,1,2 40 | OW_3_20160228,Li-129,1,3 41 | OW_4_20160228,Li-129,1,4 42 | OW_5_20160228,Li-129,1,5 43 | OW_6_20160228,Li-129,1,6 44 | OW_2_20160228,Li-129,2,1 45 | OW_1_20160228,Li-129,2,2 46 | OW_2_20160228,Li-129,2,3 47 | OW_3_20160228,Li-129,2,4 48 | OW_4_20160228,Li-129,2,5 49 | OW_5_20160228,Li-129,2,6 50 | OW_3_20160228,Li-129,3,1 51 | OW_2_20160228,Li-129,3,2 52 | OW_1_20160228,Li-129,3,3 53 | OW_2_20160228,Li-129,3,4 54 | OW_3_20160228,Li-129,3,5 55 | OW_4_20160228,Li-129,3,6 56 | OW_4_20160228,Li-129,4,1 57 | OW_3_20160228,Li-129,4,2 58 | OW_2_20160228,Li-129,4,3 59 | OW_1_20160228,Li-129,4,4 60 | OW_2_20160228,Li-129,4,5 61 | OW_3_20160228,Li-129,4,6 62 | OW_5_20160228,Li-129,5,1 63 | OW_4_20160228,Li-129,5,2 64 | OW_3_20160228,Li-129,5,3 65 | OW_2_20160228,Li-129,5,4 66 | OW_1_20160228,Li-129,5,5 67 | OW_2_20160228,Li-129,5,6 68 | OW_6_20160228,Li-129,6,1 69 | OW_5_20160228,Li-129,6,2 70 | OW_4_20160228,Li-129,6,3 71 | OW_3_20160228,Li-129,6,4 72 | OW_2_20160228,Li-129,6,5 73 | OW_1_20160228,Li-129,6,6 74 | OW_1_20160228,Lo-129,1,1 75 | OW_2_20160228,Lo-129,1,2 76 | OW_3_20160228,Lo-129,1,3 77 | OW_4_20160228,Lo-129,1,4 78 | OW_5_20160228,Lo-129,1,5 79 | OW_6_20160228,Lo-129,1,6 80 | OW_2_20160228,Lo-129,2,1 81 | OW_1_20160228,Lo-129,2,2 82 | OW_2_20160228,Lo-129,2,3 83 | OW_3_20160228,Lo-129,2,4 84 | OW_4_20160228,Lo-129,2,5 85 | OW_5_20160228,Lo-129,2,6 86 | OW_3_20160228,Lo-129,3,1 87 | OW_2_20160228,Lo-129,3,2 88 | OW_1_20160228,Lo-129,3,3 89 | OW_2_20160228,Lo-129,3,4 90 | OW_3_20160228,Lo-129,3,5 91 | OW_4_20160228,Lo-129,3,6 92 | OW_4_20160228,Lo-129,4,1 93 | OW_3_20160228,Lo-129,4,2 94 | OW_2_20160228,Lo-129,4,3 95 | OW_1_20160228,Lo-129,4,4 96 | OW_2_20160228,Lo-129,4,5 97 | OW_3_20160228,Lo-129,4,6 98 | OW_5_20160228,Lo-129,5,1 99 | OW_4_20160228,Lo-129,5,2 100 | OW_3_20160228,Lo-129,5,3 101 | OW_2_20160228,Lo-129,5,4 102 | OW_1_20160228,Lo-129,5,5 103 | OW_2_20160228,Lo-129,5,6 104 | OW_6_20160228,Lo-129,6,1 105 | OW_5_20160228,Lo-129,6,2 106 | OW_4_20160228,Lo-129,6,3 107 | OW_3_20160228,Lo-129,6,4 108 | OW_2_20160228,Lo-129,6,5 109 | OW_1_20160228,Lo-129,6,6 110 | OW_1_20160228,TaSj-129,1,1 111 | OW_2_20160228,TaSj-129,1,2 112 | OW_3_20160228,TaSj-129,1,3 113 | OW_4_20160228,TaSj-129,1,4 114 | OW_5_20160228,TaSj-129,1,5 115 | OW_6_20160228,TaSj-129,1,6 116 | OW_2_20160228,TaSj-129,2,1 117 | OW_1_20160228,TaSj-129,2,2 118 | OW_2_20160228,TaSj-129,2,3 119 | OW_3_20160228,TaSj-129,2,4 120 | OW_4_20160228,TaSj-129,2,5 121 | OW_5_20160228,TaSj-129,2,6 122 | OW_3_20160228,TaSj-129,3,1 123 | OW_2_20160228,TaSj-129,3,2 124 | OW_1_20160228,TaSj-129,3,3 125 | OW_2_20160228,TaSj-129,3,4 126 | OW_3_20160228,TaSj-129,3,5 127 | OW_4_20160228,TaSj-129,3,6 128 | OW_4_20160228,TaSj-129,4,1 129 | OW_3_20160228,TaSj-129,4,2 130 | OW_2_20160228,TaSj-129,4,3 131 | OW_1_20160228,TaSj-129,4,4 132 | OW_2_20160228,TaSj-129,4,5 133 | OW_3_20160228,TaSj-129,4,6 134 | OW_5_20160228,TaSj-129,5,1 135 | OW_4_20160228,TaSj-129,5,2 136 | OW_3_20160228,TaSj-129,5,3 137 | OW_2_20160228,TaSj-129,5,4 138 | OW_1_20160228,TaSj-129,5,5 139 | OW_2_20160228,TaSj-129,5,6 140 | OW_6_20160228,TaSj-129,6,1 141 | OW_5_20160228,TaSj-129,6,2 142 | OW_4_20160228,TaSj-129,6,3 143 | OW_3_20160228,TaSj-129,6,4 144 | OW_2_20160228,TaSj-129,6,5 145 | OW_1_20160228,TaSj-129,6,6 146 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/stops.txt: -------------------------------------------------------------------------------- 1 | stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,platform_code,wheelchair_boarding 2 | 70011,70011,San Francisco Caltrain,,37.77639,-122.394992,1,,0,,NB,1 3 | 70012,70012,San Francisco Caltrain,,37.776348,-122.394935,1,,0,,SB,1 4 | 70021,70021,22nd St Caltrain,,37.757599,-122.39188,1,,0,,NB,2 5 | 70022,70022,22nd St Caltrain,,37.757583,-122.392404,1,,0,,SB,2 6 | 70031,70031,Bayshore Caltrain,,37.709537,-122.401586,1,,0,,NB,1 7 | 70032,70032,Bayshore Caltrain,,37.709544,-122.40198,1,,0,,SB,1 8 | 70041,70041,So. San Francisco Caltrain Station,,37.65589,-122.40487,1,,0,,NB,2 9 | 70042,70042,So. San Francisco Caltrain Station,,37.655946,-122.405018,1,,0,,SB,2 10 | 70051,70051,San Bruno Caltrain,,37.631128,-122.411968,1,,0,,NB,1 11 | 70052,70052,San Bruno Caltrain,,37.631108,-122.412076,1,,0,,SB,1 12 | 70061,70061,Millbrae Caltrain,,37.59988,-122.386647,2,,0,,NB,1 13 | 70062,70062,Millbrae Caltrain,,37.599797,-122.386832,2,,0,,SB,1 14 | 70071,70071,Broadway Caltrain,,37.58764,-122.36265,2,,0,,NB,2 15 | 70072,70072,Broadway Caltrain,,37.587552,-122.362708,2,,0,,SB,2 16 | 70081,70081,Burlingame Caltrain,,37.580197,-122.3449,2,,0,,NB,1 17 | 70082,70082,Burlingame Caltrain,,37.580186,-122.345075,2,,0,,SB,1 18 | 70091,70091,San Mateo Caltrain,,37.568087,-122.323851,2,,0,,NB,1 19 | 70092,70092,San Mateo Caltrain,,37.568294,-122.324092,2,,0,,SB,1 20 | 70101,70101,Hayward Park Caltrain,,37.552938,-122.309338,2,,0,,NB,1 21 | 70102,70102,Hayward Park Caltrain,,37.552994,-122.309608,2,,0,,SB,1 22 | 70111,70111,Hillsdale Caltrain,,37.537868,-122.297349,2,,0,,NB,1 23 | 70112,70112,Hillsdale Caltrain,,37.537814,-122.297461,2,,0,,SB,1 24 | 70121,70121,Belmont Caltrain,,37.52089,-122.275738,2,,0,,NB,1 25 | 70122,70122,Belmont Caltrain,,37.520844,-122.275816,2,,0,,SB,1 26 | 70131,70131,San Carlos Caltrain,,37.50805,-122.26015,2,,0,,NB,1 27 | 70132,70132,San Carlos Caltrain,,37.507933,-122.260266,2,,0,,SB,1 28 | 70141,70141,Redwood City Caltrain,,37.486159,-122.231936,2,,0,,NB,1 29 | 70142,70142,Redwood City Caltrain,,37.486101,-122.232,2,,0,,SB,1 30 | 70151,70151,Atherton Caltrain,,37.464645,-122.19779,3,,0,,NB,2 31 | 70152,70152,Atherton Caltrain,,37.464584,-122.197869,3,,0,,SB,2 32 | 70161,70161,Menlo Park Caltrain,,37.454856,-122.182297,3,,0,,NB,1 33 | 70162,70162,Menlo Park Caltrain,,37.454745,-122.182405,3,,0,,SB,1 34 | 70171,70171,Palo Alto Caltrain,,37.443475,-122.164614,3,,0,,NB,1 35 | 70172,70172,Palo Alto Caltrain,,37.443405,-122.164697,3,,0,,SB,1 36 | 70191,70191,California Ave Caltrain,,37.429365,-122.141927,3,,0,,NB,1 37 | 70192,70192,California Ave Caltrain,,37.429333,-122.141978,3,,0,,SB,1 38 | 70201,70201,San Antonio Caltrain,,37.407323,-122.107069,3,,0,,NB,1 39 | 70202,70202,San Antonio Caltrain,,37.407277,-122.107125,3,,0,,SB,1 40 | 70211,70211,Mt View Caltrain,,37.394459,-122.075956,3,,0,,NB,1 41 | 70212,70212,Mt View Caltrain,,37.394402,-122.075994,3,,0,,SB,1 42 | 70221,70221,Sunnyvale Caltrain,,37.378916,-122.031372,3,,0,,NB,1 43 | 70222,70222,Sunnyvale Caltrain,,37.378789,-122.031423,3,,0,,SB,1 44 | 70231,70231,Lawrence Caltrain,,37.370598,-121.997114,4,,0,,NB,1 45 | 70232,70232,Lawrence Caltrain,,37.370484,-121.997135,4,,0,,SB,1 46 | 70241,70241,Santa Clara Caltrain,,37.353238,-121.93608,4,,0,,NB,1 47 | 70242,70242,Santa Clara Caltrain,,37.353189,-121.936135,4,,0,,SB,1 48 | 70251,70251,College Park Caltrain,,37.342384,-121.9146,4,,0,,NB,2 49 | 70252,70252,College Park Caltrain,,37.342338,-121.914677,4,,0,,SB,2 50 | 70261,70261,San Jose Diridon Caltrain,,37.329239,-121.903011,4,,0,,NB,1 51 | 70262,70262,San Jose Diridon Caltrain,,37.329231,-121.903173,4,,0,,SB,1 52 | 70271,70271,Tamien Caltrain,,37.31174,-121.883721,4,,0,,NB,1 53 | 70272,70272,Tamien Caltrain,,37.31175,-121.883999,4,,0,,SB,1 54 | 70281,70281,Capitol Caltrain,,37.284102,-121.841955,5,,0,,NB,1 55 | 70282,70282,Capitol Caltrain,,37.284062,-121.842037,5,,0,,SB,1 56 | 70291,70291,Blossom Hill Caltrain,,37.252422,-121.797643,5,,0,,NB,1 57 | 70292,70292,Blossom Hill Caltrain,,37.252379,-121.797683,5,,0,,SB,1 58 | 70301,70301,Morgan Hill Caltrain,,37.129363,-121.650244,6,,0,,NB,1 59 | 70302,70302,Morgan Hill Caltrain,,37.129321,-121.650304,6,,0,,SB,1 60 | 70311,70311,San Martin Caltrain,,37.085225,-121.610049,6,,0,,NB,1 61 | 70312,70312,San Martin Caltrain,,37.086653,-121.610936,6,,0,,SB,1 62 | 70321,70321,Gilroy Caltrain,,37.003538,-121.566088,6,,0,,NB,1 63 | 70322,70322,Gilroy Caltrain,,37.003485,-121.566225,6,,0,,SB,1 64 | 777402,777402,San Jose Caltrain Station,,37.330196,-121.901985,,,0,,SB,1 65 | 777403,777403,Tamien Caltrain Station,,37.311638,-121.883403,,,0,,SB,1 66 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/stops.txt: -------------------------------------------------------------------------------- 1 | stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,platform_code,wheelchair_boarding 2 | 70011,70011,San Francisco Caltrain,,37.77639,-122.394992,1,,0,,NB,1 3 | 70012,70012,San Francisco Caltrain,,37.776348,-122.394935,1,,0,,SB,1 4 | 70021,70021,22nd St Caltrain,,37.757599,-122.39188,1,,0,,NB,2 5 | 70022,70022,22nd St Caltrain,,37.757583,-122.392404,1,,0,,SB,2 6 | 70031,70031,Bayshore Caltrain,,37.709537,-122.401586,1,,0,,NB,1 7 | 70032,70032,Bayshore Caltrain,,37.709544,-122.40198,1,,0,,SB,1 8 | 70041,70041,So. San Francisco Caltrain Station,,37.65589,-122.40487,1,,0,,NB,2 9 | 70042,70042,So. San Francisco Caltrain Station,,37.655946,-122.405018,1,,0,,SB,2 10 | 70051,70051,San Bruno Caltrain,,37.631128,-122.411968,1,,0,,NB,1 11 | 70052,70052,San Bruno Caltrain,,37.631108,-122.412076,1,,0,,SB,1 12 | 70061,70061,Millbrae Caltrain,,37.59988,-122.386647,2,,0,,NB,1 13 | 70062,70062,Millbrae Caltrain,,37.599797,-122.386832,2,,0,,SB,1 14 | 70071,70071,Broadway Caltrain,,37.58764,-122.36265,2,,0,,NB,2 15 | 70072,70072,Broadway Caltrain,,37.587552,-122.362708,2,,0,,SB,2 16 | 70081,70081,Burlingame Caltrain,,37.580197,-122.3449,2,,0,,NB,1 17 | 70082,70082,Burlingame Caltrain,,37.580186,-122.345075,2,,0,,SB,1 18 | 70091,70091,San Mateo Caltrain,,37.568087,-122.323851,2,,0,,NB,1 19 | 70092,70092,San Mateo Caltrain,,37.568294,-122.324092,2,,0,,SB,1 20 | 70101,70101,Hayward Park Caltrain,,37.552938,-122.309338,2,,0,,NB,1 21 | 70102,70102,Hayward Park Caltrain,,37.552994,-122.309608,2,,0,,SB,1 22 | 70111,70111,Hillsdale Caltrain,,37.537868,-122.297349,2,,0,,NB,1 23 | 70112,70112,Hillsdale Caltrain,,37.537814,-122.297461,2,,0,,SB,1 24 | 70121,70121,Belmont Caltrain,,37.52089,-122.275738,2,,0,,NB,1 25 | 70122,70122,Belmont Caltrain,,37.520844,-122.275816,2,,0,,SB,1 26 | 70131,70131,San Carlos Caltrain,,37.50805,-122.26015,2,,0,,NB,1 27 | 70132,70132,San Carlos Caltrain,,37.507933,-122.260266,2,,0,,SB,1 28 | 70141,70141,Redwood City Caltrain,,37.486159,-122.231936,2,,0,,NB,1 29 | 70142,70142,Redwood City Caltrain,,37.486101,-122.232,2,,0,,SB,1 30 | 70151,70151,Atherton Caltrain,,37.464645,-122.19779,3,,0,,NB,2 31 | 70152,70152,Atherton Caltrain,,37.464584,-122.197869,3,,0,,SB,2 32 | 70161,70161,Menlo Park Caltrain,,37.454856,-122.182297,3,,0,,NB,1 33 | 70162,70162,Menlo Park Caltrain,,37.454745,-122.182405,3,,0,,SB,1 34 | 70171,70171,Palo Alto Caltrain,,37.443475,-122.164614,3,,0,,NB,1 35 | 70172,70172,Palo Alto Caltrain,,37.443405,-122.164697,3,,0,,SB,1 36 | 70191,70191,California Ave Caltrain,,37.429365,-122.141927,3,,0,,NB,1 37 | 70192,70192,California Ave Caltrain,,37.429333,-122.141978,3,,0,,SB,1 38 | 70201,70201,San Antonio Caltrain,,37.407323,-122.107069,3,,0,,NB,1 39 | 70202,70202,San Antonio Caltrain,,37.407277,-122.107125,3,,0,,SB,1 40 | 70211,70211,Mt View Caltrain,,37.394459,-122.075956,3,,0,,NB,1 41 | 70212,70212,Mt View Caltrain,,37.394402,-122.075994,3,,0,,SB,1 42 | 70221,70221,Sunnyvale Caltrain,,37.378916,-122.031372,3,,0,,NB,1 43 | 70222,70222,Sunnyvale Caltrain,,37.378789,-122.031423,3,,0,,SB,1 44 | 70231,70231,Lawrence Caltrain,,37.370598,-121.997114,4,,0,,NB,1 45 | 70232,70232,Lawrence Caltrain,,37.370484,-121.997135,4,,0,,SB,1 46 | 70241,70241,Santa Clara Caltrain,,37.353238,-121.93608,4,,0,,NB,1 47 | 70242,70242,Santa Clara Caltrain,,37.353189,-121.936135,4,,0,,SB,1 48 | 70251,70251,College Park Caltrain,,37.342384,-121.9146,4,,0,,NB,2 49 | 70252,70252,College Park Caltrain,,37.342338,-121.914677,4,,0,,SB,2 50 | 70261,70261,San Jose Diridon Caltrain,,37.329239,-121.903011,4,,0,,NB,1 51 | 70262,70262,San Jose Diridon Caltrain,,37.329231,-121.903173,4,,0,,SB,1 52 | 70271,70271,Tamien Caltrain,,37.31174,-121.883721,4,,0,,NB,1 53 | 70272,70272,Tamien Caltrain,,37.31175,-121.883999,4,,0,,SB,1 54 | 70281,70281,Capitol Caltrain,,37.284102,-121.841955,5,,0,,NB,1 55 | 70282,70282,Capitol Caltrain,,37.284062,-121.842037,5,,0,,SB,1 56 | 70291,70291,Blossom Hill Caltrain,,37.252422,-121.797643,5,,0,,NB,1 57 | 70292,70292,Blossom Hill Caltrain,,37.252379,-121.797683,5,,0,,SB,1 58 | 70301,70301,Morgan Hill Caltrain,,37.129363,-121.650244,6,,0,,NB,1 59 | 70302,70302,Morgan Hill Caltrain,,37.129321,-121.650304,6,,0,,SB,1 60 | 70311,70311,San Martin Caltrain,,37.085225,-121.610049,6,,0,,NB,1 61 | 70312,70312,San Martin Caltrain,,37.086653,-121.610936,6,,0,,SB,1 62 | 70321,70321,Gilroy Caltrain,,37.003538,-121.566088,6,,0,,NB,1 63 | 70322,70322,Gilroy Caltrain,,37.003485,-121.566225,6,,0,,SB,1 64 | 777402,777402,San Jose Caltrain Station,,37.330196,-121.901985,,,0,,SB,1 65 | 777403,777403,Tamien Caltrain Station,,37.311638,-121.883403,,,0,,SB,1 66 | -------------------------------------------------------------------------------- /tests/fixtures/israel-public-transportation-route-2126/shapes.txt: -------------------------------------------------------------------------------- 1 | shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence 2 | 93890,32.327459,34.858705,143 3 | 93890,32.327423,34.858596,144 4 | 93890,32.327338,34.858504,145 5 | 93890,32.327223,34.858463,146 6 | 93890,32.327152,34.858446,147 7 | 93890,32.327074,34.858438,148 8 | 93890,32.327010,34.858480,149 9 | 93890,32.326985,34.858567,150 10 | 93890,32.351540,34.865603,1 11 | 93890,32.352333,34.865661,2 12 | 93890,32.352337,34.865450,3 13 | 93890,32.352338,34.864894,4 14 | 93890,32.352380,34.864290,5 15 | 93890,32.352395,34.864103,6 16 | 93890,32.352419,34.863863,7 17 | 93890,32.352451,34.863608,8 18 | 93890,32.352447,34.863522,9 19 | 93890,32.352404,34.863475,10 20 | 93890,32.352211,34.863387,11 21 | 93890,32.351986,34.863292,12 22 | 93890,32.351765,34.863241,13 23 | 93890,32.351994,34.861974,14 24 | 93890,32.352009,34.861907,15 25 | 93890,32.352232,34.860699,16 26 | 93890,32.352341,34.859920,17 27 | 93890,32.352327,34.859644,18 28 | 93890,32.352297,34.859306,19 29 | 93890,32.352241,34.859033,20 30 | 93890,32.352178,34.858822,21 31 | 93890,32.352063,34.858432,22 32 | 93890,32.352013,34.858252,23 33 | 93890,32.351972,34.858095,24 34 | 93890,32.351900,34.858125,25 35 | 93890,32.351838,34.858128,26 36 | 93890,32.351869,34.858305,27 37 | 93890,32.351937,34.858538,28 38 | 93890,32.352096,34.858993,29 39 | 93890,32.352297,34.859306,30 40 | 93890,32.352327,34.859644,31 41 | 93890,32.352341,34.859920,32 42 | 93890,32.352232,34.860699,33 43 | 93890,32.352009,34.861907,34 44 | 93890,32.351994,34.861974,35 45 | 93890,32.351104,34.861691,36 46 | 93890,32.349989,34.861481,37 47 | 93890,32.349653,34.861418,38 48 | 93890,32.349296,34.861351,39 49 | 93890,32.349143,34.861329,40 50 | 93890,32.348307,34.861181,41 51 | 93890,32.347840,34.861107,42 52 | 93890,32.347604,34.861060,43 53 | 93890,32.347792,34.860210,44 54 | 93890,32.347857,34.859900,45 55 | 93890,32.348111,34.858730,46 56 | 93890,32.348250,34.858127,47 57 | 93890,32.348289,34.857865,48 58 | 93890,32.348319,34.857640,49 59 | 93890,32.348322,34.857502,50 60 | 93890,32.347484,34.857434,51 61 | 93890,32.346667,34.857347,52 62 | 93890,32.346537,34.857322,53 63 | 93890,32.346444,34.857312,54 64 | 93890,32.346373,34.857309,55 65 | 93890,32.346324,34.857321,56 66 | 93890,32.346324,34.857286,57 67 | 93890,32.346315,34.857256,58 68 | 93890,32.346296,34.857223,59 69 | 93890,32.346269,34.857198,60 70 | 93890,32.346243,34.857185,61 71 | 93890,32.346229,34.857183,62 72 | 93890,32.346209,34.857180,63 73 | 93890,32.346174,34.857188,64 74 | 93890,32.346144,34.857207,65 75 | 93890,32.346120,34.857236,66 76 | 93890,32.346103,34.857279,67 77 | 93890,32.346102,34.857287,68 78 | 93890,32.346100,34.857319,69 79 | 93890,32.346108,34.857358,70 80 | 93890,32.346131,34.857397,71 81 | 93890,32.346165,34.857425,72 82 | 93890,32.346195,34.857434,73 83 | 93890,32.346228,34.857524,74 84 | 93890,32.346258,34.857644,75 85 | 93890,32.346285,34.857936,76 86 | 93890,32.346278,34.858281,77 87 | 93890,32.346193,34.859343,78 88 | 93890,32.346157,34.859705,79 89 | 93890,32.346097,34.860128,80 90 | 93890,32.346062,34.860262,81 91 | 93890,32.346007,34.860443,82 92 | 93890,32.345931,34.860599,83 93 | 93890,32.345796,34.860821,84 94 | 93890,32.345554,34.861167,85 95 | 93890,32.345230,34.861707,86 96 | 93890,32.345182,34.861863,87 97 | 93890,32.345137,34.862091,88 98 | 93890,32.345088,34.862431,89 99 | 93890,32.344711,34.862392,90 100 | 93890,32.344474,34.862366,91 101 | 93890,32.344184,34.862327,92 102 | 93890,32.343854,34.862274,93 103 | 93890,32.343527,34.862229,94 104 | 93890,32.343307,34.862192,95 105 | 93890,32.342727,34.862104,96 106 | 93890,32.341935,34.861973,97 107 | 93890,32.342107,34.860369,98 108 | 93890,32.342115,34.860245,99 109 | 93890,32.342018,34.860233,100 110 | 93890,32.341832,34.860211,101 111 | 93890,32.341423,34.860162,102 112 | 93890,32.340576,34.860012,103 113 | 93890,32.338986,34.859769,104 114 | 93890,32.338758,34.859735,105 115 | 93890,32.338155,34.859656,106 116 | 93890,32.337927,34.859625,107 117 | 93890,32.337561,34.859582,108 118 | 93890,32.337285,34.859553,109 119 | 93890,32.336833,34.859505,110 120 | 93890,32.336127,34.859432,111 121 | 93890,32.335126,34.859322,112 122 | 93890,32.335036,34.859312,113 123 | 93890,32.334515,34.859242,114 124 | 93890,32.333625,34.859148,115 125 | 93890,32.333020,34.859069,116 126 | 93890,32.332907,34.859055,117 127 | 93890,32.332387,34.859011,118 128 | 93890,32.331902,34.858962,119 129 | 93890,32.331735,34.858945,120 130 | 93890,32.331640,34.858936,121 131 | 93890,32.331083,34.858888,122 132 | 93890,32.330878,34.858871,123 133 | 93890,32.330518,34.858832,124 134 | 93890,32.330411,34.858821,125 135 | 93890,32.330072,34.858784,126 136 | 93890,32.330005,34.858777,127 137 | 93890,32.329537,34.858730,128 138 | 93890,32.329452,34.858708,129 139 | 93890,32.329399,34.858693,130 140 | 93890,32.329171,34.858632,131 141 | 93890,32.329154,34.858625,132 142 | 93890,32.328799,34.858496,133 143 | 93890,32.328502,34.858372,134 144 | 93890,32.328246,34.858264,135 145 | 93890,32.328216,34.858252,136 146 | 93890,32.328169,34.858299,137 147 | 93890,32.328147,34.858366,138 148 | 93890,32.327893,34.859095,139 149 | 93890,32.327552,34.858947,140 150 | 93890,32.327530,34.858921,141 151 | 93890,32.327495,34.858881,142 152 | -------------------------------------------------------------------------------- /tests/fixtures/seattle-area-2017-11-16/calendar_dates.txt: -------------------------------------------------------------------------------- 1 | service_id,date,exception_type 2 | 86972,20180101,2 3 | 86972,20171225,2 4 | 86972,20180219,2 5 | 86972,20180115,2 6 | 86972,20180108,1 7 | 86972,20180305,1 8 | 86972,20180226,1 9 | 86972,20171218,1 10 | 86972,20171211,1 11 | 86972,20180205,1 12 | 86972,20171127,1 13 | 86972,20180212,1 14 | 86972,20171204,1 15 | 86972,20180129,1 16 | 86972,20171120,1 17 | 86972,20180122,1 18 | 86972,20171123,2 19 | 86972,20180104,1 20 | 86972,20180301,1 21 | 86972,20171221,1 22 | 86972,20180308,1 23 | 86972,20171228,1 24 | 86972,20180222,1 25 | 86972,20171214,1 26 | 86972,20180208,1 27 | 86972,20180215,1 28 | 86972,20171207,1 29 | 86972,20180201,1 30 | 86972,20171130,1 31 | 86972,20180125,1 32 | 86972,20180111,1 33 | 86972,20180118,1 34 | 85068,20180101,2 35 | 85068,20171225,2 36 | 85068,20180219,2 37 | 85068,20180115,2 38 | 85068,20180108,1 39 | 85068,20180305,1 40 | 85068,20180226,1 41 | 85068,20171218,1 42 | 85068,20171211,1 43 | 85068,20180205,1 44 | 85068,20171127,1 45 | 85068,20180212,1 46 | 85068,20171204,1 47 | 85068,20180129,1 48 | 85068,20171120,1 49 | 85068,20180122,1 50 | 85068,20171123,2 51 | 85068,20180104,1 52 | 85068,20180301,1 53 | 85068,20171221,1 54 | 85068,20180308,1 55 | 85068,20171228,1 56 | 85068,20180222,1 57 | 85068,20171214,1 58 | 85068,20180208,1 59 | 85068,20180215,1 60 | 85068,20171207,1 61 | 85068,20180201,1 62 | 85068,20171130,1 63 | 85068,20180125,1 64 | 85068,20180111,1 65 | 85068,20180118,1 66 | 85068,20171124,2 67 | 85068,20180112,1 68 | 85068,20180119,1 69 | 85068,20180105,1 70 | 85068,20180302,1 71 | 85068,20171222,1 72 | 85068,20180309,1 73 | 85068,20171229,1 74 | 85068,20180223,1 75 | 85068,20171215,1 76 | 85068,20180209,1 77 | 85068,20180216,1 78 | 85068,20171208,1 79 | 85068,20180202,1 80 | 85068,20171201,1 81 | 85068,20180126,1 82 | 71310,20180101,2 83 | 71310,20171225,2 84 | 71310,20180219,2 85 | 71310,20180115,2 86 | 71310,20180108,1 87 | 71310,20180305,1 88 | 71310,20180226,1 89 | 71310,20171218,1 90 | 71310,20171211,1 91 | 71310,20180205,1 92 | 71310,20171127,1 93 | 71310,20180212,1 94 | 71310,20171204,1 95 | 71310,20180129,1 96 | 71310,20171120,1 97 | 71310,20180122,1 98 | 71310,20171123,2 99 | 71310,20180104,1 100 | 71310,20180301,1 101 | 71310,20171221,1 102 | 71310,20180308,1 103 | 71310,20171228,1 104 | 71310,20180222,1 105 | 71310,20171214,1 106 | 71310,20180208,1 107 | 71310,20180215,1 108 | 71310,20171207,1 109 | 71310,20180201,1 110 | 71310,20171130,1 111 | 71310,20180125,1 112 | 71310,20180111,1 113 | 71310,20180118,1 114 | 71310,20180112,2 115 | 71310,20180119,2 116 | 71310,20180105,2 117 | 71310,20180302,2 118 | 71310,20171222,2 119 | 71310,20171229,2 120 | 71310,20180223,2 121 | 71310,20171215,2 122 | 71310,20180209,2 123 | 71310,20180216,2 124 | 71310,20171208,2 125 | 71310,20180202,2 126 | 71310,20171201,2 127 | 71310,20180126,2 128 | 71310,20171124,1 129 | 18623,20180108,2 130 | 18623,20180226,2 131 | 18623,20171218,2 132 | 18623,20171211,2 133 | 18623,20180205,2 134 | 18623,20171127,2 135 | 18623,20180212,2 136 | 18623,20171204,2 137 | 18623,20180129,2 138 | 18623,20171120,2 139 | 18623,20180122,2 140 | 18623,20180219,1 141 | 18623,20180101,1 142 | 18623,20171225,1 143 | 18623,20180115,1 144 | 18623,20180104,2 145 | 18623,20180301,2 146 | 18623,20171221,2 147 | 18623,20171228,2 148 | 18623,20180222,2 149 | 18623,20171214,2 150 | 18623,20180208,2 151 | 18623,20180215,2 152 | 18623,20171207,2 153 | 18623,20180201,2 154 | 18623,20171130,2 155 | 18623,20180125,2 156 | 18623,20180111,2 157 | 18623,20180118,2 158 | 18623,20171123,1 159 | 17730,20180108,2 160 | 17730,20180226,2 161 | 17730,20171218,2 162 | 17730,20180219,2 163 | 17730,20171211,2 164 | 17730,20180205,2 165 | 17730,20171127,2 166 | 17730,20180212,2 167 | 17730,20171204,2 168 | 17730,20180129,2 169 | 17730,20171120,2 170 | 17730,20180115,2 171 | 17730,20180122,2 172 | 17730,20180101,1 173 | 17730,20171225,1 174 | 17730,20180104,2 175 | 17730,20180301,2 176 | 17730,20171221,2 177 | 17730,20171228,2 178 | 17730,20180222,2 179 | 17730,20171214,2 180 | 17730,20180208,2 181 | 17730,20180215,2 182 | 17730,20171207,2 183 | 17730,20180201,2 184 | 17730,20171130,2 185 | 17730,20180125,2 186 | 17730,20180111,2 187 | 17730,20180118,2 188 | 17730,20171123,1 189 | 17133,20180108,2 190 | 17133,20180101,2 191 | 17133,20180226,2 192 | 17133,20171218,2 193 | 17133,20171225,2 194 | 17133,20171211,2 195 | 17133,20180205,2 196 | 17133,20171127,2 197 | 17133,20180212,2 198 | 17133,20171204,2 199 | 17133,20180129,2 200 | 17133,20171120,2 201 | 17133,20180122,2 202 | 17133,20180219,1 203 | 17133,20180115,1 204 | 17133,20180112,2 205 | 17133,20180119,2 206 | 17133,20180105,2 207 | 17133,20180302,2 208 | 17133,20171222,2 209 | 17133,20171229,2 210 | 17133,20180223,2 211 | 17133,20171215,2 212 | 17133,20180209,2 213 | 17133,20180216,2 214 | 17133,20171208,2 215 | 17133,20180202,2 216 | 17133,20171201,2 217 | 17133,20180126,2 218 | 17133,20171124,1 219 | 16001,20180108,2 220 | 16001,20180226,2 221 | 16001,20171218,2 222 | 16001,20171225,2 223 | 16001,20171211,2 224 | 16001,20180205,2 225 | 16001,20171127,2 226 | 16001,20180212,2 227 | 16001,20171204,2 228 | 16001,20180129,2 229 | 16001,20171120,2 230 | 16001,20180122,2 231 | 16001,20180219,1 232 | 16001,20180101,1 233 | 16001,20180115,1 234 | 893,20180212,2 235 | 893,20180205,2 236 | 893,20180129,2 237 | 893,20180122,2 238 | 893,20180219,1 239 | 893,20180115,1 240 | -------------------------------------------------------------------------------- /tests/test_readers.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | import numpy as np 4 | import partridge as ptg 5 | import pytest 6 | 7 | from .helpers import fixture, zip_file 8 | 9 | 10 | def test_load_feed(): 11 | feed = ptg.load_feed(fixture("amazon-2017-08-06")) 12 | assert feed.stop_times.dtypes["stop_id"] == object 13 | assert feed.stop_times.dtypes["stop_sequence"] == np.int64 14 | assert feed.stop_times.dtypes["arrival_time"] == np.float64 15 | 16 | 17 | def test_load_geo_feed(): 18 | gpd = pytest.importorskip("geopandas") 19 | 20 | feed = ptg.load_geo_feed(fixture("amazon-2017-08-06")) 21 | assert isinstance(feed.shapes, gpd.GeoDataFrame) 22 | assert isinstance(feed.stops, gpd.GeoDataFrame) 23 | assert {"LineString"} == set(feed.shapes.geom_type) 24 | assert {"Point"} == set(feed.stops.geom_type) 25 | assert feed.shapes.crs == {"init": "EPSG:4326"} 26 | assert feed.stops.crs == {"init": "EPSG:4326"} 27 | assert ["shape_id", "geometry"] == list(feed.shapes.columns) 28 | assert [ 29 | "stop_id", 30 | "stop_code", 31 | "stop_name", 32 | "stop_desc", 33 | "zone_id", 34 | "stop_url", 35 | "location_type", 36 | "parent_station", 37 | "stop_timezone", 38 | "wheelchair_boarding", 39 | "geometry", 40 | ] == list(feed.stops.columns) 41 | 42 | 43 | def test_load_geo_feed_empty(): 44 | gpd = pytest.importorskip("geopandas") 45 | 46 | feed = ptg.load_geo_feed(fixture("empty")) 47 | 48 | assert isinstance(feed.shapes, gpd.GeoDataFrame) 49 | assert isinstance(feed.stops, gpd.GeoDataFrame) 50 | assert feed.shapes.empty 51 | assert feed.stops.empty 52 | 53 | 54 | def test_missing_dir(): 55 | with pytest.raises(ValueError, match=r"File or path not found"): 56 | ptg.load_feed(fixture("missing")) 57 | 58 | 59 | def test_config_must_be_dag(): 60 | config = ptg.config.default_config() 61 | 62 | assert config.has_edge("routes.txt", "trips.txt") 63 | 64 | # Make a cycle 65 | config.add_edge("trips.txt", "routes.txt") 66 | 67 | path = fixture("amazon-2017-08-06") 68 | with pytest.raises(ValueError, match=r"Config must be a DAG"): 69 | ptg.load_feed(path, config=config) 70 | 71 | 72 | def test_no_service(): 73 | path = fixture("empty") 74 | with pytest.raises(AssertionError, match=r"No service"): 75 | ptg.read_service_ids_by_date(path) 76 | 77 | 78 | @pytest.mark.parametrize( 79 | "path", [zip_file("amazon-2017-08-06"), fixture("amazon-2017-08-06")] 80 | ) 81 | def test_service_ids_by_date(path): 82 | service_ids_by_date = ptg.read_service_ids_by_date(path) 83 | 84 | assert service_ids_by_date == { 85 | datetime.date(2017, 8, 1): frozenset({"1", "0"}), 86 | datetime.date(2017, 8, 2): frozenset({"1", "0"}), 87 | datetime.date(2017, 8, 3): frozenset({"1", "0"}), 88 | datetime.date(2017, 8, 4): frozenset({"1", "0"}), 89 | datetime.date(2017, 8, 5): frozenset({"1"}), 90 | datetime.date(2017, 8, 7): frozenset({"1", "0"}), 91 | } 92 | 93 | 94 | def test_unused_service_ids(): 95 | # Feed has rows in calendar.txt and calendar_dates.txt 96 | # with `service_id`s that have no applicable trips 97 | path = fixture("trimet-vermont-2018-02-06") 98 | ptg.read_service_ids_by_date(path) 99 | 100 | 101 | def test_missing_calendar_dates(): 102 | path = fixture("israel-public-transportation-route-2126") 103 | ptg.read_service_ids_by_date(path) 104 | 105 | 106 | @pytest.mark.parametrize( 107 | "path", [zip_file("amazon-2017-08-06"), fixture("amazon-2017-08-06")] 108 | ) 109 | def test_dates_by_service_ids(path): 110 | dates_by_service_ids = ptg.read_dates_by_service_ids(path) 111 | 112 | assert dates_by_service_ids == { 113 | frozenset({"1"}): {datetime.date(2017, 8, 5)}, 114 | frozenset({"1", "0"}): { 115 | datetime.date(2017, 8, 1), 116 | datetime.date(2017, 8, 2), 117 | datetime.date(2017, 8, 3), 118 | datetime.date(2017, 8, 4), 119 | datetime.date(2017, 8, 7), 120 | }, 121 | } 122 | 123 | 124 | @pytest.mark.parametrize( 125 | "path", [zip_file("amazon-2017-08-06"), fixture("amazon-2017-08-06")] 126 | ) 127 | def test_trip_counts_by_date(path): 128 | trip_counts_by_date = ptg.read_trip_counts_by_date(path) 129 | 130 | assert trip_counts_by_date == { 131 | datetime.date(2017, 8, 1): 442, 132 | datetime.date(2017, 8, 2): 442, 133 | datetime.date(2017, 8, 3): 442, 134 | datetime.date(2017, 8, 4): 442, 135 | datetime.date(2017, 8, 5): 1, 136 | datetime.date(2017, 8, 7): 442, 137 | } 138 | 139 | 140 | @pytest.mark.parametrize( 141 | "path", [zip_file("amazon-2017-08-06"), fixture("amazon-2017-08-06")] 142 | ) 143 | def test_busiest_date(path): 144 | date, service_ids = ptg.read_busiest_date(path) 145 | assert date == datetime.date(2017, 8, 1) 146 | assert service_ids == frozenset({"0", "1"}) 147 | 148 | 149 | @pytest.mark.parametrize( 150 | "path", [zip_file("amazon-2017-08-06"), fixture("amazon-2017-08-06")] 151 | ) 152 | def test_busiest_week(path): 153 | service_ids_by_date = ptg.read_busiest_week(path) 154 | assert service_ids_by_date == { 155 | datetime.date(2017, 8, 1): frozenset({"0", "1"}), 156 | datetime.date(2017, 8, 2): frozenset({"0", "1"}), 157 | datetime.date(2017, 8, 3): frozenset({"0", "1"}), 158 | datetime.date(2017, 8, 4): frozenset({"0", "1"}), 159 | datetime.date(2017, 8, 5): frozenset({"1"}), 160 | } 161 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | History 3 | ======= 4 | 5 | 1.1.2 (2022-11-23) 6 | ------------------ 7 | 8 | Code changes: 9 | 10 | * Remove references to deprecated NumPy types (https://github.com/remix/partridge/pull/69 - thanks @BlackSpade741!) 11 | * Switch from `cChardet `_ to `charset-normalizer `_ for Python 3.10 support (https://github.com/remix/partridge/pull/76 - thanks @brockhaywood!) 12 | 13 | Other changes: 14 | 15 | * Miscellaneous improvements to tests, code formatting, and documentation (https://github.com/remix/partridge/pull/61 - thanks @invisiblefunnel!) 16 | * Relocate usage examples from wiki to README (https://github.com/remix/partridge/pull/70 - thanks @landonreed!) 17 | * README tweaks (https://github.com/remix/partridge/pull/74 - thanks @chelsey!) 18 | * Use GitHub Actions for automated testing (https://github.com/remix/partridge/pull/79 - thanks @dget!). **Note:** we now test against Python versions 3.8, 3.9, 3.10, and 3.11. 19 | 20 | 21 | 1.1.1 (2019-09-13) 22 | ------------------ 23 | 24 | * Improve file encoding sniffer, which was misidentifying some Finnish/emoji unicode. Thanks to @dyakovlev! 25 | 26 | 27 | 1.1.0 (2019-02-21) 28 | ------------------ 29 | 30 | * Add ``partridge.load_geo_feed`` for reading stops and shapes into GeoPandas GeoDataFrames. 31 | 32 | 33 | 1.0.0 (2018-12-18) 34 | ------------------ 35 | 36 | This release is a combination of major internal refactorings and some minor interface changes. Overall, you should expect your upgrade from pre-1.0 versions to be relatively painless. A big thank you to @genhernandez and @csb19815 for their valuable design feedback. If you still need Python 2 support, please continue using version 0.11.0. 37 | 38 | Here is a list of interface changes: 39 | 40 | * The class ``partridge.gtfs.feed`` has been renamed to ``partridge.gtfs.Feed``. 41 | * The public interface for instantiating feeds is ``partridge.load_feed``. This function replaces the previously undocumented function ``partridge.get_filtered_feed``. 42 | * A new function has been added for identifying the busiest week in a feed: ``partridge.read_busiest_date`` 43 | * The public function ``partridge.get_representative_feed`` has been removed in favor of using ``partridge.read_busiest_date`` directly. 44 | * The public function ``partridge.writers.extract_feed`` is now available via the top level module: ``partridge.extract_feed``. 45 | 46 | Miscellaneous minor changes: 47 | 48 | * Character encoding detection is now done by the ``cchardet`` package instead of ``chardet``. ``cchardet`` is faster, but may not always return the same result as ``chardet``. 49 | * Zip files are unpacked into a temporary directory instead of reading directly from the zip. These temporary directories are cleaned up when the feed is garbage collected or when the process exits. 50 | * The code base is now annotated with type hints and the build runs ``mypy`` to verify the types. 51 | * DataFrames are cached in a dictionary instead of the ``functools.lru_cache`` decorator. 52 | * The ``partridge.extract_feed`` function now writes files concurrently to improve performance. 53 | 54 | 55 | 0.11.0 (2018-08-01) 56 | ------------------- 57 | 58 | * Fix major performance issue related to encoding detection. Thank you to @cjer for reporting the issue and advising on a solution. 59 | 60 | 61 | 0.10.0 (2018-04-30) 62 | ------------------- 63 | 64 | * Improved handling of non-standard compliant file encodings 65 | * Only require functools32 for Python < 3 66 | * ``ptg.parsers.parse_date`` no longer accepts dates, only strings 67 | 68 | 69 | 0.9.0 (2018-03-24) 70 | ------------------ 71 | 72 | * Improves read time for large feeds by adding LRU caching to ``ptg.parsers.parse_time``. 73 | 74 | 75 | 0.8.0 (2018-03-14) 76 | ------------------ 77 | 78 | * Gracefully handle completely empty files. This change unifies the behavior of reading from a CSV with a header only (no data rows) and a completely empty (zero bytes) file in the zip. 79 | 80 | 81 | 0.7.0 (2018-03-09) 82 | ------------------ 83 | 84 | * Fix handling of nested folders and zip containing nested folders. 85 | * Add ``ptg.get_filtered_feed`` for multi-file filtering. 86 | 87 | 88 | 0.6.1 (2018-02-24) 89 | ------------------ 90 | 91 | * Fix bug in ``ptg.read_service_ids_by_date``. Reported by @cjer in #27. 92 | 93 | 94 | 0.6.0 (2018-02-21) 95 | ------------------ 96 | 97 | * Published package no longer includes unnecessary fixtures to reduce the size. 98 | * Naively write a feed object to a zip file with ``ptg.write_feed_dangerously``. 99 | * Read the earliest, busiest date and its ``service_id``'s from a feed with ``ptg.read_busiest_date``. 100 | * Bug fix: Handle ``calendar.txt``/``calendar_dates.txt`` entries w/o applicable trips. 101 | 102 | 103 | 0.6.0.dev1 (2018-01-23) 104 | ----------------------- 105 | 106 | * Add support for reading files from a folder. Thanks again @danielsclint! 107 | 108 | 109 | 0.5.0 (2017-12-22) 110 | ------------------ 111 | 112 | * Easily build a representative view of a zip with ``ptg.get_representative_feed``. Inspired by `peartree `_. 113 | * Extract out GTFS zips by agency_id/route_id with ``ptg.extract_{agencies,routes}``. 114 | * Read arbitrary files from a zip with ``feed.get('myfile.txt')``. 115 | * Remove ``service_ids_by_date``, ``dates_by_service_ids``, and ``trip_counts_by_date`` from the feed class. Instead use ``ptg.{read_service_ids_by_date,read_dates_by_service_ids,read_trip_counts_by_date}``. 116 | 117 | 118 | 0.4.0 (2017-12-10) 119 | ------------------ 120 | 121 | * Add support for Python 2.7. Thanks @danielsclint! 122 | 123 | 124 | 0.3.0 (2017-10-12) 125 | ------------------ 126 | 127 | * Fix service date resolution for raw_feed. Previously raw_feed considered all days of the week from calendar.txt to be active regardless of 0/1 value. 128 | 129 | 130 | 0.2.0 (2017-09-30) 131 | ------------------ 132 | 133 | * Add missing edge from fare_rules.txt to routes.txt in default dependency graph. 134 | 135 | 136 | 0.1.0 (2017-09-23) 137 | ------------------ 138 | 139 | * First release on PyPI. 140 | -------------------------------------------------------------------------------- /partridge/gtfs.py: -------------------------------------------------------------------------------- 1 | import os 2 | from threading import RLock 3 | from typing import Dict, Optional, Union 4 | 5 | import networkx as nx 6 | import pandas as pd 7 | 8 | from .config import default_config 9 | from .types import View 10 | from .utilities import detect_encoding, empty_df, setwrap 11 | 12 | 13 | def _read_file(filename: str) -> property: 14 | def getter(self) -> pd.DataFrame: 15 | return self.get(filename) 16 | 17 | return property(getter) 18 | 19 | 20 | class Feed(object): 21 | def __init__( 22 | self, 23 | source: Union[str, "Feed"], 24 | view: Optional[View] = None, 25 | config: Optional[nx.DiGraph] = None, 26 | ): 27 | self._config: nx.DiGraph = default_config() if config is None else config 28 | self._view: View = {} if view is None else view 29 | self._cache: Dict[str, pd.DataFrame] = {} 30 | self._pathmap: Dict[str, str] = {} 31 | self._delete_after_reading: bool = False 32 | self._shared_lock = RLock() 33 | self._locks: Dict[str, RLock] = {} 34 | if isinstance(source, self.__class__): 35 | self._read = source.get 36 | elif isinstance(source, str) and os.path.isdir(source): 37 | self._read = self._read_csv 38 | self._bootstrap(source) 39 | else: 40 | raise ValueError("Invalid source") 41 | 42 | def get(self, filename: str) -> pd.DataFrame: 43 | lock = self._locks.get(filename, self._shared_lock) 44 | with lock: 45 | df = self._cache.get(filename) 46 | if df is None: 47 | df = self._read(filename) 48 | df = self._filter(filename, df) 49 | df = self._prune(filename, df) 50 | self._convert_types(filename, df) 51 | df = df.reset_index(drop=True) 52 | df = self._transform(filename, df) 53 | self.set(filename, df) 54 | return self._cache[filename] 55 | 56 | def set(self, filename: str, df: pd.DataFrame) -> None: 57 | lock = self._locks.get(filename, self._shared_lock) 58 | with lock: 59 | self._cache[filename] = df 60 | 61 | agency = _read_file("agency.txt") 62 | calendar = _read_file("calendar.txt") 63 | calendar_dates = _read_file("calendar_dates.txt") 64 | fare_attributes = _read_file("fare_attributes.txt") 65 | fare_rules = _read_file("fare_rules.txt") 66 | feed_info = _read_file("feed_info.txt") 67 | frequencies = _read_file("frequencies.txt") 68 | routes = _read_file("routes.txt") 69 | shapes = _read_file("shapes.txt") 70 | stops = _read_file("stops.txt") 71 | stop_times = _read_file("stop_times.txt") 72 | transfers = _read_file("transfers.txt") 73 | trips = _read_file("trips.txt") 74 | 75 | def _bootstrap(self, path: str) -> None: 76 | # Walk recursively through the directory 77 | for root, _subdirs, files in os.walk(path): 78 | for fname in files: 79 | basename = os.path.basename(fname) 80 | if basename in self._pathmap: 81 | # Verify that the folder does not contain multiple files of the same name. 82 | raise ValueError("More than one {} in folder".format(basename)) 83 | # Index paths by their basename. 84 | self._pathmap[basename] = os.path.join(root, fname) 85 | # Build a lock for each file to synchronize reads. 86 | self._locks[basename] = RLock() 87 | 88 | def _read_csv(self, filename: str) -> pd.DataFrame: 89 | path = self._pathmap.get(filename) 90 | columns = self._config.nodes.get(filename, {}).get("required_columns", []) 91 | 92 | if path is None or os.path.getsize(path) == 0: 93 | # The file is missing or empty. Return an empty 94 | # DataFrame containing any required columns. 95 | return empty_df(columns) 96 | 97 | # If the file isn't in the zip, return an empty DataFrame. 98 | with open(path, "rb") as f: 99 | encoding = detect_encoding(f) 100 | 101 | df = pd.read_csv(path, dtype=str, encoding=encoding, index_col=False) 102 | 103 | # Strip leading/trailing whitespace from column names 104 | df.rename(columns=lambda x: x.strip(), inplace=True) 105 | 106 | if not df.empty: 107 | # Strip leading/trailing whitespace from column values 108 | for col in df.columns: 109 | df[col] = df[col].str.strip() 110 | 111 | return df 112 | 113 | def _filter(self, filename: str, df: pd.DataFrame) -> pd.DataFrame: 114 | """Apply view filters""" 115 | view = self._view.get(filename) 116 | if view is None: 117 | return df 118 | 119 | for col, values in view.items(): 120 | # If applicable, filter this dataframe by the given set of values 121 | if col in df.columns: 122 | df = df[df[col].isin(setwrap(values))] 123 | 124 | return df 125 | 126 | def _prune(self, filename: str, df: pd.DataFrame) -> pd.DataFrame: 127 | """Depth-first search through the dependency graph 128 | and prune dependent DataFrames along the way. 129 | """ 130 | dependencies = [] 131 | for _, depf, data in self._config.out_edges(filename, data=True): 132 | deps = data.get("dependencies") 133 | if deps is None: 134 | msg = f"Edge missing `dependencies` attribute: {filename}->{depf}" 135 | raise ValueError(msg) 136 | dependencies.append((depf, deps)) 137 | 138 | if not dependencies: 139 | return df 140 | 141 | for depfile, column_pairs in dependencies: 142 | # Read the filtered, cached file dependency 143 | depdf = self.get(depfile) 144 | for deps in column_pairs: 145 | col = deps[filename] 146 | depcol = deps[depfile] 147 | # If applicable, prune this dataframe by the other 148 | if col in df.columns and depcol in depdf.columns: 149 | df = df[df[col].isin(depdf[depcol])] 150 | 151 | return df 152 | 153 | def _convert_types(self, filename: str, df: pd.DataFrame) -> None: 154 | """ 155 | Apply type conversions 156 | """ 157 | if df.empty: 158 | return 159 | 160 | converters = self._config.nodes.get(filename, {}).get("converters", {}) 161 | for col, converter in converters.items(): 162 | if col in df.columns: 163 | df[col] = converter(df[col]) 164 | 165 | def _transform(self, filename: str, df: pd.DataFrame) -> pd.DataFrame: 166 | transformations = self._config.nodes.get(filename, {}).get( 167 | "transformations", [] 168 | ) 169 | 170 | for transform in transformations: 171 | df = transform(df) 172 | 173 | return df 174 | -------------------------------------------------------------------------------- /tests/fixtures/region-nord-v2/calendar_dates.txt: -------------------------------------------------------------------------------- 1 | service_id,date,exception_type 2 | 0004,20190101,1 3 | 0004,20190106,1 4 | 0004,20190113,1 5 | 0004,20190120,1 6 | 0004,20190127,1 7 | 0005,20190105,1 8 | 0005,20190112,1 9 | 0005,20190119,1 10 | 0005,20190126,1 11 | 0006,20190104,1 12 | 0006,20190111,1 13 | 0006,20190118,1 14 | 0006,20190125,1 15 | 0006,20190201,1 16 | 0007,20190103,1 17 | 0007,20190110,1 18 | 0007,20190117,1 19 | 0007,20190124,1 20 | 0007,20190131,1 21 | 0008,20190103,1 22 | 0008,20190104,1 23 | 0008,20190110,1 24 | 0008,20190111,1 25 | 0008,20190117,1 26 | 0008,20190118,1 27 | 0008,20190124,1 28 | 0008,20190125,1 29 | 0008,20190131,1 30 | 0008,20190201,1 31 | 0009,20190102,1 32 | 0009,20190109,1 33 | 0009,20190116,1 34 | 0009,20190123,1 35 | 0009,20190130,1 36 | 0010,20190102,1 37 | 0010,20190104,1 38 | 0010,20190109,1 39 | 0010,20190111,1 40 | 0010,20190116,1 41 | 0010,20190118,1 42 | 0010,20190123,1 43 | 0010,20190125,1 44 | 0010,20190130,1 45 | 0010,20190201,1 46 | 0011,20190102,1 47 | 0011,20190103,1 48 | 0011,20190109,1 49 | 0011,20190110,1 50 | 0011,20190116,1 51 | 0011,20190117,1 52 | 0011,20190123,1 53 | 0011,20190124,1 54 | 0011,20190130,1 55 | 0011,20190131,1 56 | 0012,20190102,1 57 | 0012,20190103,1 58 | 0012,20190104,1 59 | 0012,20190109,1 60 | 0012,20190110,1 61 | 0012,20190111,1 62 | 0012,20190116,1 63 | 0012,20190117,1 64 | 0012,20190118,1 65 | 0012,20190123,1 66 | 0012,20190124,1 67 | 0012,20190125,1 68 | 0012,20190130,1 69 | 0012,20190131,1 70 | 0012,20190201,1 71 | 0013,20190108,1 72 | 0013,20190115,1 73 | 0013,20190122,1 74 | 0013,20190129,1 75 | 0014,20190104,1 76 | 0014,20190108,1 77 | 0014,20190111,1 78 | 0014,20190115,1 79 | 0014,20190118,1 80 | 0014,20190122,1 81 | 0014,20190125,1 82 | 0014,20190129,1 83 | 0014,20190201,1 84 | 0015,20190103,1 85 | 0015,20190108,1 86 | 0015,20190110,1 87 | 0015,20190115,1 88 | 0015,20190117,1 89 | 0015,20190122,1 90 | 0015,20190124,1 91 | 0015,20190129,1 92 | 0015,20190131,1 93 | 0016,20190103,1 94 | 0016,20190104,1 95 | 0016,20190108,1 96 | 0016,20190110,1 97 | 0016,20190111,1 98 | 0016,20190115,1 99 | 0016,20190117,1 100 | 0016,20190118,1 101 | 0016,20190122,1 102 | 0016,20190124,1 103 | 0016,20190125,1 104 | 0016,20190129,1 105 | 0016,20190131,1 106 | 0016,20190201,1 107 | 0017,20190102,1 108 | 0017,20190108,1 109 | 0017,20190109,1 110 | 0017,20190115,1 111 | 0017,20190116,1 112 | 0017,20190122,1 113 | 0017,20190123,1 114 | 0017,20190129,1 115 | 0017,20190130,1 116 | 0018,20190102,1 117 | 0018,20190103,1 118 | 0018,20190108,1 119 | 0018,20190109,1 120 | 0018,20190110,1 121 | 0018,20190115,1 122 | 0018,20190116,1 123 | 0018,20190117,1 124 | 0018,20190122,1 125 | 0018,20190123,1 126 | 0018,20190124,1 127 | 0018,20190129,1 128 | 0018,20190130,1 129 | 0018,20190131,1 130 | 0019,20190102,1 131 | 0019,20190103,1 132 | 0019,20190104,1 133 | 0019,20190108,1 134 | 0019,20190109,1 135 | 0019,20190110,1 136 | 0019,20190111,1 137 | 0019,20190115,1 138 | 0019,20190116,1 139 | 0019,20190117,1 140 | 0019,20190118,1 141 | 0019,20190122,1 142 | 0019,20190123,1 143 | 0019,20190124,1 144 | 0019,20190125,1 145 | 0019,20190129,1 146 | 0019,20190130,1 147 | 0019,20190131,1 148 | 0019,20190201,1 149 | 0020,20190107,1 150 | 0020,20190114,1 151 | 0020,20190121,1 152 | 0020,20190128,1 153 | 0021,20190104,1 154 | 0021,20190107,1 155 | 0021,20190111,1 156 | 0021,20190114,1 157 | 0021,20190118,1 158 | 0021,20190121,1 159 | 0021,20190125,1 160 | 0021,20190128,1 161 | 0021,20190201,1 162 | 0022,20190103,1 163 | 0022,20190104,1 164 | 0022,20190107,1 165 | 0022,20190110,1 166 | 0022,20190111,1 167 | 0022,20190114,1 168 | 0022,20190117,1 169 | 0022,20190118,1 170 | 0022,20190121,1 171 | 0022,20190124,1 172 | 0022,20190125,1 173 | 0022,20190128,1 174 | 0022,20190131,1 175 | 0022,20190201,1 176 | 0023,20190102,1 177 | 0023,20190107,1 178 | 0023,20190109,1 179 | 0023,20190114,1 180 | 0023,20190116,1 181 | 0023,20190121,1 182 | 0023,20190123,1 183 | 0023,20190128,1 184 | 0023,20190130,1 185 | 0024,20190102,1 186 | 0024,20190104,1 187 | 0024,20190107,1 188 | 0024,20190109,1 189 | 0024,20190111,1 190 | 0024,20190114,1 191 | 0024,20190116,1 192 | 0024,20190118,1 193 | 0024,20190121,1 194 | 0024,20190123,1 195 | 0024,20190125,1 196 | 0024,20190128,1 197 | 0024,20190130,1 198 | 0024,20190201,1 199 | 0025,20190102,1 200 | 0025,20190103,1 201 | 0025,20190107,1 202 | 0025,20190109,1 203 | 0025,20190110,1 204 | 0025,20190114,1 205 | 0025,20190116,1 206 | 0025,20190117,1 207 | 0025,20190121,1 208 | 0025,20190123,1 209 | 0025,20190124,1 210 | 0025,20190128,1 211 | 0025,20190130,1 212 | 0025,20190131,1 213 | 0026,20190102,1 214 | 0026,20190103,1 215 | 0026,20190104,1 216 | 0026,20190107,1 217 | 0026,20190109,1 218 | 0026,20190110,1 219 | 0026,20190111,1 220 | 0026,20190114,1 221 | 0026,20190116,1 222 | 0026,20190117,1 223 | 0026,20190118,1 224 | 0026,20190121,1 225 | 0026,20190123,1 226 | 0026,20190124,1 227 | 0026,20190125,1 228 | 0026,20190128,1 229 | 0026,20190130,1 230 | 0026,20190131,1 231 | 0026,20190201,1 232 | 0027,20190103,1 233 | 0027,20190107,1 234 | 0027,20190108,1 235 | 0027,20190110,1 236 | 0027,20190114,1 237 | 0027,20190115,1 238 | 0027,20190117,1 239 | 0027,20190121,1 240 | 0027,20190122,1 241 | 0027,20190124,1 242 | 0027,20190128,1 243 | 0027,20190129,1 244 | 0027,20190131,1 245 | 0028,20190103,1 246 | 0028,20190104,1 247 | 0028,20190107,1 248 | 0028,20190108,1 249 | 0028,20190110,1 250 | 0028,20190111,1 251 | 0028,20190114,1 252 | 0028,20190115,1 253 | 0028,20190117,1 254 | 0028,20190118,1 255 | 0028,20190121,1 256 | 0028,20190122,1 257 | 0028,20190124,1 258 | 0028,20190125,1 259 | 0028,20190128,1 260 | 0028,20190129,1 261 | 0028,20190131,1 262 | 0028,20190201,1 263 | 0029,20190102,1 264 | 0029,20190107,1 265 | 0029,20190108,1 266 | 0029,20190109,1 267 | 0029,20190114,1 268 | 0029,20190115,1 269 | 0029,20190116,1 270 | 0029,20190121,1 271 | 0029,20190122,1 272 | 0029,20190123,1 273 | 0029,20190128,1 274 | 0029,20190129,1 275 | 0029,20190130,1 276 | 0030,20190102,1 277 | 0030,20190104,1 278 | 0030,20190107,1 279 | 0030,20190108,1 280 | 0030,20190109,1 281 | 0030,20190111,1 282 | 0030,20190114,1 283 | 0030,20190115,1 284 | 0030,20190116,1 285 | 0030,20190118,1 286 | 0030,20190121,1 287 | 0030,20190122,1 288 | 0030,20190123,1 289 | 0030,20190125,1 290 | 0030,20190128,1 291 | 0030,20190129,1 292 | 0030,20190130,1 293 | 0030,20190201,1 294 | 0031,20190102,1 295 | 0031,20190103,1 296 | 0031,20190107,1 297 | 0031,20190108,1 298 | 0031,20190109,1 299 | 0031,20190110,1 300 | 0031,20190114,1 301 | 0031,20190115,1 302 | 0031,20190116,1 303 | 0031,20190117,1 304 | 0031,20190121,1 305 | 0031,20190122,1 306 | 0031,20190123,1 307 | 0031,20190124,1 308 | 0031,20190128,1 309 | 0031,20190129,1 310 | 0031,20190130,1 311 | 0031,20190131,1 312 | 0032,20190102,1 313 | 0032,20190103,1 314 | 0032,20190104,1 315 | 0032,20190107,1 316 | 0032,20190108,1 317 | 0032,20190109,1 318 | 0032,20190110,1 319 | 0032,20190111,1 320 | 0032,20190114,1 321 | 0032,20190115,1 322 | 0032,20190116,1 323 | 0032,20190117,1 324 | 0032,20190118,1 325 | 0032,20190121,1 326 | 0032,20190122,1 327 | 0032,20190123,1 328 | 0032,20190124,1 329 | 0032,20190125,1 330 | 0032,20190128,1 331 | 0032,20190129,1 332 | 0032,20190130,1 333 | 0032,20190131,1 334 | 0032,20190201,1 335 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | Partridge 3 | ========= 4 | 5 | 6 | .. image:: https://img.shields.io/pypi/v/partridge.svg 7 | :target: https://pypi.python.org/pypi/partridge 8 | 9 | .. image:: https://img.shields.io/travis/remix/partridge.svg 10 | :target: https://travis-ci.org/remix/partridge 11 | 12 | 13 | Partridge is a Python 3.6+ library for working with `GTFS `__ feeds using `pandas `__ DataFrames. 14 | 15 | Partridge is heavily influenced by our experience at `Remix `__ analyzing and debugging every GTFS feed we could find. 16 | 17 | At the core of Partridge is a dependency graph rooted at ``trips.txt``. Disconnected data is pruned away according to this graph when reading the contents of a feed. 18 | 19 | Feeds can also be filtered to create a view specific to your needs. It's most common to filter a feed down to specific dates (``service_id``) or routes (``route_id``), but any field can be filtered. 20 | 21 | .. figure:: dependency-graph.png 22 | :alt: dependency graph 23 | 24 | 25 | Philosophy 26 | ---------- 27 | 28 | The design of Partridge is guided by the following principles: 29 | 30 | **As much as possible** 31 | 32 | - Favor speed 33 | - Allow for extension 34 | - Succeed lazily on expensive paths 35 | - Fail eagerly on inexpensive paths 36 | 37 | **As little as possible** 38 | 39 | - Do anything other than efficiently read GTFS files into DataFrames 40 | - Take an opinion on the GTFS spec 41 | 42 | 43 | Installation 44 | ------------ 45 | 46 | .. code:: console 47 | 48 | pip install partridge 49 | 50 | 51 | **GeoPandas support** 52 | 53 | .. code:: console 54 | 55 | pip install partridge[full] 56 | 57 | 58 | Usage 59 | ----- 60 | 61 | **Setup** 62 | 63 | .. code:: python 64 | 65 | import partridge as ptg 66 | 67 | inpath = 'path/to/caltrain-2017-07-24/' 68 | 69 | 70 | Examples 71 | -------- 72 | 73 | The following is a collection of gists containing Jupyter notebooks with transformations to GTFS feeds that may be useful for intake into software applications. 74 | 75 | * `Find the busiest week in a feed and reduce its file size `_ 76 | * `Combine routes by route_short_name `_ 77 | * `Merge GTFS with shapefile geometries `_ 78 | * `Merge multiple agencies into one `_ 79 | * `Rewrite a feed to clean up formatting issues `_ 80 | * `If a feed has stop_code, replace the contents of stop_id with the contents of stop_code `_ 81 | * `Diff the number of service hours in two feeds `_ 82 | * `Investigate the the distance in meters of each stop to the closest point on a shape `_ 83 | * `Convert frequencies.txt to an equivalent trips.txt `_ 84 | * `Calculate headway for a stop `_ 85 | 86 | 87 | Inspecting the calendar 88 | ~~~~~~~~~~~~~~~~~~~~~~~ 89 | 90 | 91 | **The date with the most trips** 92 | 93 | .. code:: python 94 | 95 | date, service_ids = ptg.read_busiest_date(inpath) 96 | # datetime.date(2017, 7, 17), frozenset({'CT-17JUL-Combo-Weekday-01'}) 97 | 98 | 99 | **The week with the most trips** 100 | 101 | 102 | .. code:: python 103 | 104 | service_ids_by_date = ptg.read_busiest_week(inpath) 105 | # {datetime.date(2017, 7, 17): frozenset({'CT-17JUL-Combo-Weekday-01'}), 106 | # datetime.date(2017, 7, 18): frozenset({'CT-17JUL-Combo-Weekday-01'}), 107 | # datetime.date(2017, 7, 19): frozenset({'CT-17JUL-Combo-Weekday-01'}), 108 | # datetime.date(2017, 7, 20): frozenset({'CT-17JUL-Combo-Weekday-01'}), 109 | # datetime.date(2017, 7, 21): frozenset({'CT-17JUL-Combo-Weekday-01'}), 110 | # datetime.date(2017, 7, 22): frozenset({'CT-17JUL-Caltrain-Saturday-03'}), 111 | # datetime.date(2017, 7, 23): frozenset({'CT-17JUL-Caltrain-Sunday-01'})} 112 | 113 | 114 | **Dates with active service** 115 | 116 | .. code:: python 117 | 118 | service_ids_by_date = ptg.read_service_ids_by_date(path) 119 | 120 | date, service_ids = min(service_ids_by_date.items()) 121 | # datetime.date(2017, 7, 15), frozenset({'CT-17JUL-Caltrain-Saturday-03'}) 122 | 123 | date, service_ids = max(service_ids_by_date.items()) 124 | # datetime.date(2019, 7, 20), frozenset({'CT-17JUL-Caltrain-Saturday-03'}) 125 | 126 | 127 | **Dates with identical service** 128 | 129 | 130 | .. code:: python 131 | 132 | dates_by_service_ids = ptg.read_dates_by_service_ids(inpath) 133 | 134 | busiest_date, busiest_service = ptg.read_busiest_date(inpath) 135 | dates = dates_by_service_ids[busiest_service] 136 | 137 | min(dates), max(dates) 138 | # datetime.date(2017, 7, 17), datetime.date(2019, 7, 19) 139 | 140 | 141 | Reading a feed 142 | ~~~~~~~~~~~~~~ 143 | 144 | 145 | .. code:: python 146 | 147 | _date, service_ids = ptg.read_busiest_date(inpath) 148 | 149 | view = { 150 | 'trips.txt': {'service_id': service_ids}, 151 | 'stops.txt': {'stop_name': 'Gilroy Caltrain'}, 152 | } 153 | 154 | feed = ptg.load_feed(path, view) 155 | 156 | 157 | **Read shapes and stops as GeoDataFrames** 158 | 159 | .. code:: python 160 | 161 | service_ids = ptg.read_busiest_date(inpath)[1] 162 | view = {'trips.txt': {'service_id': service_ids}} 163 | 164 | feed = ptg.load_geo_feed(path, view) 165 | 166 | feed.shapes.head() 167 | # shape_id geometry 168 | # 0 cal_gil_sf LINESTRING (-121.5661454200744 37.003512297983... 169 | # 1 cal_sf_gil LINESTRING (-122.3944115638733 37.776439059278... 170 | # 2 cal_sf_sj LINESTRING (-122.3944115638733 37.776439059278... 171 | # 3 cal_sf_tam LINESTRING (-122.3944115638733 37.776439059278... 172 | # 4 cal_sj_sf LINESTRING (-121.9031703472137 37.330157067882... 173 | 174 | minlon, minlat, maxlon, maxlat = feed.stops.total_bounds 175 | # -122.412076, 37.003485, -121.566088, 37.77639 176 | 177 | 178 | Extracting a new feed 179 | ~~~~~~~~~~~~~~~~~~~~~ 180 | 181 | .. code:: python 182 | 183 | outpath = 'gtfs-slim.zip' 184 | 185 | service_ids = ptg.read_busiest_date(inpath)[1] 186 | view = {'trips.txt': {'service_id': service_ids}} 187 | 188 | ptg.extract_feed(inpath, outpath, view) 189 | feed = ptg.load_feed(outpath) 190 | 191 | assert service_ids == set(feed.trips.service_id) 192 | 193 | 194 | Features 195 | -------- 196 | 197 | - Surprisingly fast :) 198 | - Load only what you need into memory 199 | - Built-in support for resolving service dates 200 | - Easily extended to support fields and files outside the official spec 201 | (TODO: document this) 202 | - Handle nested folders and bad data in zips 203 | - Predictable type conversions 204 | 205 | Thank You 206 | --------- 207 | 208 | I hope you find this library useful. If you have suggestions for 209 | improving Partridge, please open an `issue on 210 | GitHub `__. 211 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/partridge.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/partridge.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/partridge" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/partridge" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\partridge.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\partridge.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /tests/test_feed.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import pytest 3 | 4 | import partridge as ptg 5 | from partridge.config import default_config, empty_config 6 | from partridge.gtfs import Feed 7 | 8 | from .helpers import fixture, fixtures_dir 9 | 10 | 11 | def test_invalid_source(): 12 | with pytest.raises(ValueError, match=r"Invalid source"): 13 | Feed(fixture("missing")) 14 | 15 | 16 | def test_duplicate_files(): 17 | with pytest.raises(ValueError, match=r"More than one"): 18 | Feed(fixtures_dir) 19 | 20 | 21 | def test_bad_edge_config(): 22 | config = default_config() 23 | 24 | # Remove the `dependencies` key from an edge config 25 | config.edges["stop_times.txt", "trips.txt"].pop("dependencies") 26 | 27 | feed = Feed(fixture("caltrain-2017-07-24"), config=config) 28 | 29 | with pytest.raises(ValueError, match=r"Edge missing `dependencies` attribute"): 30 | feed.stop_times 31 | 32 | 33 | def test_set(): 34 | feed = Feed(fixture("caltrain-2017-07-24")) 35 | newval = object() 36 | feed.set("newkey", newval) 37 | assert feed.get("newkey") is newval 38 | 39 | 40 | @pytest.mark.parametrize( 41 | "path,dates,shapes", 42 | [ 43 | ( 44 | fixture("caltrain-2017-07-24"), 45 | [], 46 | { 47 | "agency.txt": (1, 6), 48 | "calendar.txt": (3, 10), 49 | "calendar_dates.txt": (642, 3), 50 | "fare_attributes.txt": (6, 6), 51 | "fare_rules.txt": (144, 4), 52 | "routes.txt": (4, 7), 53 | "shapes.txt": (3008, 5), 54 | "stops.txt": (64, 12), 55 | }, 56 | ), 57 | ( 58 | fixture("caltrain-2017-07-24"), 59 | [datetime.date(2017, 8, 6)], 60 | { 61 | "agency.txt": (1, 6), 62 | "calendar.txt": (1, 10), 63 | "calendar_dates.txt": (6, 3), 64 | "fare_attributes.txt": (4, 6), 65 | "fare_rules.txt": (48, 4), 66 | "routes.txt": (3, 7), 67 | "shapes.txt": (1094, 5), 68 | "stops.txt": (50, 12), 69 | }, 70 | ), 71 | ( 72 | fixture("nested"), 73 | [datetime.date(2017, 8, 6)], 74 | { 75 | "agency.txt": (1, 6), 76 | "calendar.txt": (1, 10), 77 | "calendar_dates.txt": (6, 3), 78 | "fare_attributes.txt": (4, 6), 79 | "fare_rules.txt": (48, 4), 80 | "routes.txt": (3, 7), 81 | "shapes.txt": (1094, 5), 82 | "stops.txt": (50, 12), 83 | }, 84 | ), 85 | ( 86 | fixture("amazon-2017-08-06"), 87 | [], 88 | { 89 | "agency.txt": (1, 7), 90 | "calendar.txt": (2, 10), 91 | "calendar_dates.txt": (2, 3), 92 | "fare_attributes.txt": (0, 5), 93 | "fare_rules.txt": (0, 1), 94 | "routes.txt": (50, 9), 95 | "shapes.txt": (12032, 5), 96 | "stops.txt": (35, 12), 97 | }, 98 | ), 99 | ( 100 | fixture("amazon-2017-08-06"), 101 | [datetime.date(2017, 8, 5)], 102 | { 103 | "agency.txt": (1, 7), 104 | "calendar.txt": (1, 10), 105 | "calendar_dates.txt": (2, 3), 106 | "fare_attributes.txt": (0, 5), 107 | "fare_rules.txt": (0, 1), 108 | "routes.txt": (1, 9), 109 | "shapes.txt": (3, 5), 110 | "stops.txt": (2, 12), 111 | }, 112 | ), 113 | ( 114 | fixture("region-nord-v2"), 115 | [], 116 | { 117 | "agency.txt": (1, 7), 118 | "calendar.txt": (0, 10), 119 | "calendar_dates.txt": (333, 3), 120 | "fare_attributes.txt": (0, 5), 121 | "fare_rules.txt": (0, 1), 122 | "routes.txt": (181, 12), 123 | "shapes.txt": (0, 4), 124 | "stops.txt": (3693, 15), 125 | }, 126 | ), 127 | ], 128 | ) 129 | def test_read_file(path, dates, shapes): 130 | service_ids_by_date = ptg.read_service_ids_by_date(path) 131 | 132 | service_ids = { 133 | service_id 134 | for date in dates 135 | if date in service_ids_by_date 136 | for service_id in service_ids_by_date[date] 137 | } 138 | 139 | if service_ids: 140 | feed = Feed(path, view={"trips.txt": {"service_id": service_ids}}) 141 | else: 142 | feed = Feed(path) 143 | 144 | for filename, shape in shapes.items(): 145 | assert ( 146 | feed.get(filename).shape == shape 147 | ), "{}/{} dataframe shape was incorrect".format(path, filename) 148 | 149 | 150 | @pytest.mark.parametrize( 151 | "path,shapes", 152 | [ 153 | ( 154 | fixture("empty"), 155 | { 156 | "agency.txt": (0, 3), 157 | "calendar.txt": (0, 0), 158 | "calendar_dates.txt": (0, 3), 159 | "fare_attributes.txt": (0, 5), 160 | "fare_rules.txt": (0, 1), 161 | "routes.txt": (0, 4), 162 | "stops.txt": (0, 4), 163 | }, 164 | ), 165 | ( 166 | fixture("caltrain-2017-07-24"), 167 | { 168 | "agency.txt": (1, 6), 169 | "calendar.txt": (3, 10), 170 | "calendar_dates.txt": (642, 3), 171 | "fare_attributes.txt": (6, 6), 172 | "fare_rules.txt": (144, 4), 173 | "routes.txt": (4, 7), 174 | "shapes.txt": (3008, 5), 175 | "stops.txt": (64, 12), 176 | }, 177 | ), 178 | ( 179 | fixture("amazon-2017-08-06"), 180 | { 181 | "agency.txt": (1, 7), 182 | "calendar.txt": (3, 10), 183 | "calendar_dates.txt": (2, 3), 184 | "fare_attributes.txt": (0, 0), 185 | "fare_rules.txt": (0, 0), 186 | "routes.txt": (50, 9), 187 | "shapes.txt": (12032, 5), 188 | "stops.txt": (35, 12), 189 | }, 190 | ), 191 | ( 192 | fixture("region-nord-v2"), 193 | { 194 | "agency.txt": (1, 7), 195 | "calendar.txt": (0, 0), 196 | "calendar_dates.txt": (333, 3), 197 | "fare_attributes.txt": (0, 0), 198 | "fare_rules.txt": (0, 0), 199 | "routes.txt": (181, 12), 200 | "shapes.txt": (0, 0), 201 | "stops.txt": (3693, 15), 202 | }, 203 | ), 204 | ], 205 | ) 206 | def test_raw_feed(path, shapes): 207 | feed = Feed(path, config=empty_config()) 208 | 209 | for filename, shape in shapes.items(): 210 | assert ( 211 | feed.get(filename).shape == shape 212 | ), "{}/{} dataframe shape was incorrect".format(path, filename) 213 | 214 | 215 | @pytest.mark.parametrize( 216 | "path", [fixture("amazon-2017-08-06"), fixture("caltrain-2017-07-24")] 217 | ) 218 | def test_filtered_columns(path): 219 | service_ids_by_date = ptg.read_service_ids_by_date(path) 220 | service_ids = list(service_ids_by_date.values())[0] 221 | 222 | feed_full = Feed(path) 223 | feed_view = Feed(path, view={"trips.txt": {"service_id": service_ids}}) 224 | feed_null = Feed(path, view={"trips.txt": {"service_id": "never-match"}}) 225 | 226 | assert set(feed_full.trips.columns) == set(feed_view.trips.columns) 227 | assert set(feed_full.trips.columns) == set(feed_null.trips.columns) 228 | -------------------------------------------------------------------------------- /tests/fixtures/caltrain-2017-07-24/realtime_trips.txt: -------------------------------------------------------------------------------- 1 | trip_id,realtime_trip_id 2 | 6512143-CT-17JUL-Caltrain-Sunday-01,441u 3 | 6512144-CT-17JUL-Caltrain-Sunday-01,423u 4 | 6512145-CT-17JUL-Caltrain-Sunday-01,425u 5 | 6512146-CT-17JUL-Caltrain-Sunday-01,427u 6 | 6512147-CT-17JUL-Caltrain-Sunday-01,429u 7 | 6512148-CT-17JUL-Caltrain-Sunday-01,431u 8 | 6512149-CT-17JUL-Caltrain-Sunday-01,433u 9 | 6512150-CT-17JUL-Caltrain-Sunday-01,435u 10 | 6512151-CT-17JUL-Caltrain-Sunday-01,439u 11 | 6512152-CT-17JUL-Caltrain-Sunday-01,437u 12 | 6512153-CT-17JUL-Caltrain-Sunday-01,801u 13 | 6512154-CT-17JUL-Caltrain-Sunday-01,803u 14 | 6512155-CT-17JUL-Caltrain-Sunday-01,422u 15 | 6512156-CT-17JUL-Caltrain-Sunday-01,424u 16 | 6512157-CT-17JUL-Caltrain-Sunday-01,426u 17 | 6512158-CT-17JUL-Caltrain-Sunday-01,428u 18 | 6512159-CT-17JUL-Caltrain-Sunday-01,440u 19 | 6512160-CT-17JUL-Caltrain-Sunday-01,430u 20 | 6512161-CT-17JUL-Caltrain-Sunday-01,432u 21 | 6512162-CT-17JUL-Caltrain-Sunday-01,438u 22 | 6512163-CT-17JUL-Caltrain-Sunday-01,434u 23 | 6512164-CT-17JUL-Caltrain-Sunday-01,436u 24 | 6512165-CT-17JUL-Caltrain-Sunday-01,802u 25 | 6512166-CT-17JUL-Caltrain-Sunday-01,804u 26 | 6512167-CT-17JUL-Caltrain-Sunday-01,38u 27 | 6512168-CT-17JUL-Caltrain-Sunday-01,40u 28 | 6512169-CT-17JUL-Caltrain-Sunday-01,36u 29 | 6512170-CT-17JUL-Caltrain-Sunday-01,35u 30 | 6512171-CT-17JUL-Caltrain-Sunday-01,34u 31 | 6512172-CT-17JUL-Caltrain-Sunday-01,33u 32 | 6512173-CT-17JUL-Caltrain-Sunday-01,32u 33 | 6512174-CT-17JUL-Caltrain-Sunday-01,31u 34 | 6512175-CT-17JUL-Caltrain-Sunday-01,30u 35 | 6512176-CT-17JUL-Caltrain-Sunday-01,29u 36 | 6512177-CT-17JUL-Caltrain-Sunday-01,37u 37 | 6512178-CT-17JUL-Caltrain-Sunday-01,39u 38 | 6512179-CT-17JUL-Caltrain-Sunday-01,54u 39 | 6512180-CT-17JUL-Caltrain-Sunday-01,45u 40 | 6512181-CT-17JUL-Caltrain-Sunday-01,46u 41 | 6512182-CT-17JUL-Caltrain-Sunday-01,47u 42 | 6512183-CT-17JUL-Caltrain-Sunday-01,48u 43 | 6512184-CT-17JUL-Caltrain-Sunday-01,49u 44 | 6512185-CT-17JUL-Caltrain-Sunday-01,50u 45 | 6512186-CT-17JUL-Caltrain-Sunday-01,51u 46 | 6512187-CT-17JUL-Caltrain-Sunday-01,52u 47 | 6512188-CT-17JUL-Caltrain-Sunday-01,53u 48 | 6512135-CT-17JUL-Caltrain-Saturday-03,421 49 | 6512136-CT-17JUL-Caltrain-Saturday-03,443 50 | 6512137-CT-17JUL-Caltrain-Saturday-03,442 51 | 6512138-CT-17JUL-Caltrain-Saturday-03,444 52 | 6512143-CT-17JUL-Caltrain-Saturday-03,441 53 | 6512144-CT-17JUL-Caltrain-Saturday-03,423 54 | 6512145-CT-17JUL-Caltrain-Saturday-03,425 55 | 6512146-CT-17JUL-Caltrain-Saturday-03,427 56 | 6512147-CT-17JUL-Caltrain-Saturday-03,429 57 | 6512148-CT-17JUL-Caltrain-Saturday-03,431 58 | 6512149-CT-17JUL-Caltrain-Saturday-03,433 59 | 6512150-CT-17JUL-Caltrain-Saturday-03,435 60 | 6512151-CT-17JUL-Caltrain-Saturday-03,439 61 | 6512152-CT-17JUL-Caltrain-Saturday-03,437 62 | 6512153-CT-17JUL-Caltrain-Saturday-03,801 63 | 6512154-CT-17JUL-Caltrain-Saturday-03,803 64 | 6512155-CT-17JUL-Caltrain-Saturday-03,422 65 | 6512156-CT-17JUL-Caltrain-Saturday-03,424 66 | 6512157-CT-17JUL-Caltrain-Saturday-03,426 67 | 6512158-CT-17JUL-Caltrain-Saturday-03,428 68 | 6512159-CT-17JUL-Caltrain-Saturday-03,440 69 | 6512160-CT-17JUL-Caltrain-Saturday-03,430 70 | 6512161-CT-17JUL-Caltrain-Saturday-03,432 71 | 6512162-CT-17JUL-Caltrain-Saturday-03,438 72 | 6512163-CT-17JUL-Caltrain-Saturday-03,434 73 | 6512164-CT-17JUL-Caltrain-Saturday-03,436 74 | 6512165-CT-17JUL-Caltrain-Saturday-03,802 75 | 6512166-CT-17JUL-Caltrain-Saturday-03,804 76 | 6512167-CT-17JUL-Caltrain-Saturday-03,38 77 | 6512168-CT-17JUL-Caltrain-Saturday-03,40 78 | 6512169-CT-17JUL-Caltrain-Saturday-03,36 79 | 6512170-CT-17JUL-Caltrain-Saturday-03,35 80 | 6512171-CT-17JUL-Caltrain-Saturday-03,34 81 | 6512172-CT-17JUL-Caltrain-Saturday-03,33 82 | 6512173-CT-17JUL-Caltrain-Saturday-03,32 83 | 6512174-CT-17JUL-Caltrain-Saturday-03,31 84 | 6512175-CT-17JUL-Caltrain-Saturday-03,30 85 | 6512176-CT-17JUL-Caltrain-Saturday-03,29 86 | 6512177-CT-17JUL-Caltrain-Saturday-03,37 87 | 6512178-CT-17JUL-Caltrain-Saturday-03,39 88 | 6512179-CT-17JUL-Caltrain-Saturday-03,54 89 | 6512180-CT-17JUL-Caltrain-Saturday-03,45 90 | 6512181-CT-17JUL-Caltrain-Saturday-03,46 91 | 6512182-CT-17JUL-Caltrain-Saturday-03,47 92 | 6512183-CT-17JUL-Caltrain-Saturday-03,48 93 | 6512184-CT-17JUL-Caltrain-Saturday-03,49 94 | 6512185-CT-17JUL-Caltrain-Saturday-03,50 95 | 6512186-CT-17JUL-Caltrain-Saturday-03,51 96 | 6512187-CT-17JUL-Caltrain-Saturday-03,52 97 | 6512188-CT-17JUL-Caltrain-Saturday-03,53 98 | 6512015-CT-17JUL-Combo-Weekday-01,371 99 | 6512016-CT-17JUL-Combo-Weekday-01,381 100 | 6512017-CT-17JUL-Combo-Weekday-01,309 101 | 6512018-CT-17JUL-Combo-Weekday-01,319 102 | 6512019-CT-17JUL-Combo-Weekday-01,323 103 | 6512020-CT-17JUL-Combo-Weekday-01,313 104 | 6512021-CT-17JUL-Combo-Weekday-01,360 105 | 6512022-CT-17JUL-Combo-Weekday-01,380 106 | 6512023-CT-17JUL-Combo-Weekday-01,370 107 | 6512024-CT-17JUL-Combo-Weekday-01,329 108 | 6512025-CT-17JUL-Combo-Weekday-01,365 109 | 6512026-CT-17JUL-Combo-Weekday-01,375 110 | 6512027-CT-17JUL-Combo-Weekday-01,385 111 | 6512028-CT-17JUL-Combo-Weekday-01,305 112 | 6512029-CT-17JUL-Combo-Weekday-01,324 113 | 6512030-CT-17JUL-Combo-Weekday-01,314 114 | 6512031-CT-17JUL-Combo-Weekday-01,386 115 | 6512032-CT-17JUL-Combo-Weekday-01,366 116 | 6512033-CT-17JUL-Combo-Weekday-01,376 117 | 6512034-CT-17JUL-Combo-Weekday-01,330 118 | 6512035-CT-17JUL-Combo-Weekday-01,320 119 | 6512036-CT-17JUL-Combo-Weekday-01,310 120 | 6512037-CT-17JUL-Combo-Weekday-01,221 121 | 6512038-CT-17JUL-Combo-Weekday-01,217 122 | 6512039-CT-17JUL-Combo-Weekday-01,227 123 | 6512040-CT-17JUL-Combo-Weekday-01,206 124 | 6512041-CT-17JUL-Combo-Weekday-01,208 125 | 6512042-CT-17JUL-Combo-Weekday-01,218 126 | 6512043-CT-17JUL-Combo-Weekday-01,263 127 | 6512044-CT-17JUL-Combo-Weekday-01,273 128 | 6512045-CT-17JUL-Combo-Weekday-01,283 129 | 6512046-CT-17JUL-Combo-Weekday-01,216 130 | 6512047-CT-17JUL-Combo-Weekday-01,226 131 | 6512048-CT-17JUL-Combo-Weekday-01,267 132 | 6512049-CT-17JUL-Combo-Weekday-01,277 133 | 6512050-CT-17JUL-Combo-Weekday-01,261 134 | 6512051-CT-17JUL-Combo-Weekday-01,269 135 | 6512052-CT-17JUL-Combo-Weekday-01,279 136 | 6512053-CT-17JUL-Combo-Weekday-01,236 137 | 6512054-CT-17JUL-Combo-Weekday-01,254 138 | 6512055-CT-17JUL-Combo-Weekday-01,258 139 | 6512056-CT-17JUL-Combo-Weekday-01,233 140 | 6512057-CT-17JUL-Combo-Weekday-01,237 141 | 6512058-CT-17JUL-Combo-Weekday-01,257 142 | 6512059-CT-17JUL-Combo-Weekday-01,282 143 | 6512060-CT-17JUL-Combo-Weekday-01,215 144 | 6512061-CT-17JUL-Combo-Weekday-01,225 145 | 6512062-CT-17JUL-Combo-Weekday-01,231 146 | 6512063-CT-17JUL-Combo-Weekday-01,264 147 | 6512064-CT-17JUL-Combo-Weekday-01,284 148 | 6512065-CT-17JUL-Combo-Weekday-01,274 149 | 6512066-CT-17JUL-Combo-Weekday-01,278 150 | 6512067-CT-17JUL-Combo-Weekday-01,288 151 | 6512068-CT-17JUL-Combo-Weekday-01,289 152 | 6512069-CT-17JUL-Combo-Weekday-01,228 153 | 6512070-CT-17JUL-Combo-Weekday-01,268 154 | 6512071-CT-17JUL-Combo-Weekday-01,207 155 | 6512072-CT-17JUL-Combo-Weekday-01,222 156 | 6512073-CT-17JUL-Combo-Weekday-01,232 157 | 6512074-CT-17JUL-Combo-Weekday-01,262 158 | 6512075-CT-17JUL-Combo-Weekday-01,272 159 | 6512076-CT-17JUL-Combo-Weekday-01,211 160 | 6512077-CT-17JUL-Combo-Weekday-01,287 161 | 6512078-CT-17JUL-Combo-Weekday-01,212 162 | 6512079-CT-17JUL-Combo-Weekday-01,196 163 | 6512080-CT-17JUL-Combo-Weekday-01,190 164 | 6512081-CT-17JUL-Combo-Weekday-01,102 165 | 6512082-CT-17JUL-Combo-Weekday-01,104 166 | 6512083-CT-17JUL-Combo-Weekday-01,101 167 | 6512084-CT-17JUL-Combo-Weekday-01,135 168 | 6512085-CT-17JUL-Combo-Weekday-01,139 169 | 6512086-CT-17JUL-Combo-Weekday-01,143 170 | 6512087-CT-17JUL-Combo-Weekday-01,147 171 | 6512088-CT-17JUL-Combo-Weekday-01,151 172 | 6512089-CT-17JUL-Combo-Weekday-01,155 173 | 6512090-CT-17JUL-Combo-Weekday-01,191 174 | 6512091-CT-17JUL-Combo-Weekday-01,193 175 | 6512092-CT-17JUL-Combo-Weekday-01,199 176 | 6512093-CT-17JUL-Combo-Weekday-01,150 177 | 6512094-CT-17JUL-Combo-Weekday-01,152 178 | 6512095-CT-17JUL-Combo-Weekday-01,134 179 | 6512096-CT-17JUL-Combo-Weekday-01,138 180 | 6512097-CT-17JUL-Combo-Weekday-01,142 181 | 6512098-CT-17JUL-Combo-Weekday-01,146 182 | 6512099-CT-17JUL-Combo-Weekday-01,198 183 | 6512100-CT-17JUL-Combo-Weekday-01,156 184 | 6512101-CT-17JUL-Combo-Weekday-01,192 185 | 6512102-CT-17JUL-Combo-Weekday-01,194 186 | 6512103-CT-17JUL-Combo-Weekday-01,159 187 | 6512104-CT-17JUL-Combo-Weekday-01,103 188 | 6512105-CT-17JUL-Combo-Weekday-01,197 189 | 6512106-CT-17JUL-Combo-Weekday-01,195 190 | -------------------------------------------------------------------------------- /tests/fixtures/nested/a/b/c/caltrain-2017-07-24/realtime_trips.txt: -------------------------------------------------------------------------------- 1 | trip_id,realtime_trip_id 2 | 6512143-CT-17JUL-Caltrain-Sunday-01,441u 3 | 6512144-CT-17JUL-Caltrain-Sunday-01,423u 4 | 6512145-CT-17JUL-Caltrain-Sunday-01,425u 5 | 6512146-CT-17JUL-Caltrain-Sunday-01,427u 6 | 6512147-CT-17JUL-Caltrain-Sunday-01,429u 7 | 6512148-CT-17JUL-Caltrain-Sunday-01,431u 8 | 6512149-CT-17JUL-Caltrain-Sunday-01,433u 9 | 6512150-CT-17JUL-Caltrain-Sunday-01,435u 10 | 6512151-CT-17JUL-Caltrain-Sunday-01,439u 11 | 6512152-CT-17JUL-Caltrain-Sunday-01,437u 12 | 6512153-CT-17JUL-Caltrain-Sunday-01,801u 13 | 6512154-CT-17JUL-Caltrain-Sunday-01,803u 14 | 6512155-CT-17JUL-Caltrain-Sunday-01,422u 15 | 6512156-CT-17JUL-Caltrain-Sunday-01,424u 16 | 6512157-CT-17JUL-Caltrain-Sunday-01,426u 17 | 6512158-CT-17JUL-Caltrain-Sunday-01,428u 18 | 6512159-CT-17JUL-Caltrain-Sunday-01,440u 19 | 6512160-CT-17JUL-Caltrain-Sunday-01,430u 20 | 6512161-CT-17JUL-Caltrain-Sunday-01,432u 21 | 6512162-CT-17JUL-Caltrain-Sunday-01,438u 22 | 6512163-CT-17JUL-Caltrain-Sunday-01,434u 23 | 6512164-CT-17JUL-Caltrain-Sunday-01,436u 24 | 6512165-CT-17JUL-Caltrain-Sunday-01,802u 25 | 6512166-CT-17JUL-Caltrain-Sunday-01,804u 26 | 6512167-CT-17JUL-Caltrain-Sunday-01,38u 27 | 6512168-CT-17JUL-Caltrain-Sunday-01,40u 28 | 6512169-CT-17JUL-Caltrain-Sunday-01,36u 29 | 6512170-CT-17JUL-Caltrain-Sunday-01,35u 30 | 6512171-CT-17JUL-Caltrain-Sunday-01,34u 31 | 6512172-CT-17JUL-Caltrain-Sunday-01,33u 32 | 6512173-CT-17JUL-Caltrain-Sunday-01,32u 33 | 6512174-CT-17JUL-Caltrain-Sunday-01,31u 34 | 6512175-CT-17JUL-Caltrain-Sunday-01,30u 35 | 6512176-CT-17JUL-Caltrain-Sunday-01,29u 36 | 6512177-CT-17JUL-Caltrain-Sunday-01,37u 37 | 6512178-CT-17JUL-Caltrain-Sunday-01,39u 38 | 6512179-CT-17JUL-Caltrain-Sunday-01,54u 39 | 6512180-CT-17JUL-Caltrain-Sunday-01,45u 40 | 6512181-CT-17JUL-Caltrain-Sunday-01,46u 41 | 6512182-CT-17JUL-Caltrain-Sunday-01,47u 42 | 6512183-CT-17JUL-Caltrain-Sunday-01,48u 43 | 6512184-CT-17JUL-Caltrain-Sunday-01,49u 44 | 6512185-CT-17JUL-Caltrain-Sunday-01,50u 45 | 6512186-CT-17JUL-Caltrain-Sunday-01,51u 46 | 6512187-CT-17JUL-Caltrain-Sunday-01,52u 47 | 6512188-CT-17JUL-Caltrain-Sunday-01,53u 48 | 6512135-CT-17JUL-Caltrain-Saturday-03,421 49 | 6512136-CT-17JUL-Caltrain-Saturday-03,443 50 | 6512137-CT-17JUL-Caltrain-Saturday-03,442 51 | 6512138-CT-17JUL-Caltrain-Saturday-03,444 52 | 6512143-CT-17JUL-Caltrain-Saturday-03,441 53 | 6512144-CT-17JUL-Caltrain-Saturday-03,423 54 | 6512145-CT-17JUL-Caltrain-Saturday-03,425 55 | 6512146-CT-17JUL-Caltrain-Saturday-03,427 56 | 6512147-CT-17JUL-Caltrain-Saturday-03,429 57 | 6512148-CT-17JUL-Caltrain-Saturday-03,431 58 | 6512149-CT-17JUL-Caltrain-Saturday-03,433 59 | 6512150-CT-17JUL-Caltrain-Saturday-03,435 60 | 6512151-CT-17JUL-Caltrain-Saturday-03,439 61 | 6512152-CT-17JUL-Caltrain-Saturday-03,437 62 | 6512153-CT-17JUL-Caltrain-Saturday-03,801 63 | 6512154-CT-17JUL-Caltrain-Saturday-03,803 64 | 6512155-CT-17JUL-Caltrain-Saturday-03,422 65 | 6512156-CT-17JUL-Caltrain-Saturday-03,424 66 | 6512157-CT-17JUL-Caltrain-Saturday-03,426 67 | 6512158-CT-17JUL-Caltrain-Saturday-03,428 68 | 6512159-CT-17JUL-Caltrain-Saturday-03,440 69 | 6512160-CT-17JUL-Caltrain-Saturday-03,430 70 | 6512161-CT-17JUL-Caltrain-Saturday-03,432 71 | 6512162-CT-17JUL-Caltrain-Saturday-03,438 72 | 6512163-CT-17JUL-Caltrain-Saturday-03,434 73 | 6512164-CT-17JUL-Caltrain-Saturday-03,436 74 | 6512165-CT-17JUL-Caltrain-Saturday-03,802 75 | 6512166-CT-17JUL-Caltrain-Saturday-03,804 76 | 6512167-CT-17JUL-Caltrain-Saturday-03,38 77 | 6512168-CT-17JUL-Caltrain-Saturday-03,40 78 | 6512169-CT-17JUL-Caltrain-Saturday-03,36 79 | 6512170-CT-17JUL-Caltrain-Saturday-03,35 80 | 6512171-CT-17JUL-Caltrain-Saturday-03,34 81 | 6512172-CT-17JUL-Caltrain-Saturday-03,33 82 | 6512173-CT-17JUL-Caltrain-Saturday-03,32 83 | 6512174-CT-17JUL-Caltrain-Saturday-03,31 84 | 6512175-CT-17JUL-Caltrain-Saturday-03,30 85 | 6512176-CT-17JUL-Caltrain-Saturday-03,29 86 | 6512177-CT-17JUL-Caltrain-Saturday-03,37 87 | 6512178-CT-17JUL-Caltrain-Saturday-03,39 88 | 6512179-CT-17JUL-Caltrain-Saturday-03,54 89 | 6512180-CT-17JUL-Caltrain-Saturday-03,45 90 | 6512181-CT-17JUL-Caltrain-Saturday-03,46 91 | 6512182-CT-17JUL-Caltrain-Saturday-03,47 92 | 6512183-CT-17JUL-Caltrain-Saturday-03,48 93 | 6512184-CT-17JUL-Caltrain-Saturday-03,49 94 | 6512185-CT-17JUL-Caltrain-Saturday-03,50 95 | 6512186-CT-17JUL-Caltrain-Saturday-03,51 96 | 6512187-CT-17JUL-Caltrain-Saturday-03,52 97 | 6512188-CT-17JUL-Caltrain-Saturday-03,53 98 | 6512015-CT-17JUL-Combo-Weekday-01,371 99 | 6512016-CT-17JUL-Combo-Weekday-01,381 100 | 6512017-CT-17JUL-Combo-Weekday-01,309 101 | 6512018-CT-17JUL-Combo-Weekday-01,319 102 | 6512019-CT-17JUL-Combo-Weekday-01,323 103 | 6512020-CT-17JUL-Combo-Weekday-01,313 104 | 6512021-CT-17JUL-Combo-Weekday-01,360 105 | 6512022-CT-17JUL-Combo-Weekday-01,380 106 | 6512023-CT-17JUL-Combo-Weekday-01,370 107 | 6512024-CT-17JUL-Combo-Weekday-01,329 108 | 6512025-CT-17JUL-Combo-Weekday-01,365 109 | 6512026-CT-17JUL-Combo-Weekday-01,375 110 | 6512027-CT-17JUL-Combo-Weekday-01,385 111 | 6512028-CT-17JUL-Combo-Weekday-01,305 112 | 6512029-CT-17JUL-Combo-Weekday-01,324 113 | 6512030-CT-17JUL-Combo-Weekday-01,314 114 | 6512031-CT-17JUL-Combo-Weekday-01,386 115 | 6512032-CT-17JUL-Combo-Weekday-01,366 116 | 6512033-CT-17JUL-Combo-Weekday-01,376 117 | 6512034-CT-17JUL-Combo-Weekday-01,330 118 | 6512035-CT-17JUL-Combo-Weekday-01,320 119 | 6512036-CT-17JUL-Combo-Weekday-01,310 120 | 6512037-CT-17JUL-Combo-Weekday-01,221 121 | 6512038-CT-17JUL-Combo-Weekday-01,217 122 | 6512039-CT-17JUL-Combo-Weekday-01,227 123 | 6512040-CT-17JUL-Combo-Weekday-01,206 124 | 6512041-CT-17JUL-Combo-Weekday-01,208 125 | 6512042-CT-17JUL-Combo-Weekday-01,218 126 | 6512043-CT-17JUL-Combo-Weekday-01,263 127 | 6512044-CT-17JUL-Combo-Weekday-01,273 128 | 6512045-CT-17JUL-Combo-Weekday-01,283 129 | 6512046-CT-17JUL-Combo-Weekday-01,216 130 | 6512047-CT-17JUL-Combo-Weekday-01,226 131 | 6512048-CT-17JUL-Combo-Weekday-01,267 132 | 6512049-CT-17JUL-Combo-Weekday-01,277 133 | 6512050-CT-17JUL-Combo-Weekday-01,261 134 | 6512051-CT-17JUL-Combo-Weekday-01,269 135 | 6512052-CT-17JUL-Combo-Weekday-01,279 136 | 6512053-CT-17JUL-Combo-Weekday-01,236 137 | 6512054-CT-17JUL-Combo-Weekday-01,254 138 | 6512055-CT-17JUL-Combo-Weekday-01,258 139 | 6512056-CT-17JUL-Combo-Weekday-01,233 140 | 6512057-CT-17JUL-Combo-Weekday-01,237 141 | 6512058-CT-17JUL-Combo-Weekday-01,257 142 | 6512059-CT-17JUL-Combo-Weekday-01,282 143 | 6512060-CT-17JUL-Combo-Weekday-01,215 144 | 6512061-CT-17JUL-Combo-Weekday-01,225 145 | 6512062-CT-17JUL-Combo-Weekday-01,231 146 | 6512063-CT-17JUL-Combo-Weekday-01,264 147 | 6512064-CT-17JUL-Combo-Weekday-01,284 148 | 6512065-CT-17JUL-Combo-Weekday-01,274 149 | 6512066-CT-17JUL-Combo-Weekday-01,278 150 | 6512067-CT-17JUL-Combo-Weekday-01,288 151 | 6512068-CT-17JUL-Combo-Weekday-01,289 152 | 6512069-CT-17JUL-Combo-Weekday-01,228 153 | 6512070-CT-17JUL-Combo-Weekday-01,268 154 | 6512071-CT-17JUL-Combo-Weekday-01,207 155 | 6512072-CT-17JUL-Combo-Weekday-01,222 156 | 6512073-CT-17JUL-Combo-Weekday-01,232 157 | 6512074-CT-17JUL-Combo-Weekday-01,262 158 | 6512075-CT-17JUL-Combo-Weekday-01,272 159 | 6512076-CT-17JUL-Combo-Weekday-01,211 160 | 6512077-CT-17JUL-Combo-Weekday-01,287 161 | 6512078-CT-17JUL-Combo-Weekday-01,212 162 | 6512079-CT-17JUL-Combo-Weekday-01,196 163 | 6512080-CT-17JUL-Combo-Weekday-01,190 164 | 6512081-CT-17JUL-Combo-Weekday-01,102 165 | 6512082-CT-17JUL-Combo-Weekday-01,104 166 | 6512083-CT-17JUL-Combo-Weekday-01,101 167 | 6512084-CT-17JUL-Combo-Weekday-01,135 168 | 6512085-CT-17JUL-Combo-Weekday-01,139 169 | 6512086-CT-17JUL-Combo-Weekday-01,143 170 | 6512087-CT-17JUL-Combo-Weekday-01,147 171 | 6512088-CT-17JUL-Combo-Weekday-01,151 172 | 6512089-CT-17JUL-Combo-Weekday-01,155 173 | 6512090-CT-17JUL-Combo-Weekday-01,191 174 | 6512091-CT-17JUL-Combo-Weekday-01,193 175 | 6512092-CT-17JUL-Combo-Weekday-01,199 176 | 6512093-CT-17JUL-Combo-Weekday-01,150 177 | 6512094-CT-17JUL-Combo-Weekday-01,152 178 | 6512095-CT-17JUL-Combo-Weekday-01,134 179 | 6512096-CT-17JUL-Combo-Weekday-01,138 180 | 6512097-CT-17JUL-Combo-Weekday-01,142 181 | 6512098-CT-17JUL-Combo-Weekday-01,146 182 | 6512099-CT-17JUL-Combo-Weekday-01,198 183 | 6512100-CT-17JUL-Combo-Weekday-01,156 184 | 6512101-CT-17JUL-Combo-Weekday-01,192 185 | 6512102-CT-17JUL-Combo-Weekday-01,194 186 | 6512103-CT-17JUL-Combo-Weekday-01,159 187 | 6512104-CT-17JUL-Combo-Weekday-01,103 188 | 6512105-CT-17JUL-Combo-Weekday-01,197 189 | 6512106-CT-17JUL-Combo-Weekday-01,195 190 | -------------------------------------------------------------------------------- /partridge/readers.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | import datetime 3 | import os 4 | import shutil 5 | import tempfile 6 | from typing import DefaultDict, Dict, FrozenSet, Optional, Set, Tuple 7 | import weakref 8 | 9 | from isoweek import Week 10 | import networkx as nx 11 | 12 | from .config import default_config, geo_config, empty_config, reroot_graph 13 | from .gtfs import Feed 14 | from .parsers import vparse_date 15 | from .types import View 16 | from .utilities import remove_node_attributes 17 | 18 | 19 | DAY_NAMES = ( 20 | "monday", 21 | "tuesday", 22 | "wednesday", 23 | "thursday", 24 | "friday", 25 | "saturday", 26 | "sunday", 27 | ) 28 | 29 | 30 | def load_feed( 31 | path: str, view: Optional[View] = None, config: Optional[nx.DiGraph] = None 32 | ) -> Feed: 33 | config = default_config() if config is None else config 34 | view = {} if view is None else view 35 | 36 | if not nx.is_directed_acyclic_graph(config): 37 | raise ValueError("Config must be a DAG") 38 | 39 | if os.path.isdir(path): 40 | feed = _load_feed(path, view, config) 41 | elif os.path.isfile(path): 42 | feed = _unpack_feed(path, view, config) 43 | else: 44 | raise ValueError("File or path not found: {}".format(path)) 45 | 46 | return feed 47 | 48 | 49 | def load_raw_feed(path: str) -> Feed: 50 | return load_feed(path, view={}, config=empty_config()) 51 | 52 | 53 | def load_geo_feed(path: str, view: Optional[View] = None) -> Feed: 54 | return load_feed(path, view=view, config=geo_config()) 55 | 56 | 57 | def read_busiest_date(path: str) -> Tuple[datetime.date, FrozenSet[str]]: 58 | """Find the earliest date with the most trips""" 59 | feed = load_raw_feed(path) 60 | return _busiest_date(feed) 61 | 62 | 63 | def read_busiest_week(path: str) -> Dict[datetime.date, FrozenSet[str]]: 64 | """Find the earliest week with the most trips""" 65 | feed = load_raw_feed(path) 66 | return _busiest_week(feed) 67 | 68 | 69 | def read_service_ids_by_date(path: str) -> Dict[datetime.date, FrozenSet[str]]: 70 | """Find all service identifiers by date""" 71 | feed = load_raw_feed(path) 72 | return _service_ids_by_date(feed) 73 | 74 | 75 | def read_dates_by_service_ids( 76 | path: str, 77 | ) -> Dict[FrozenSet[str], FrozenSet[datetime.date]]: 78 | """Find dates with identical service""" 79 | feed = load_raw_feed(path) 80 | return _dates_by_service_ids(feed) 81 | 82 | 83 | def read_trip_counts_by_date(path: str) -> Dict[datetime.date, int]: 84 | """A useful proxy for busyness""" 85 | feed = load_raw_feed(path) 86 | return _trip_counts_by_date(feed) 87 | 88 | 89 | def _unpack_feed(path: str, view: View, config: nx.DiGraph) -> Feed: 90 | tmpdir = tempfile.mkdtemp() 91 | shutil.unpack_archive(path, tmpdir) 92 | feed: Feed = _load_feed(tmpdir, view, config) 93 | 94 | # Eager cleanup 95 | feed._delete_after_reading = True 96 | 97 | def finalize() -> None: 98 | shutil.rmtree(tmpdir) 99 | 100 | # Lazy cleanup 101 | weakref.finalize(feed, finalize) 102 | 103 | return feed 104 | 105 | 106 | def _load_feed(path: str, view: View, config: nx.DiGraph) -> Feed: 107 | """Multi-file feed filtering""" 108 | config_ = remove_node_attributes(config, ["converters", "transformations"]) 109 | feed_ = Feed(path, view={}, config=config_) 110 | for filename, column_filters in view.items(): 111 | config_ = reroot_graph(config_, filename) 112 | view_ = {filename: column_filters} 113 | feed_ = Feed(feed_, view=view_, config=config_) 114 | return Feed(feed_, config=config) 115 | 116 | 117 | def _busiest_date(feed: Feed) -> Tuple[datetime.date, FrozenSet[str]]: 118 | service_ids_by_date = _service_ids_by_date(feed) 119 | trip_counts_by_date = _trip_counts_by_date(feed) 120 | 121 | def max_by(kv: Tuple[datetime.date, int]) -> Tuple[int, int]: 122 | date, count = kv 123 | return count, -date.toordinal() 124 | 125 | date, _ = max(trip_counts_by_date.items(), key=max_by) 126 | service_ids = service_ids_by_date[date] 127 | 128 | return date, service_ids 129 | 130 | 131 | def _busiest_week(feed: Feed) -> Dict[datetime.date, FrozenSet[str]]: 132 | service_ids_by_date = _service_ids_by_date(feed) 133 | trip_counts_by_date = _trip_counts_by_date(feed) 134 | 135 | weekly_trip_counts: DefaultDict[Week, int] = defaultdict(int) 136 | weekly_dates: DefaultDict[Week, Set[datetime.date]] = defaultdict(set) 137 | for date in service_ids_by_date.keys(): 138 | key = Week.withdate(date) 139 | weekly_trip_counts[key] += trip_counts_by_date[date] 140 | weekly_dates[key].add(date) 141 | 142 | def max_by(kv: Tuple[Week, int]) -> Tuple[int, int]: 143 | week, count = kv 144 | return count, -week.toordinal() 145 | 146 | week, _ = max(weekly_trip_counts.items(), key=max_by) 147 | dates = sorted(weekly_dates[week]) 148 | 149 | return {date: service_ids_by_date[date] for date in dates} 150 | 151 | 152 | def _service_ids_by_date(feed: Feed) -> Dict[datetime.date, FrozenSet[str]]: 153 | results: DefaultDict[datetime.date, Set[str]] = defaultdict(set) 154 | removals: DefaultDict[datetime.date, Set[str]] = defaultdict(set) 155 | 156 | service_ids = set(feed.trips.service_id) 157 | calendar = feed.calendar 158 | caldates = feed.calendar_dates 159 | 160 | if not calendar.empty: 161 | # Only consider calendar.txt rows with applicable trips 162 | calendar = calendar[calendar.service_id.isin(service_ids)].copy() 163 | 164 | if not caldates.empty: 165 | # Only consider calendar_dates.txt rows with applicable trips 166 | caldates = caldates[caldates.service_id.isin(service_ids)].copy() 167 | 168 | if not calendar.empty: 169 | # Parse dates 170 | calendar.start_date = vparse_date(calendar.start_date) 171 | calendar.end_date = vparse_date(calendar.end_date) 172 | 173 | # Build up results dict from calendar ranges 174 | for _, cal in calendar.iterrows(): 175 | start = cal.start_date.toordinal() 176 | end = cal.end_date.toordinal() 177 | 178 | dow = {i: cal[day] for i, day in enumerate(DAY_NAMES)} 179 | for ordinal in range(start, end + 1): 180 | date = datetime.date.fromordinal(ordinal) 181 | if int(dow[date.weekday()]): 182 | results[date].add(cal.service_id) 183 | 184 | if not caldates.empty: 185 | # Parse dates 186 | caldates.date = vparse_date(caldates.date) 187 | 188 | # Split out additions and removals 189 | cdadd = caldates[caldates.exception_type == "1"] 190 | cdrem = caldates[caldates.exception_type == "2"] 191 | 192 | # Add to results by date 193 | for _, cd in cdadd.iterrows(): 194 | results[cd.date].add(cd.service_id) 195 | 196 | # Collect removals 197 | for _, cd in cdrem.iterrows(): 198 | removals[cd.date].add(cd.service_id) 199 | 200 | # Finally, process removals by date 201 | for date in removals: 202 | for service_id in removals[date]: 203 | if service_id in results[date]: 204 | results[date].remove(service_id) 205 | 206 | # Drop the key from results if no service present 207 | if len(results[date]) == 0: 208 | del results[date] 209 | 210 | assert results, "No service found in feed." 211 | 212 | return {k: frozenset(v) for k, v in results.items()} 213 | 214 | 215 | def _dates_by_service_ids(feed: Feed) -> Dict[FrozenSet[str], FrozenSet[datetime.date]]: 216 | results: DefaultDict[FrozenSet[str], Set[datetime.date]] = defaultdict(set) 217 | for date, service_ids in _service_ids_by_date(feed).items(): 218 | results[service_ids].add(date) 219 | return {k: frozenset(v) for k, v in results.items()} 220 | 221 | 222 | def _trip_counts_by_date(feed: Feed) -> Dict[datetime.date, int]: 223 | results: DefaultDict[datetime.date, int] = defaultdict(int) 224 | trips = feed.trips 225 | for service_ids, dates in _dates_by_service_ids(feed).items(): 226 | trip_count = trips[trips.service_id.isin(service_ids)].shape[0] 227 | for date in dates: 228 | results[date] += trip_count 229 | return dict(results) 230 | -------------------------------------------------------------------------------- /tests/fixtures/region-nord-v2/routes.txt: -------------------------------------------------------------------------------- 1 | agency_id,route_id,route_short_name,route_long_name,route_type,route_desc,route_url,route_color,route_text_color,route_bikes_allowed,bikes_allowed,route_sort_order 2 | 160,0301,301,Kulstadvika - Ørmelen,3,,,,,,, 3 | 160,0303,303,Aspeheim - Leksdal,3,,,,,,, 4 | 160,0304,304,Tuset - Verdal,3,,,,,,, 5 | 160,0305,305,Mogrenda - Leksdal,3,,,,,,, 6 | 160,0310,310,Erstad - Hokstad,3,,,,,,, 7 | 160,0311,311,Hokstad - Ytterøy skole,3,,,,,,, 8 | 160,0312,312,Forberg - Ytterøy skole,3,,,,,,, 9 | 160,0330,330,Finstad -Reitan - Binde,3,,,,,,, 10 | 160,0370,370,Inderøy,3,,,,,,, 11 | 160,0371,371,Inderøy,3,,,,,,, 12 | 160,0404,404,Hammer - Vegset - Snåsa,3,,,,,,, 13 | 160,0411,411,Snåsa - Grong,3,,,,,,, 14 | 160,0424,424,Snåsa - Agle,3,,,,,,, 15 | 160,0425,425,Agle - Snåsa,3,,,,,,, 16 | 160,0430,430,Holsing - Breide,3,,,,,,, 17 | 160,0431,431,Imsdalen - Snåsa,3,,,,,,, 18 | 160,0435,435,Strindmoen - Snåsa,3,,,,,,, 19 | 160,0543,543,Vassbotna - Høylandet,3,,,,,,, 20 | 160,0545,545,Mevassvik - Høylandet,3,,,,,,, 21 | 160,0553,553,Øyheim - Grong,3,,,,,,, 22 | 160,0554,554,Grong - Formofoss,3,,,,,,, 23 | 160,0555,555,Værem - Grong,3,,,,,,, 24 | 160,0572,572,Murumoen - Sandvika,3,,,,,,, 25 | 160,0573,573,Fagerstrand - Sandvika,3,,,,,,, 26 | 160,0574,574,Berglia - Sørli skole,3,,,,,,, 27 | 160,0575,575,Tunnsjø - Sandvika,3,,,,,,, 28 | 160,0586,586,Stallvika - Rørvik,3,,,,,,, 29 | 160,0587,587,Namsvatn - Røyrvik,3,,,,,,, 30 | 160,0588,588,Kvemo - Stortangen,3,,,,,,, 31 | 160,0589,589,Devika - Røyrvik,3,,,,,,, 32 | 160,0590,590,Åsnes - Stortangen skole,3,,,,,,, 33 | 160,0591,591,Trones - Namsskogan,3,,,,,,, 34 | 160,0594,594,Brekkvasselv - Namsskogan,3,,,,,,, 35 | 160,0596,596,Hognes - Høylandet,3,,,,,,, 36 | 160,0597,597,Hovland - Namsskogan,3,,,,,,, 37 | 160,0598,598,Grong - Harran - Namsskogan,3,,,,,,, 38 | 160,0600,600,Steinkjer - Lø - Steinkjer Ringrute morgen,3,,,,,,, 39 | 160,0601,601,Steinkjer - Ogndal,3,,,,,,, 40 | 160,0602,602,Aspås - Steinkjer,3,,,,,,, 41 | 160,0603,603,Ogndal - Steinkjer,3,,,,,,, 42 | 160,0604,604,Mære - Guldbergaunet,3,,,,,,, 43 | 160,0605,605,Steinkjer - Mære,3,,,,,,, 44 | 160,0676,676,Grong - Steinkjer,3,,,,,,, 45 | 160,0701,701,Derås - Hundset - Namdalseid skole,3,,,,,,, 46 | 160,0702,702,Alte - Fossli - Namdalseid skole,3,,,,,,, 47 | 160,0703,703,Oksdøla - Statland skole,3,,,,,,, 48 | 160,0704,704,Statland - Utvorda - Statland,3,,,,,,, 49 | 160,0706,706,Solstad - OBUS - Hunn skole,3,,,,,,, 50 | 160,0707,707,Tranåsn - Fosnes - Jøa skole,3,,,,,,, 51 | 160,0708,708,Lauvsnes - Flatanger montessori,3,,,,,,, 52 | 160,0709,709,Sandmo - OBUS - Øysletta,3,,,,,,, 53 | 160,0710,710,Hatligshus - Beistad skole/Vellamelen,3,,,,,,, 54 | 160,0711,711,Korsen - Morkmo - Bjørgan,3,,,,,,, 55 | 160,0713,713,Solem - Klabbdal - OBUS,3,,,,,,, 56 | 160,0714,714,Vada - Malm skole Eldnes,3,,,,,,, 57 | 160,0715,715,Malm skole - Holden,3,,,,,,, 58 | 160,0716,716,Stjerna - Holdervegen - Bjørkan,3,,,,,,, 59 | 160,0717,717,Stramda - Jøa skole,3,,,,,,, 60 | 160,0718,718,Romstad - Klinga Bangdalsruta,3,,,,,,, 61 | 160,1000,1000,Levanger - Steinkjer - Namsos fra 07.02.2018,3,,,,,,, 62 | 160,1003,1003,Egge - Søndre Egge,3,,,,,,, 63 | 160,1010,1010,Bybuss Søndre Egge,3,,,,,,, 64 | 160,1012,1012,Steinkjer - Byafossen - Steinkjer,3,,,,,,, 65 | 160,1022,1022,Steinkjer - Gjørv,3,,,,,,, 66 | 160,1030,1030,Finnlibakken - Follafossen - Malm - Steinkjer,3,,,,,,, 67 | 160,1032,1032,Vanvikan - Follafoss - Steinkjer,3,,,,,,, 68 | 160,1034,1034,Beistad - Jådåren,3,,,,,,, 69 | 160,1036,1036,Beistad - Sprova,3,,,,,,, 70 | 160,1038,1038,Beistad - Bartnes,3,,,,,,, 71 | 160,1040,1040,Steinkjer - Bartnes - Steinkjer,3,,,,,,, 72 | 160,1050,1050,Skogn - Levanger - Verdal - Steinkjer,3,,,,,,, 73 | 160,1200,1200,Agle Snåsa - Steinkjer,3,,,,,,, 74 | 160,1220,1220,Øvre Kvam - Steinkjer,3,,,,,,, 75 | 160,1288,1288,Råde - Fagerheim,3,,,,,,, 76 | 160,1290,1290,Vellamelen - Steinkjer,3,,,,,,, 77 | 160,1292,1292,Grønnvika - Binde,3,,,,,,, 78 | 160,1294,1294,Nyveiskorsen - Sunnan - Binde,3,,,,,,, 79 | 160,1296,1296,Utgård - Binde,3,,,,,,, 80 | 160,1298,1298,Binde - Egge ungdom skole,3,,,,,,, 81 | 160,1310,1310,Straumen - Kjerknesvåg,3,,,,,,, 82 | 160,1320,1320,Inderøy - Verdal,3,,,,,,, 83 | 160,1330,1330,Straumen - Steinkjer,3,,,,,,, 84 | 160,1380,1380,Mosvik - Straumen,3,,,,,,, 85 | 160,1382,1382,Straumen - (Flaget) - Røra,3,,,,,,, 86 | 160,1384,1384,Straumen - Grande - Røra,3,,,,,,, 87 | 160,1386,1386,Gangstad - Straumen,3,,,,,,, 88 | 160,1387,1387,Mosvik - Inderøy/Steinkjer,3,,,,,,, 89 | 160,1388,1388,Straumen - Grønnesby - Steinkjer,3,,,,,,, 90 | 160,1420,1420,Steinkjer - Sparbu,3,,,,,,, 91 | 160,1422,1422,Steinkjer - Gangstad,3,,,,,,, 92 | 160,1424,1424,Steinkjer - Røra - Inderøy,3,,,,,,, 93 | 160,1450,1450,Sjøåsen - Namdalseid - Steinkjer,3,,,,,,, 94 | 160,1616,1616,Mosvik - Straumen,3,,,,,,, 95 | 160,1682,1682,Brandsås - Testmann,3,,,,,,, 96 | 160,2020,2020,Spillum - Sentrum - Fossbrenna,3,,,,,,, 97 | 160,2030,2030,Namsos - Bangsund,3,,,,,,, 98 | 160,2032,2032,Bangsund,3,,,,,,, 99 | 160,2090,2090,Svea - Høknes,3,,,,,,, 100 | 160,2091,2091,Svea - Høknes,3,,,,,,, 101 | 160,2092,2092,Sørenget - Namsos,3,,,,,,, 102 | 160,2093,2093,Gullholmstranda - Svea,3,,,,,,, 103 | 160,2121,2121,Svea - Gullhomstrand Bybuss,3,,,,,,, 104 | 160,2150,2150,Aglen - Skorstad - Namsos,3,,,,,,, 105 | 160,2290,2290,Namsos - Bangsund - Namdalseid,3,,,,,,, 106 | 160,2300,2300,Flatanger - Sjøåsen - Namsos,3,,,,,,, 107 | 160,2400,2400,Namsos - Vibstad - Øysletta,3,,,,,,, 108 | 160,2470,2470,Namsos - Høylandet,3,,,,,,, 109 | 160,2500,2500,Namsos - Grong - (Harran),3,,,,,,, 110 | 160,2510,2510,Høylandet - Grong,3,,,,,,, 111 | 160,2600,2600,Namsos - Grong - Sørli,3,,,,,,, 112 | 160,2700,2700,Rløyrvik - Skorovatn - Namsskogan - Grøndalselv - Harran - Grong,3,,,,,,, 113 | 160,2810,2810,Namsos - Lund,3,,,,,,, 114 | 160,2900,2900,Namsos - Høylandet - Kolvereid - Rørvik,3,,,,,,, 115 | 160,2910,2910,Foldereid - Kolvereid - Rørvik,3,,,,,,, 116 | 160,2911,2911,Grong - Høylandet - Kongsmoen,3,,,,,,, 117 | 160,2920,2920,Rørvik - Garstad - Austafjord,3,,,,,,, 118 | 160,2930,2930,Kolvereid - Gutvik,3,,,,,,, 119 | 160,2940,2940,Kolvereid - Hofles - Salsbruket,3,,,,,,, 120 | 160,2950,2950,Kolvereid - Ottersøy - Måneset - Kolvereid,3,,,,,,, 121 | 160,2955,2955,Måneset - Rørvik,3,,,,,,, 122 | 160,2960,2960,Abelvær - Kolvereid,3,,,,,,, 123 | 160,2965,2965,Storval - Bjørndalen - Fikkan - Ottersøy,3,,,,,,, 124 | 160,2970,2970,Kolvereid - Våg - Arnøya,3,,,,,,, 125 | 160,2994,2994,Rørvik - Lauvøya,3,,,,,,, 126 | 160,2998,2998,Stein - Leka skole,3,,,,,,, 127 | 160,3010,3010,Momarka - Høgberget - Magneten,3,,,,,,, 128 | 160,3012,3012,Levanger - Nesset - Gjemble,3,,,,,,, 129 | 160,3020,3020,Levanger - Verdal - Steinkjer,3,,,,,,, 130 | 160,3040,3040,Levanger - Holåsen vest,3,,,,,,, 131 | 160,3050,3050,Levanger - Ekne - Levanger,3,,,,,,, 132 | 160,3051,3051,Levanger - Ekne - Levanger,3,,,,,,, 133 | 160,3060,3060,Levanger - Buran - Nybrotta,3,,,,,,, 134 | 160,3061,3061,Buran - Okkenhaug - Levanger,3,,,,,,, 135 | 160,3062,3062,Moan - Stokkbakken - Buran,3,,,,,,, 136 | 160,3107,3107,Nossum - Håa - Nesheim - Gjemble,3,,,,,,, 137 | 160,3109,3109,Elihu - Nesheim - Neset - Gjemble - Høgberget - Okkenhaug - Verdal,3,,,,,,, 138 | 160,3110,3110,Verdal - Levanger vgs,3,,,,,,, 139 | 160,3112,3112,Høgberget - Momarka - Halsan skole,3,,,,,,, 140 | 160,3126,3126,Børøya - Mule skole - Frol skole,3,,,,,,, 141 | 160,3141,3141,Skogn - Finne - Markabygda,3,,,,,,, 142 | 160,3142,3142,Markabygda - Gruslina - Markabygda,3,,,,,,, 143 | 160,3143,3143,Markabygda - Skogn - Levanger,3,,,,,,, 144 | 160,3146,3146,Markabygda,3,,,,,,, 145 | 160,3147,3147,Stavlo - Skogn,3,,,,,,, 146 | 160,3150,3150,Strandkorsen - Rongland - Levanger,3,,,,,,, 147 | 160,3151,3151,Strandkorsen - Ekne - Skogn,3,,,,,,, 148 | 160,3152,3152,Skogn - Holte - Hotran,3,,,,,,, 149 | 160,3161,3161,Mule - Okkenhaug,3,,,,,,, 150 | 160,3163,3163,Levanger - Munkeby - Stokkanbakken - Halsan - Levanger,3,,,,,,, 151 | 160,3200,3200,Åsen - Levanger,3,,,,,,, 152 | 160,3510,3510,Verdal vgs - Minsås,3,,,,,,, 153 | 160,3511,3511,Brannan - Verdal stasjon,3,,,,,,, 154 | 160,3540,3540,Skjælerfossen - Vuku - Verdal,3,,,,,,, 155 | 160,3550,3550,Innsmoen - Garnes - Verdal,3,,,,,,, 156 | 160,3551,3551,Garnes skole - Stene,3,,,,,,, 157 | 160,3552,3552,Verdal vgs - Lysthaug - Garnes,3,,,,,,, 158 | 160,3553,3553,Trones - Vinne - Verdalsøra skole,3,,,,,,, 159 | 160,3554,3554,Verdalsøra skole - Vinne,3,,,,,,, 160 | 160,3612,3612,Leksdal - Verdalsøra skole,3,,,,,,, 161 | 160,3614,3614,Forbregd - Stiklestad skole,3,,,,,,, 162 | 160,3615,3615,Kråg - Stiklestad skole,3,,,,,,, 163 | 160,3616,3616,Verdal - Stiklestad - Leirådal - Vuku,3,,,,,,, 164 | 160,3617,3617,Vuku - Leirådal - Vuku,3,,,,,,, 165 | 160,3618,3618,Lein - Vuku skole,3,,,,,,, 166 | 160,3619,3619,Verdal stasjon - Hallem - Vuku skole,3,,,,,,, 167 | 160,3620,3620,Ravlo - Verdalsøra barne skole,3,,,,,,, 168 | 160,3621,3621,Bjørga - Verdalsøra barneskole,3,,,,,,, 169 | 160,3801,3801,Frosta - Åsen - Stjørdal - Levanger,3,,,,,,, 170 | 160,3840,3840,Giset - Frosta skole,3,,,,,,, 171 | 160,3842,3842,Tautra - Frosta skole,3,,,,,,, 172 | 160,3844,3844,Vågen - Frosta skole,3,,,,,,, 173 | 160,3847,3847,Frosta skole - Nordbygda - Frosta skole,3,,,,,,, 174 | 160,3854,3854,Vinan - Sjur - Åsen barne- og ungdomskole,3,,,,,,, 175 | 160,3856,3856,Åsen - Norbygda,3,,,,,,, 176 | 160,3858,3858,Åsenfjorden - Åsen,3,,,,,,, 177 | 160,3859,3859,Nesjø - Fætten - Åsen barne- og ungdom skole,3,,,,,,, 178 | 160,3860,3860,Leangen - Åsenfjorden - Åsen barne- og ungdom skole,3,,,,,,, 179 | 160,4682,4682,Testmann - Brandsås - Testmann,3,,,,,,, 180 | 160,9991,9991,Kolvereid - Foldereid,3,,,,,,, 181 | 160,9992,9992,Minibussen - Botnan,3,,,,,,, 182 | 160,9993,9993,Formiddag,3,,,,,,, 183 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # partridge documentation build configuration file, created by 5 | # sphinx-quickstart on Tue Jul 9 22:26:36 2013. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | import sys 17 | import os 18 | 19 | # If extensions (or modules to document with autodoc) are in another 20 | # directory, add these directories to sys.path here. If the directory is 21 | # relative to the documentation root, use os.path.abspath to make it 22 | # absolute, like shown here. 23 | # sys.path.insert(0, os.path.abspath('.')) 24 | 25 | # Get the project root dir, which is the parent dir of this 26 | cwd = os.getcwd() 27 | project_root = os.path.dirname(cwd) 28 | 29 | # Insert the project root dir as the first element in the PYTHONPATH. 30 | # This lets us ensure that the source package is imported, and that its 31 | # version is used. 32 | sys.path.insert(0, project_root) 33 | 34 | import partridge 35 | 36 | # -- General configuration --------------------------------------------- 37 | 38 | # If your documentation needs a minimal Sphinx version, state it here. 39 | # needs_sphinx = '1.0' 40 | 41 | # Add any Sphinx extension module names here, as strings. They can be 42 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 43 | extensions = ["sphinx.ext.autodoc", "sphinx_autodoc_annotation", "sphinx.ext.viewcode"] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ["_templates"] 47 | 48 | # The suffix of source filenames. 49 | source_suffix = ".rst" 50 | 51 | # The encoding of source files. 52 | # source_encoding = 'utf-8-sig' 53 | 54 | # The master toctree document. 55 | master_doc = "index" 56 | 57 | # General information about the project. 58 | project = u"partridge" 59 | copyright = u"2017, Remix" 60 | 61 | # The version info for the project you're documenting, acts as replacement 62 | # for |version| and |release|, also used in various other places throughout 63 | # the built documents. 64 | # 65 | # The short X.Y version. 66 | version = partridge.__version__ 67 | # The full version, including alpha/beta/rc tags. 68 | release = partridge.__version__ 69 | 70 | # The language for content autogenerated by Sphinx. Refer to documentation 71 | # for a list of supported languages. 72 | # language = None 73 | 74 | # There are two options for replacing |today|: either, you set today to 75 | # some non-false value, then it is used: 76 | # today = '' 77 | # Else, today_fmt is used as the format for a strftime call. 78 | # today_fmt = '%B %d, %Y' 79 | 80 | # List of patterns, relative to source directory, that match files and 81 | # directories to ignore when looking for source files. 82 | exclude_patterns = ["_build"] 83 | 84 | # The reST default role (used for this markup: `text`) to use for all 85 | # documents. 86 | # default_role = None 87 | 88 | # If true, '()' will be appended to :func: etc. cross-reference text. 89 | # add_function_parentheses = True 90 | 91 | # If true, the current module name will be prepended to all description 92 | # unit titles (such as .. function::). 93 | # add_module_names = True 94 | 95 | # If true, sectionauthor and moduleauthor directives will be shown in the 96 | # output. They are ignored by default. 97 | # show_authors = False 98 | 99 | # The name of the Pygments (syntax highlighting) style to use. 100 | pygments_style = "sphinx" 101 | 102 | # A list of ignored prefixes for module index sorting. 103 | # modindex_common_prefix = [] 104 | 105 | # If true, keep warnings as "system message" paragraphs in the built 106 | # documents. 107 | # keep_warnings = False 108 | 109 | 110 | # -- Options for HTML output ------------------------------------------- 111 | 112 | # The theme to use for HTML and HTML Help pages. See the documentation for 113 | # a list of builtin themes. 114 | html_theme = "default" 115 | 116 | # Theme options are theme-specific and customize the look and feel of a 117 | # theme further. For a list of options available for each theme, see the 118 | # documentation. 119 | # html_theme_options = {} 120 | 121 | # Add any paths that contain custom themes here, relative to this directory. 122 | # html_theme_path = [] 123 | 124 | # The name for this set of Sphinx documents. If None, it defaults to 125 | # " v documentation". 126 | # html_title = None 127 | 128 | # A shorter title for the navigation bar. Default is the same as 129 | # html_title. 130 | # html_short_title = None 131 | 132 | # The name of an image file (relative to this directory) to place at the 133 | # top of the sidebar. 134 | # html_logo = None 135 | 136 | # The name of an image file (within the static path) to use as favicon 137 | # of the docs. This file should be a Windows icon file (.ico) being 138 | # 16x16 or 32x32 pixels large. 139 | # html_favicon = None 140 | 141 | # Add any paths that contain custom static files (such as style sheets) 142 | # here, relative to this directory. They are copied after the builtin 143 | # static files, so a file named "default.css" will overwrite the builtin 144 | # "default.css". 145 | html_static_path = ["_static"] 146 | 147 | # If not '', a 'Last updated on:' timestamp is inserted at every page 148 | # bottom, using the given strftime format. 149 | # html_last_updated_fmt = '%b %d, %Y' 150 | 151 | # If true, SmartyPants will be used to convert quotes and dashes to 152 | # typographically correct entities. 153 | # html_use_smartypants = True 154 | 155 | # Custom sidebar templates, maps document names to template names. 156 | # html_sidebars = {} 157 | 158 | # Additional templates that should be rendered to pages, maps page names 159 | # to template names. 160 | # html_additional_pages = {} 161 | 162 | # If false, no module index is generated. 163 | # html_domain_indices = True 164 | 165 | # If false, no index is generated. 166 | # html_use_index = True 167 | 168 | # If true, the index is split into individual pages for each letter. 169 | # html_split_index = False 170 | 171 | # If true, links to the reST sources are added to the pages. 172 | # html_show_sourcelink = True 173 | 174 | # If true, "Created using Sphinx" is shown in the HTML footer. 175 | # Default is True. 176 | # html_show_sphinx = True 177 | 178 | # If true, "(C) Copyright ..." is shown in the HTML footer. 179 | # Default is True. 180 | # html_show_copyright = True 181 | 182 | # If true, an OpenSearch description file will be output, and all pages 183 | # will contain a tag referring to it. The value of this option 184 | # must be the base URL from which the finished HTML is served. 185 | # html_use_opensearch = '' 186 | 187 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 188 | # html_file_suffix = None 189 | 190 | # Output file base name for HTML help builder. 191 | htmlhelp_basename = "partridgedoc" 192 | 193 | 194 | # -- Options for LaTeX output ------------------------------------------ 195 | 196 | latex_elements = { 197 | # The paper size ('letterpaper' or 'a4paper'). 198 | #'papersize': 'letterpaper', 199 | # The font size ('10pt', '11pt' or '12pt'). 200 | #'pointsize': '10pt', 201 | # Additional stuff for the LaTeX preamble. 202 | #'preamble': '', 203 | } 204 | 205 | # Grouping the document tree into LaTeX files. List of tuples 206 | # (source start file, target name, title, author, documentclass 207 | # [howto/manual]). 208 | latex_documents = [ 209 | ("index", "partridge.tex", u"partridge Documentation", u"Danny Whalen", "manual") 210 | ] 211 | 212 | # The name of an image file (relative to this directory) to place at 213 | # the top of the title page. 214 | # latex_logo = None 215 | 216 | # For "manual" documents, if this is true, then toplevel headings 217 | # are parts, not chapters. 218 | # latex_use_parts = False 219 | 220 | # If true, show page references after internal links. 221 | # latex_show_pagerefs = False 222 | 223 | # If true, show URL addresses after external links. 224 | # latex_show_urls = False 225 | 226 | # Documents to append as an appendix to all manuals. 227 | # latex_appendices = [] 228 | 229 | # If false, no module index is generated. 230 | # latex_domain_indices = True 231 | 232 | 233 | # -- Options for manual page output ------------------------------------ 234 | 235 | # One entry per manual page. List of tuples 236 | # (source start file, name, description, authors, manual section). 237 | man_pages = [("index", "partridge", u"partridge Documentation", [u"Danny Whalen"], 1)] 238 | 239 | # If true, show URL addresses after external links. 240 | # man_show_urls = False 241 | 242 | 243 | # -- Options for Texinfo output ---------------------------------------- 244 | 245 | # Grouping the document tree into Texinfo files. List of tuples 246 | # (source start file, target name, title, author, 247 | # dir menu entry, description, category) 248 | texinfo_documents = [ 249 | ( 250 | "index", 251 | "partridge", 252 | u"partridge Documentation", 253 | u"Danny Whalen", 254 | "partridge", 255 | "One line description of project.", 256 | "Miscellaneous", 257 | ) 258 | ] 259 | 260 | # Documents to append as an appendix to all manuals. 261 | # texinfo_appendices = [] 262 | 263 | # If false, no module index is generated. 264 | # texinfo_domain_indices = True 265 | 266 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 267 | # texinfo_show_urls = 'footnote' 268 | 269 | # If true, do not generate a @detailmenu in the "Top" node's menu. 270 | # texinfo_no_detailmenu = False 271 | -------------------------------------------------------------------------------- /partridge/config.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa E501 2 | 3 | import networkx as nx 4 | import pandas as pd 5 | 6 | from .parsers import vparse_date, vparse_time 7 | 8 | 9 | def empty_config() -> nx.DiGraph: 10 | return nx.DiGraph() 11 | 12 | 13 | def default_config() -> nx.DiGraph: 14 | G = empty_config() 15 | add_edge_config(G) 16 | add_node_config(G) 17 | return G 18 | 19 | 20 | def geo_config() -> nx.DiGraph: 21 | G = default_config() 22 | add_geo_config(G) 23 | return G 24 | 25 | 26 | def add_edge_config(g: nx.DiGraph) -> nx.DiGraph: 27 | g.add_edges_from( 28 | [ 29 | ( 30 | "agency.txt", 31 | "routes.txt", 32 | { 33 | "dependencies": [ 34 | {"agency.txt": "agency_id", "routes.txt": "agency_id"} 35 | ] 36 | }, 37 | ), 38 | ( 39 | "calendar.txt", 40 | "trips.txt", 41 | { 42 | "dependencies": [ 43 | {"calendar.txt": "service_id", "trips.txt": "service_id"} 44 | ] 45 | }, 46 | ), 47 | ( 48 | "calendar_dates.txt", 49 | "trips.txt", 50 | { 51 | "dependencies": [ 52 | {"calendar_dates.txt": "service_id", "trips.txt": "service_id"} 53 | ] 54 | }, 55 | ), 56 | ( 57 | "fare_attributes.txt", 58 | "fare_rules.txt", 59 | { 60 | "dependencies": [ 61 | {"fare_attributes.txt": "fare_id", "fare_rules.txt": "fare_id"} 62 | ] 63 | }, 64 | ), 65 | ( 66 | "fare_rules.txt", 67 | "stops.txt", 68 | { 69 | "dependencies": [ 70 | {"fare_rules.txt": "origin_id", "stops.txt": "zone_id"}, 71 | {"fare_rules.txt": "destination_id", "stops.txt": "zone_id"}, 72 | {"fare_rules.txt": "contains_id", "stops.txt": "zone_id"}, 73 | ] 74 | }, 75 | ), 76 | ( 77 | "fare_rules.txt", 78 | "routes.txt", 79 | { 80 | "dependencies": [ 81 | {"fare_rules.txt": "route_id", "routes.txt": "route_id"} 82 | ] 83 | }, 84 | ), 85 | ( 86 | "frequencies.txt", 87 | "trips.txt", 88 | { 89 | "dependencies": [ 90 | {"frequencies.txt": "trip_id", "trips.txt": "trip_id"} 91 | ] 92 | }, 93 | ), 94 | ( 95 | "routes.txt", 96 | "trips.txt", 97 | {"dependencies": [{"routes.txt": "route_id", "trips.txt": "route_id"}]}, 98 | ), 99 | ( 100 | "shapes.txt", 101 | "trips.txt", 102 | {"dependencies": [{"shapes.txt": "shape_id", "trips.txt": "shape_id"}]}, 103 | ), 104 | ( 105 | "stops.txt", 106 | "stop_times.txt", 107 | { 108 | "dependencies": [ 109 | {"stops.txt": "stop_id", "stop_times.txt": "stop_id"} 110 | ] 111 | }, 112 | ), 113 | ( 114 | "stop_times.txt", 115 | "trips.txt", 116 | { 117 | "dependencies": [ 118 | {"stop_times.txt": "trip_id", "trips.txt": "trip_id"} 119 | ] 120 | }, 121 | ), 122 | ( 123 | "transfers.txt", 124 | "stops.txt", 125 | { 126 | "dependencies": [ 127 | {"transfers.txt": "from_stop_id", "stops.txt": "stop_id"}, 128 | {"transfers.txt": "to_stop_id", "stops.txt": "stop_id"}, 129 | ] 130 | }, 131 | ), 132 | ] 133 | ) 134 | 135 | 136 | def add_node_config(g: nx.DiGraph) -> nx.DiGraph: 137 | g.add_nodes_from( 138 | [ 139 | ( 140 | "agency.txt", 141 | {"required_columns": ("agency_name", "agency_url", "agency_timezone")}, 142 | ), 143 | ( 144 | "calendar.txt", 145 | { 146 | "converters": { 147 | "start_date": vparse_date, 148 | "end_date": vparse_date, 149 | "monday": pd.to_numeric, 150 | "tuesday": pd.to_numeric, 151 | "wednesday": pd.to_numeric, 152 | "thursday": pd.to_numeric, 153 | "friday": pd.to_numeric, 154 | "saturday": pd.to_numeric, 155 | "sunday": pd.to_numeric, 156 | }, 157 | "required_columns": ( 158 | "service_id", 159 | "monday", 160 | "tuesday", 161 | "wednesday", 162 | "thursday", 163 | "friday", 164 | "saturday", 165 | "sunday", 166 | "start_date", 167 | "end_date", 168 | ), 169 | }, 170 | ), 171 | ( 172 | "calendar_dates.txt", 173 | { 174 | "converters": { 175 | "date": vparse_date, 176 | "exception_type": pd.to_numeric, 177 | }, 178 | "required_columns": ("service_id", "date", "exception_type"), 179 | }, 180 | ), 181 | ( 182 | "fare_attributes.txt", 183 | { 184 | "converters": { 185 | "price": pd.to_numeric, 186 | "payment_method": pd.to_numeric, 187 | "transfer_duration": pd.to_numeric, 188 | }, 189 | "required_columns": ( 190 | "fare_id", 191 | "price", 192 | "currency_type", 193 | "payment_method", 194 | "transfers", 195 | ), 196 | }, 197 | ), 198 | ("fare_rules.txt", {"required_columns": ("fare_id",)}), 199 | ( 200 | "feed_info.txt", 201 | { 202 | "converters": { 203 | "feed_start_date": vparse_date, 204 | "feed_end_date": vparse_date, 205 | }, 206 | "required_columns": ( 207 | "feed_publisher_name", 208 | "feed_publisher_url", 209 | "feed_lang", 210 | ), 211 | }, 212 | ), 213 | ( 214 | "frequencies.txt", 215 | { 216 | "converters": { 217 | "headway_secs": pd.to_numeric, 218 | "exact_times": pd.to_numeric, 219 | "start_time": vparse_time, 220 | "end_time": vparse_time, 221 | }, 222 | "required_columns": ( 223 | "trip_id", 224 | "start_time", 225 | "end_time", 226 | "headway_secs", 227 | ), 228 | }, 229 | ), 230 | ( 231 | "routes.txt", 232 | { 233 | "converters": {"route_type": pd.to_numeric}, 234 | "required_columns": ( 235 | "route_id", 236 | "route_short_name", 237 | "route_long_name", 238 | "route_type", 239 | ), 240 | }, 241 | ), 242 | ( 243 | "shapes.txt", 244 | { 245 | "converters": { 246 | "shape_pt_lat": pd.to_numeric, 247 | "shape_pt_lon": pd.to_numeric, 248 | "shape_pt_sequence": pd.to_numeric, 249 | "shape_dist_traveled": pd.to_numeric, 250 | }, 251 | "required_columns": ( 252 | "shape_id", 253 | "shape_pt_lat", 254 | "shape_pt_lon", 255 | "shape_pt_sequence", 256 | ), 257 | }, 258 | ), 259 | ( 260 | "stops.txt", 261 | { 262 | "converters": { 263 | "stop_lat": pd.to_numeric, 264 | "stop_lon": pd.to_numeric, 265 | "location_type": pd.to_numeric, 266 | "wheelchair_boarding": pd.to_numeric, 267 | "pickup_type": pd.to_numeric, 268 | "drop_off_type": pd.to_numeric, 269 | "shape_dist_traveled": pd.to_numeric, 270 | "timepoint": pd.to_numeric, 271 | }, 272 | "required_columns": ( 273 | "stop_id", 274 | "stop_name", 275 | "stop_lat", 276 | "stop_lon", 277 | ), 278 | }, 279 | ), 280 | ( 281 | "stop_times.txt", 282 | { 283 | "converters": { 284 | "arrival_time": vparse_time, 285 | "departure_time": vparse_time, 286 | "pickup_type": pd.to_numeric, 287 | "shape_dist_traveled": pd.to_numeric, 288 | "stop_sequence": pd.to_numeric, 289 | "timepoint": pd.to_numeric, 290 | }, 291 | "required_columns": ( 292 | "trip_id", 293 | "arrival_time", 294 | "departure_time", 295 | "stop_id", 296 | "stop_sequence", 297 | ), 298 | }, 299 | ), 300 | ( 301 | "transfers.txt", 302 | { 303 | "converters": { 304 | "transfer_type": pd.to_numeric, 305 | "min_transfer_time": pd.to_numeric, 306 | }, 307 | "required_columns": ("from_stop_id", "to_stop_id", "transfer_type"), 308 | }, 309 | ), 310 | ( 311 | "trips.txt", 312 | { 313 | "converters": { 314 | "direction_id": pd.to_numeric, 315 | "wheelchair_accessible": pd.to_numeric, 316 | "bikes_allowed": pd.to_numeric, 317 | }, 318 | "required_columns": ("route_id", "service_id", "trip_id"), 319 | }, 320 | ), 321 | ] 322 | ) 323 | 324 | 325 | def add_geo_config(g: nx.DiGraph) -> nx.DiGraph: 326 | from .geo import build_shapes, build_stops 327 | 328 | for node, transform in (("shapes.txt", build_shapes), ("stops.txt", build_stops)): 329 | assert node in g.nodes, "Missing config for node: {}".format(node) 330 | 331 | if "transformations" not in g.nodes[node]: 332 | g.nodes[node]["transformations"] = [] 333 | 334 | g.nodes[node]["transformations"].append(transform) 335 | 336 | return g 337 | 338 | 339 | def reroot_graph(G: nx.DiGraph, node: str) -> nx.DiGraph: 340 | """Return a copy of the graph rooted at the given node""" 341 | G = G.copy() 342 | for n, successors in list(nx.bfs_successors(G, source=node)): 343 | for s in successors: 344 | G.add_edge(s, n, **G.edges[n, s]) 345 | G.remove_edge(n, s) 346 | return G 347 | --------------------------------------------------------------------------------