needle = 'A%08X' % (zlib.crc32('|'.join([
                    str(message[x]) for x in
                    ['dataownercode', 'messagecodedate', 'messagecodenumber']
                ])))

                if message['messagetype'] == 'DELETEMESSAGE':
                    feedentity = feedmessage.entity.add()
                    feedentity.id = str(needle)
                    removeAlert(feedentity, needle)

                elif message['messagetype'] == 'STOPMESSAGE' and message[
                        'messagedurationtype'] != "FIRSTVEJO":
                    feedentity = feedmessage.entity.add()
                    feedentity.id = str(needle)
                    getAlertKV15(feedentity, message, needle)

        elif kv17 in sockets and sockets[kv17] == zmq.POLLIN:
            packet = kv17.recv_json()

            feedmessage = FeedMessage()
            feedmessage.header.gtfs_realtime_version = "1.0"
            feedmessage.header.incrementality = gtfs_realtime_pb2.FeedHeader.DIFFERENTIAL
            feedmessage.header.timestamp = int(
                time.mktime(
                    iso8601.parse_date(packet['timestamp']).timetuple()))

            for cvlinfo in packet['cvlinfo']:
                if 'journey' not in cvlinfo:
                    continue
Exemplo n.º 2
0
from gtfs_realtime_pb2 import FeedEntity

import utils
from google.protobuf import text_format

print 'getTripId', utils.getTripId('CXX', 'M300', '340', '2013-06-03')

print 'getRouteId', utils.getStopId('ARR', '49005091')

print 'getStopSequenceTripId', utils.getStopSequenceTripId('CXX', 'M300', '340', '2013-06-03', '57430800', '0')

posinfo = {'operatingday':  '2013-06-03', 'dataownercode': 'CXX', 'lineplanningnumber': 'M300', 'journeynumber': '340', 'messagetype': 'ONSTOP', 'rd-x': 150000, 'rd-y': 300000, 'userstopcode': '57430800', 'passagesequencenumber': '0', 'timestamp': '2013-06-03T02:00:00'}
feedentity = FeedEntity()
utils.getVehiclePosition(feedentity, posinfo)
print 'getVehiclePosition', text_format.MessageToString(feedentity)

message = {'operatingday':  '2013-06-03', 'dataownercode': 'CXX', 'lineplanningnumber': 'M300', 'userstopcodes': ['57430800'], 'messagecontent': 'Hello World', 'messagestarttime': '2012-01-01T00:00:00', 'messagedurationtype': 'REMOVE'}
feedentity = FeedEntity()
utils.getAlertKV15(feedentity, message)
print 'getAlertKV15', text_format.MessageToString(feedentity)

operation = {'messagetype': 'CANCEL'}
journey = {'operatingday':  '2013-06-03', 'dataownercode': 'CXX', 'lineplanningnumber': 'M300', 'journeynumber': '340'}
feedentity = FeedEntity()
utils.getAlertKV17(feedentity, operation, journey)
print 'getAlertKV17', text_format.MessageToString(feedentity)
            for message in packet['messages']:
                if message['messagetype'] == 'STOPERRORMESSAGE':
                    continue

                needle = 'A%08X' % (zlib.crc32('|'.join([str(message[x]) for x in ['dataownercode', 'messagecodedate', 'messagecodenumber']])))

                if message['messagetype'] == 'DELETEMESSAGE':
                    feedentity = feedmessage.entity.add()
                    feedentity.id = str(needle)
                    removeAlert(feedentity, needle)

                elif message['messagetype'] == 'STOPMESSAGE' and message['messagedurationtype'] != "FIRSTVEJO":
                    feedentity = feedmessage.entity.add()
                    feedentity.id = str(needle)
                    getAlertKV15(feedentity, message, needle)

        elif kv17 in sockets and sockets[kv17] == zmq.POLLIN:
            packet = kv17.recv_json()

            feedmessage = FeedMessage()
            feedmessage.header.gtfs_realtime_version = "1.0"
            feedmessage.header.incrementality = gtfs_realtime_pb2.FeedHeader.DIFFERENTIAL
            feedmessage.header.timestamp = int(time.mktime(iso8601.parse_date(packet['timestamp']).timetuple()))

            for cvlinfo in packet['cvlinfo']:
                if 'journey' not in cvlinfo:
                    continue

                if 'mutatejourney' in cvlinfo:
                    needle = 'J%08X' % (abs(zlib.crc32('|'.join([str(cvlinfo['journey'][x]) for x in ['dataownercode', 'lineplanningnumber', 'operatingday', 'journeynumber', 'reinforcementnumber']]))))