Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link routes to default agency on import #43

Open
alaw005 opened this issue May 1, 2015 · 2 comments
Open

Link routes to default agency on import #43

alaw005 opened this issue May 1, 2015 · 2 comments

Comments

@alaw005
Copy link
Contributor

alaw005 commented May 1, 2015

The agency_id field is optional for feeds with only one agency. This means that routes are not directly associated within an agency on import as there appears to be no relationship .

Suggest that on import check to see if there is only one agency present. If there is only one agency then assign it a default agency_id (e.g. 1) and update the route records to reference this new agency.

I don't fully understand the import process but it would appear that a good option might be to update the "import_gtfs" function in the feed model (immediately before update geometries)? I attempted adding a a default value of 1 to agency_id and Agency and agency_id in Route but this didn't work.

@jwhitlock
Copy link
Member

Check out the test_import_minimal test. If the agency_id column is omitted, then Agency.agency_id is a blank string.

It is true that there is no direct link from the route to the agency in this case. However, they are both part of the same feed, so you can derive the relation from that. If you need to make this link explicit, then you'll have to post-process the feed.

@alaw005
Copy link
Contributor Author

alaw005 commented May 1, 2015

I suppose the current behavior is true to the GTFS so correct. I think an explicit link would be useful as an Agency object does exist for that feed, it just isn't referenced in the Route object.

Would it be sensible to make changes to this section of the feed import i.e. immediately before the geometries are updated? I'm only learning python/django but looking at your existing code would something like this work:

if self.agency_set.count() == 1:
    start_time = time.time()
    for route in self.route_set.all():
        route.agency_id = self.agency
    end_time = time.time()
    logger.info(
        "Assigned default agency for %d routes in %0.1f seconds",
        self.route_set.count(), end_time - start_time)

Also, thank you for your help/guidance on my earlier input which was my first "official" adventure in contributing to a project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants