Skip to content

Commit 6096d86

Browse files
committed
fix(stop_code): allow stop_code as none value .. no longer default stop id value
1 parent e7b6f9e commit 6096d86

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

gtfsdb/model/stop.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,10 @@ def query_active_stop_ids(cls, session, limit=None, active_filter=True):
199199
def post_make_record(cls, row, **kwargs):
200200
""" NOTE: this is a (derived from base.py) method to fix up stop records before committing the record to the db """
201201

202-
# SMART (5/2024) has a stop record w/out a stop name, so let's fix that here and prevent the
202+
# SMART (5/2024) has a stop record w/out a stop name, so let's fix that here and prevent an empty name
203203
if row.get('stop_name') is None:
204-
row['stop_name'] = "Stop ID {}".format(row.get('stop_id'))
205-
log.warning(row['stop_name'])
206-
207-
# seen a few feeeds w/out a stop_code -- fix that here
208-
if row.get('stop_code') is None:
209-
row['stop_code'] = row['stop_id']
204+
code = row.get('stop_code', row.get('stop_id'))
205+
row['stop_name'] = f"Stop ID {code}"
210206

211207
return row
212208

gtfsdb/model/stop_base.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ class StopBase(object):
1212
"""
1313
StopBase provides a generic set of stop query routines
1414
"""
15-
16-
def get_stop_code(self):
15+
def get_stop_code(self, def_val=""):
1716
"""
18-
should this method just return "" if no stop code, ala this blurb from GTFS:
17+
will return "" if no stop code in the data, per this blurb from GTFS:
1918
'This field should be left empty for locations without a code presented to riders.'
2019
"""
21-
ret_val = self.stop_id
20+
ret_val = def_val
2221
try:
2322
if self.stop_code and len(self.stop_code) > 0:
2423
ret_val = self.stop_code
25-
else:
26-
ret_val = self.stop_id
2724
except Exception as e:
2825
log.warning(e)
2926
return ret_val
@@ -121,8 +118,8 @@ def query_stops(cls, session, **kwargs):
121118
will query the db for a stop, either via bbox, point & distance or just an id
122119
:return list of stops
123120
"""
124-
ret_val = []
125121
# import pdb; pdb.set_trace()
122+
ret_val = []
126123
if kwargs.get('lat') or kwargs.get('min_lat'):
127124
bbox = BBox(**kwargs)
128125
if bbox.is_valid:

gtfsdb/scripts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def get_args(prog_name='gtfsdb-load', do_parse=True, def_db=config.DEFAULT_DATAB
5252
help='create new db tables (note: not currently used in gtfsdb, which always creates tables)')
5353
parser.add_argument('--print', '-p', action="store_true",
5454
help='print results from some sql query or data transform to cmdline')
55+
parser.add_argument('--ignore_stop_codes', '-nsc', default=False, action='store_true',
56+
help="no public stop codes or ids should be used, so don't publish stop codes to downstream systems")
5557
parser.add_argument('--current_tables', '-ct', default=False, action='store_true',
5658
help="create tables that represent 'current' service (e.g., views)")
5759
parser.add_argument('--current_tables_all', '-cta', default=False, action='store_true',

0 commit comments

Comments
 (0)