Skip to content

Commit

Permalink
consolidate quality checks for stop id (#49)
Browse files Browse the repository at this point in the history
* consolidate quality checks for stop id

* proper quotes
  • Loading branch information
hamima-halim authored Jan 11, 2024
1 parent 0a9237d commit e7823d8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/event.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from datetime import date, datetime
from typing import Tuple
import pandas as pd
Expand Down Expand Up @@ -47,12 +48,13 @@ def reduce_update_event(update):

try:
# The vehicle’s current (when current_status is STOPPED_AT) or next stop.
if "stop" in update["relationships"]:
stop_id = update["relationships"]["stop"]["data"]["id"]
else:
stop_id = None
except TypeError:
logger.error(f"Encountered TypeError when processing update: {update}")
stop_id = update["relationships"]["stop"]["data"]["id"]
except (TypeError, KeyError):
logger.error(
f"Encountered degenerate stop information. This event will be skipped: {json.dumps(update)}",
stack_info=True,
exc_info=True,
)
stop_id = None

return (
Expand Down Expand Up @@ -105,7 +107,6 @@ def process_event(
prev["updated_at"] = datetime.fromisoformat(prev["updated_at"])

if stop_id is None:
logger.info(f"Skipping event with no stop_id: {update}")
return

is_departure_event, is_arrival_event = arr_or_dep_event(
Expand Down

0 comments on commit e7823d8

Please sign in to comment.