Skip to content

Commit

Permalink
MTA Subway: remove unnecessary conversion (#16)
Browse files Browse the repository at this point in the history
* conversion is actually unnecessary
  • Loading branch information
AlexChaseJones authored Oct 16, 2019
1 parent d56f1fb commit 047a530
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 4 additions & 10 deletions gtfs_realtime_translators/translators/mta_subway.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pendulum

from gtfs_realtime_translators.factories import TripUpdate, FeedMessage


Expand Down Expand Up @@ -29,22 +27,18 @@ def parse_id(cls, value):
except Exception:
return value

@classmethod
def to_gmt_timestamp(cls, timestamp):
return int(pendulum.from_timestamp(timestamp).subtract(hours=4).timestamp())

@classmethod
def __make_trip_update(cls, _id, route_id, stop_name, arrival):
entity_id = str(_id + 1)
arrival_time = cls.to_gmt_timestamp(arrival['serviceDay'] + arrival['realtimeArrival'])
departure_time = cls.to_gmt_timestamp(arrival['serviceDay'] + arrival['realtimeDeparture'])
arrival_time = arrival['serviceDay'] + arrival['realtimeArrival']
departure_time = arrival['serviceDay'] + arrival['realtimeDeparture']
trip_id = cls.parse_id(arrival['tripId'])
stop_id = cls.parse_id(arrival['stopId'])

##### Intersection Extensions
headsign = arrival['tripHeadsign']
scheduled_arrival_time = cls.to_gmt_timestamp(arrival['serviceDay'] + arrival['scheduledArrival'])
scheduled_departure_time = cls.to_gmt_timestamp(arrival['serviceDay'] + arrival['scheduledDeparture'])
scheduled_arrival_time = arrival['serviceDay'] + arrival['scheduledArrival']
scheduled_departure_time = arrival['serviceDay'] + arrival['scheduledDeparture']
return TripUpdate.create(entity_id=entity_id,
arrival_time=arrival_time,
departure_time=departure_time,
Expand Down
4 changes: 2 additions & 2 deletions test/test_mta_subway.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def test_mta_subway_data(mta_subway):

assert entity.id == '1'

assert stop_time_update.arrival.time == 1569492935
assert stop_time_update.departure.time == 1569492935
assert stop_time_update.arrival.time == 1569507335
assert stop_time_update.departure.time == 1569507335
assert stop_time_update.stop_id == '101N'
assert entity.trip_update.trip.route_id == '1'
assert entity.trip_update.trip.trip_id == '2351'
Expand Down

0 comments on commit 047a530

Please sign in to comment.