Skip to content

Commit

Permalink
Merge pull request #15 from HSLdevcom/route-color
Browse files Browse the repository at this point in the history
Add route color to topic
  • Loading branch information
optionsome authored Mar 2, 2021
2 parents 7361e9b + 13e22c0 commit 56f42b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gtfsrthttp2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ def doGTFSRTPolling(self):
start_time = entity.vehicle.trip.start_time[0:5] # hh:mm
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)

# 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>/
# 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}/'.format(
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,
trip_headsign, trip_id, stop_id, start_time, vehicle_id, geohash_head, geohash_firstdeg,
geohash_seconddeg, geohash_thirddeg, short_name)
geohash_seconddeg, geohash_thirddeg, short_name, color)

sernmesg = nfeedmsg.SerializeToString()
self.client.publish(full_topic, sernmesg)
Expand Down
16 changes: 16 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ def parse_short_name(feed, trip_id, route_id, otp_data):
return ""
return otp_data[feed + ":" + route_id]["shortName"]

def parse_color(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"]["color"] or ""

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

def get_OTP_query(feed):
if feed == "OULU":
return """
Expand All @@ -41,6 +55,7 @@ def get_OTP_query(feed):
route {
shortName
gtfsId
color
}
gtfsId
pattern {
Expand All @@ -55,6 +70,7 @@ def get_OTP_query(feed):
routes(feeds: [\"%s\"]) {
gtfsId
shortName
color
}
}
""" % feed
Expand Down

0 comments on commit 56f42b4

Please sign in to comment.