-
Notifications
You must be signed in to change notification settings - Fork 34
Update routes for specific dates #638
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
base: master
Are you sure you want to change the base?
Changes from 52 commits
614bfe3
857fe04
c87b43e
3817c06
22cb4c3
e56fa1e
28b1931
cb55856
33a8e53
690e0cc
0c9fba6
26f1772
9998299
ee2ebe5
50812c4
5f7112f
652a459
36565da
7ac1b10
6ebe655
ff9500b
e618a1f
aa0b423
d4f13f8
6e0c3b3
24f56e9
bb7dbf4
4d568e4
d5a7cbc
0bf3cf2
e496466
93b90b7
af19055
483a0b2
2084742
385e209
8711770
f35f14a
e219b42
198a3ae
8fcbb5b
46c9927
d4f8b72
2a4c807
a5f5a62
4d24dfe
fdba9b7
d2be8d4
78e5386
ed4c4d7
3b30c68
7b81c1a
8a7443c
de0b556
5639610
db1bacc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| import gzip | ||
| import hashlib | ||
| import zipfile | ||
| import os | ||
| from datetime import datetime, timedelta | ||
|
|
||
| from . import config, util, nextbus, routeconfig, timetables | ||
|
|
||
|
|
@@ -49,28 +51,35 @@ def get_stop_geometry(stop_xy, shape_lines_xy, shape_cumulative_dist, start_inde | |
| 'after_index': best_index, # the index of the coordinate of the shape just before this stop | ||
| 'offset': int(best_offset) # distance in meters between this stop and the closest line segment of shape | ||
| } | ||
|
|
||
|
|
||
| def download_gtfs_data(agency: config.Agency, gtfs_cache_dir): | ||
| def get_gtfs_data(agency: config.Agency, gtfs_cache_dir, gtfs_path=None): | ||
| cache_dir = Path(gtfs_cache_dir) | ||
| zip_path = f'{util.get_data_dir()}/gtfs-{agency.id}.zip' | ||
| gtfs_url = agency.gtfs_url | ||
|
|
||
|
|
||
| if gtfs_url is None: | ||
| raise Exception(f'agency {agency.id} does not have gtfs_url in config') | ||
|
|
||
| cache_dir = Path(gtfs_cache_dir) | ||
|
|
||
| if not cache_dir.exists(): | ||
| print(f'downloading gtfs data from {gtfs_url}') | ||
| r = requests.get(gtfs_url) | ||
|
|
||
| if r.status_code != 200: | ||
| raise Exception(f"Error fetching {gtfs_url}: HTTP {r.status_code}: {r.text}") | ||
|
|
||
| zip_path = f'{util.get_data_dir()}/gtfs-{agency.id}.zip' | ||
|
|
||
| with open(zip_path, 'wb') as f: | ||
| f.write(r.content) | ||
|
|
||
| with zipfile.ZipFile(zip_path, 'r') as zip_ref: | ||
| zip_ref.extractall(gtfs_cache_dir) | ||
| if gtfs_path is not None: | ||
| zip_path = gtfs_path | ||
|
|
||
| with zipfile.ZipFile(zip_path, 'r') as zip_ref: | ||
| zip_ref.extractall(gtfs_cache_dir) | ||
|
|
||
|
|
||
| def is_subsequence(smaller, bigger): | ||
| smaller_len = len(smaller) | ||
| bigger_len = len(bigger) | ||
|
|
@@ -108,15 +117,14 @@ def contains_excluded_stop(shape_stop_ids, excluded_stop_ids): | |
| return False | ||
|
|
||
| class GtfsScraper: | ||
| def __init__(self, agency: config.Agency): | ||
| def __init__(self, agency: config.Agency, gtfs_path=None): | ||
| self.agency = agency | ||
| self.agency_id = agency_id = agency.id | ||
| gtfs_cache_dir = f'{util.get_data_dir()}/gtfs-{agency_id}' | ||
|
|
||
| download_gtfs_data(agency, gtfs_cache_dir) | ||
| get_gtfs_data(agency, gtfs_cache_dir, gtfs_path=gtfs_path) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For say trimet, the GTFS directory ends up being: Then, in line 127 the GTFS that's passed in ends up being the one in gtfs_cache_dir, so gtfs_path ends up not being used.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added an if-else which should solve that. I think there are cleaner ways, and I haven't yet done a good job of testing this fix.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am going to re-request a review at this point. Thank you so much for looking through this over and over again! |
||
|
|
||
| self.feed = ptg.load_geo_feed(gtfs_cache_dir, {}) | ||
|
|
||
| self.errors = [] | ||
| self.stop_times_by_trip = None | ||
| self.stops_df = None | ||
|
|
@@ -261,7 +269,6 @@ def save_timetables(self, save_to_s3=False, skip_existing=False): | |
| agency_id = self.agency_id | ||
|
|
||
| dates_map = self.get_services_by_date() | ||
|
|
||
| # | ||
| # Typically, many dates have identical scheduled timetables (with times relative to midnight on that date). | ||
| # Instead of storing redundant timetables for each date, store one timetable per route for each unique set of service_ids. | ||
|
|
@@ -1078,4 +1085,4 @@ def save_routes(self, save_to_s3, d): | |
|
|
||
| routes = [routeconfig.RouteConfig(agency_id, route_data) for route_data in routes_data] | ||
|
|
||
| routeconfig.save_routes(agency_id, routes, save_to_s3=save_to_s3) | ||
| routeconfig.save_routes(agency_id, routes, save_to_s3=save_to_s3, gtfs_date=d) | ||
Uh oh!
There was an error while loading. Please reload this page.