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

                    for operation in cvlinfo['mutatejourney']:
                        if operation['messagetype'] == 'CANCEL':
                            feedentity = feedmessage.entity.add()
                            feedentity.id = str(needle)
                            getAlertKV17(feedentity, operation,
                                         cvlinfo['journey'])

                        elif operation['messagetype'] == 'RECOVER':
                            feedentity = feedmessage.entity.add()
                            feedentity.id = str(needle)
                            removeAlert(feedentity)

                if 'mutatejourneystop' in cvlinfo:
                    for operation in cvlinfo['mutatejourneystop']:
                        if operation['messagetype'] == 'MUTATIONMESSAGE':
                            needle = 'M%08X' % (abs(
                                zlib.crc32('|'.join([
                                    str(cvlinfo['journey'][x]) for x in [
                                        'dataownercode', 'lineplanningnumber',
                                        'operatingday', 'journeynumber',
                                        'reinforcementnumber'
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)
            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']]))))

                    for operation in cvlinfo['mutatejourney']:
                        if operation['messagetype'] == 'CANCEL':
                            feedentity = feedmessage.entity.add()
                            feedentity.id = str(needle)
                            getAlertKV17(feedentity, operation, cvlinfo['journey'])

                        elif operation['messagetype'] == 'RECOVER':
                            feedentity = feedmessage.entity.add()
                            feedentity.id = str(needle)
                            removeAlert(feedentity)


                if 'mutatejourneystop' in cvlinfo:
                    for operation in cvlinfo['mutatejourneystop']:
                        if operation['messagetype'] == 'MUTATIONMESSAGE':
                            needle = 'M%08X' % (abs(zlib.crc32('|'.join([str(cvlinfo['journey'][x]) for x in ['dataownercode', 'lineplanningnumber', 'operatingday', 'journeynumber', 'reinforcementnumber']] + [operation['userstopcode']]))))
                            feedentity = feedmessage.entity.add()
                            feedentity.id = str(needle)
                            getAlertKV17(feedentity, operation, cvlinfo['journey'], operation['userstopcode'])