Skip to content

Commit

Permalink
NOJIRA: Use DirectionId if available in SwiftlyGtfsRealTimeTranslator (
Browse files Browse the repository at this point in the history
…#58)

* Use DirectionId if avalailable

* autopep8
  • Loading branch information
JorgeBillini authored Nov 30, 2023
1 parent 321b046 commit b248ef6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions gtfs_realtime_translators/translators/swiftly.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,30 @@ def __call__(self, data):
RequiredFieldValidator.validate_field_value('stop_id', stop_id)
trip_updates = self.__make_trip_updates(data, stop_id)
entities.extend(trip_updates)

return FeedMessage.create(entities=entities)

@classmethod
def __make_trip_updates(cls, data, stop_id):
trip_updates = []
route_id = data.get("routeId")

##### Intersection Extensions
# Intersection Extensions
route_short_name = data.get("routeShortName")
route_long_name = data.get("routeName")
stop_name = data.get("stopName")

for destination in data["destinations"]:
# Intersection Extension
headsign = destination.get("headsign")

direction_id = destination.get("directionId", -1)
# realtime predictions
predictions = enumerate(destination["predictions"])
for _idx, arrival in predictions:
entity_id = str(_idx + 1)
now = int(pendulum.now().timestamp())
arrival_or_departure_time = now + math.floor(arrival.get("sec") / 60) * 60
arrival_or_departure_time = now + \
math.floor(arrival.get("sec") / 60) * 60
trip_id = arrival.get('tripId')

trip_update = TripUpdate.create(entity_id=entity_id,
Expand All @@ -57,8 +58,10 @@ def __make_trip_updates(cls, data, stop_id):
route_long_name=route_long_name,
stop_id=stop_id,
stop_name=stop_name,
headsign=headsign)
headsign=headsign,
direction_id=direction_id,
)

trip_updates.append(trip_update)

return trip_updates

0 comments on commit b248ef6

Please sign in to comment.