Skip to content

Commit

Permalink
Merge pull request #16 from HSLdevcom/tre-trams
Browse files Browse the repository at this point in the history
Parse mode from otp data into topic
  • Loading branch information
vesameskanen authored Apr 13, 2021
2 parents 56f42b4 + 771eb8d commit 2133ab6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gtfsrthttp2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ def doGTFSRTPolling(self):
vehicle_id = entity.vehicle.vehicle.id
short_name = utils.parse_short_name(self.feedName, trip_id, route_id, self.OTPData)
color = utils.parse_color(self.feedName, trip_id, route_id, self.OTPData)
mode = utils.parse_mode(self.feedName, trip_id, route_id, self.OTPData)

# gtfsrt/vp/<feed_name>/<agency_id>/<agency_name>/<mode>/<route_id>/<direction_id>/<trip_headsign>/<trip_id>/<next_stop>/<start_time>/<vehicle_id>/<geohash_head>/<geohash_firstdeg>/<geohash_seconddeg>/<geohash_thirddeg>/<short_name>/<color>/
# GTFS RT feed used for testing was missing some information so those are empty
full_topic = '{0}/{1}////{2}/{3}/{4}/{5}/{6}/{7}/{8}/{9}/{10}/{11}/{12}/{13}/{14}/'.format(
self.baseMqttTopic, self.feedName, route_id, direction_id,
full_topic = '{0}/{1}///{2}/{3}/{4}/{5}/{6}/{7}/{8}/{9}/{10}/{11}/{12}/{13}/{14}/{15}/'.format(
self.baseMqttTopic, self.feedName, mode, route_id, direction_id,
trip_headsign, trip_id, stop_id, start_time, vehicle_id, geohash_head, geohash_firstdeg,
geohash_seconddeg, geohash_thirddeg, short_name, color)

Expand Down
16 changes: 16 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ def parse_color(feed, trip_id, route_id, otp_data):
return ""
return otp_data[feed + ":" + route_id]["color"] or ""

def parse_mode(feed, trip_id, route_id, otp_data):
if otp_data == None:
return ""
elif feed == "OULU":
feed_scoped_id = "OULU:" + trip_id
if feed_scoped_id not in otp_data:
return ""
return otp_data[feed_scoped_id]["route"]["mode"] or ""

feed_scoped_id = feed + ":" + route_id
if feed_scoped_id not in otp_data:
return ""
return otp_data[feed + ":" + route_id]["mode"] or ""

def get_OTP_query(feed):
if feed == "OULU":
return """
Expand All @@ -56,6 +70,7 @@ def get_OTP_query(feed):
shortName
gtfsId
color
mode
}
gtfsId
pattern {
Expand All @@ -71,6 +86,7 @@ def get_OTP_query(feed):
gtfsId
shortName
color
mode
}
}
""" % feed
Expand Down

0 comments on commit 2133ab6

Please sign in to comment.