Permalink
Browse files

Merge pull request #16 from remix/representative-feed

Add convenience function for getting a representative feed view
  • Loading branch information...
invisiblefunnel committed Dec 18, 2017
2 parents f98980a + d58d488 commit 1dde52151cf72b4699fd685b58333fe015a5ee3d
Showing with 29 additions and 1 deletion.
  1. +2 −0 partridge/__init__.py
  2. +14 −1 partridge/readers.py
  3. +13 −0 tests/test_readers.py
View
@@ -1,6 +1,7 @@
from partridge.__version__ import __version__
from partridge.gtfs import feed, raw_feed
from partridge.readers import (
get_representative_feed,
read_service_ids_by_date,
read_dates_by_service_ids,
read_trip_counts_by_date,
@@ -15,6 +16,7 @@
'__version__',
'feed',
'raw_feed',
'get_representative_feed',
'read_service_ids_by_date',
'read_dates_by_service_ids',
'read_trip_counts_by_date',
View
@@ -1,7 +1,7 @@
from collections import defaultdict
import datetime
from partridge.gtfs import raw_feed
from partridge.gtfs import feed as mkfeed, raw_feed
from partridge.parsers import vparse_date
@@ -13,6 +13,19 @@
'''Public'''
def get_representative_feed(path):
feed = raw_feed(path)
service_ids_by_date = _service_ids_by_date(feed)
trip_counts_by_date = _trip_counts_by_date(feed)
date, _ = max(trip_counts_by_date.items(), key=lambda p: p[1])
service_ids = service_ids_by_date[date]
view = {'trips.txt': {'service_id': service_ids}}
return mkfeed(path, view=view)
def read_service_ids_by_date(path):
'''Find all service identifiers by date'''
feed = raw_feed(path)
View
@@ -4,6 +4,19 @@
import partridge as ptg
def test_get_representative_feed():
path = fixture('caltrain-2017-07-24.zip')
trip_counts_by_date = ptg.read_trip_counts_by_date(path)
service_ids_by_date = ptg.read_service_ids_by_date(path)
date, _ = max(trip_counts_by_date.items(), key=lambda p: p[1])
service_ids = service_ids_by_date[date]
feed = ptg.get_representative_feed(path)
assert isinstance(feed, ptg.feed)
assert feed.view == {'trips.txt': {'service_id': service_ids}}
def test_service_ids_by_date():
path = fixture('amazon-2017-08-06.zip')
service_ids_by_date = ptg.read_service_ids_by_date(path)

0 comments on commit 1dde521

Please sign in to comment.