Skip to content

Commit

Permalink
Parsing work complete
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespfennell committed May 28, 2020
1 parent 5cb80b1 commit c958403
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tests/unit/parse/test_gtfsrealtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ def build_test_parse_vehicle_params(gtfs):
stop_id="7",
current_status=VEHICLE_STOP_STATUS.value,
congestion_level=CONGESTION_LEVEL.value,
# occupancy_status=1,
# occupancy_percentage=1 # TODO?
occupancy_status=OCCUPANCY_STATUS.value,
),
parse.Vehicle(
id=VEHICLE_ID,
Expand All @@ -493,8 +492,25 @@ def build_test_parse_vehicle_params(gtfs):
current_stop_id="7",
current_status=VEHICLE_STOP_STATUS,
congestion_level=CONGESTION_LEVEL,
# occupancy_status=1,
# occupancy_percentage=1
occupancy_status=OCCUPANCY_STATUS,
),
],
[ # Some data not copied
None,
gtfs.VehiclePosition(
vehicle=gtfs.VehicleDescriptor(id=VEHICLE_ID),
position=gtfs.Position(latitude=1.0, longitude=2.0,),
current_stop_sequence=6,
stop_id="7",
occupancy_status=OCCUPANCY_STATUS.value,
),
parse.Vehicle(
id=VEHICLE_ID,
latitude=1.0,
longitude=2.0,
current_stop_sequence=6,
current_stop_id="7",
occupancy_status=OCCUPANCY_STATUS,
),
],
[None, None, None], # No data at all
Expand Down
4 changes: 4 additions & 0 deletions transiter/parse/gtfsrealtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ def parse_vehicles(feed_message):
vehicle.congestion_level = parse.Vehicle.CongestionLevel(
vehicle_position.congestion_level
)
if vehicle_position.HasField("occupancy_status"):
vehicle.occupancy_status = parse.Vehicle.OccupancyStatus(
vehicle_position.occupancy_status
)
yield vehicle


Expand Down
2 changes: 2 additions & 0 deletions transiter/parse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class OccupancyStatus(enum.Enum):
CRUSHED_STANDING_ROOM_ONLY = 4
FULL = 5
NOT_ACCEPTING_PASSENGERS = 6
UNKNOWN = 100

id: str
trip_id: str = None
Expand All @@ -205,6 +206,7 @@ class OccupancyStatus(enum.Enum):
speed: float = None
updated_at: datetime.datetime = None
congestion_level: CongestionLevel = CongestionLevel.UNKNOWN_CONGESTION_LEVEL
occupancy_status: OccupancyStatus = OccupancyStatus.UNKNOWN


@dataclass
Expand Down

0 comments on commit c958403

Please sign in to comment.