Skip to content

Commit

Permalink
bug: JSON output sometimes contains empty named property
Browse files Browse the repository at this point in the history
doc: documentation update
  • Loading branch information
JeffJacobson committed Sep 6, 2018
1 parent c949a3d commit 4d496a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 19 additions & 1 deletion wsdottraffic/fielddetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,21 @@ def _get_field_type(value):

class FieldInfo(object):
"""Represents parameters for creating fields.
Attributes:
field_name: name of the field
field_length: length of field. Only applicable to certain data types.
field_type: data type of field
field_is_nullable: indicates if the field is nullable.
"""
def __init__(self, name, value, template=None):
"""Creates a new FieldInfo instance.
Args:
name: field name
value: value used to determine the data type of the field
template: Another FieldInfo object to be used as a template
"""
self.field_name = None
self.field_length = None
self.field_type = None
Expand Down Expand Up @@ -137,6 +150,11 @@ def __init__(self, name, value, template=None):
def from_features(features):
"""Extracts a list of FieldInfos from a list of dicts representing
GDB features
Args:
features: a list of dicts that define features
Returns:
A dict of field infos keyed by field_name.
"""
master = {}
for feature in features:
Expand All @@ -151,7 +169,7 @@ def from_features(features):


def _iter_field_infos(feature_dict):
"""Iterates over dict key/value paris and yields FieldInfo objects
"""Iterates over dict key/value pairs and yields FieldInfo objects
"""
for key, val in feature_dict.items():
next_fi = FieldInfo(key, val)
Expand Down
7 changes: 4 additions & 3 deletions wsdottraffic/jsonhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def parse_traveler_info_object(dct):
for roadway_location_key in val:
new_key = key + roadway_location_key
new_key = _simplify_field_name(new_key)
if new_key and val.get(roadway_location_key) is None:
if not new_key or (new_key and val.get(roadway_location_key) is None):
continue
if (road_name_field.match(new_key) and
val.get(roadway_location_key) and
Expand All @@ -89,7 +89,7 @@ def parse_traveler_info_object(dct):
output[new_key] = val[roadway_location_key]
else:
simplified_key = _simplify_field_name(key)
if simplified_key and val is None:
if not simplified_key or (simplified_key and val is None):
continue
if simplified_key == "LocationID":
output[simplified_key] = "{%s}" % val
Expand All @@ -102,7 +102,6 @@ def parse_traveler_info_object(dct):
output[simplified_key] = val
return output


def to_geo_json(dct):
"""This method is used by the json.load method to customize how
the traffic info objects are deserialized.
Expand Down Expand Up @@ -137,6 +136,8 @@ def to_geo_json(dct):
]
}
nonproperty_fields = multi_point_geo_fields
else:
outdict["geometry"] = None
for key, value in dct.items():
if key in nonproperty_fields:
continue
Expand Down

0 comments on commit 4d496a8

Please sign in to comment.