def KV7planning(contents): result = {} c = ctx(contents) copy_table(c, 'LINE', ['DataOwnerCode', 'LinePlanningNumber', 'LinePublicNumber', 'LineName', 'LineVeTagNumber', 'TransportType']) copy_table(c, 'DESTINATION', ['DataOwnerCode', 'DestinationCode', 'DestinationName50', 'DestinationName30','DestinationName24','DestinationName19','DestinationName16','DestinationDetail24', 'DestinationDetail19', 'DestinationDetail16', 'DestinationDisplay16']) copy_table(c, 'DESTINATIONVIA', ['DataOwnerCode', 'DestinationCodeP', 'DestinationCodeC', 'DestinationViaOrderNr']) copy_table(c, 'TIMINGPOINT', ['DataOwnerCode', 'TimingPointCode', 'TimingPointName', 'TimingPointTown', 'StopAreaCode']) copy_table(c, 'USERTIMINGPOINT', ['DataOwnerCode', 'UserStopCode', 'TimingPointDataOwnerCode', 'TimingPointCode']) if 'LOCALSERVICEGROUPPASSTIME' in c.ctx: rows = c.ctx['LOCALSERVICEGROUPPASSTIME'].columns() print """COPY %d RECORDS INTO "sys".LOCALSERVICEGROUPPASSTIME FROM stdin USING DELIMITERS '\\t','\\n' NULL AS '';""" % (len(rows['DataOwnerCode'])) for x in range(0, len(rows['DataOwnerCode'])): if rows['WheelChairAccessible'][x] == 'ACCESSIBLE': WheelChairAccessible = True elif rows['WheelChairAccessible'][x] == 'NOTACCESSIBLE': WheelChairAccessible = False else: WheelChairAccessible = None IsTimingStop = (rows['IsTimingStop'][x] == '1') print '\t'.join([rows['DataOwnerCode'][x], rows['LocalServiceLevelCode'][x], rows['LinePlanningNumber'][x], rows['JourneyNumber'][x], rows['FortifyOrderNumber'][x], rows['UserStopCode'][x], rows['UserStopOrderNumber'][x], rows['LineDirection'][x], rows['DestinationCode'][x], rows['TargetArrivalTime'][x], rows['TargetDepartureTime'][x], rows['SideCode'][x], str(WheelChairAccessible or '').lower(), rows['JourneyStopType'][x], str(IsTimingStop).lower(), rows['ProductFormulaType'][x]])
def KV7planning(contents): result = {} c = ctx(contents) if 'DATAOWNER' in c.ctx: result['DATAOWNER'] = c.ctx['DATAOWNER'].rowsdict(['DataOwnerCode']) if 'DESTINATION' in c.ctx: result['DESTINATION'] = c.ctx['DESTINATION'].rowsdict(['DataOwnerCode', 'DestinationCode']) if 'USERTIMINGPOINT' in c.ctx: result['USERTIMINGPOINT'] = c.ctx['USERTIMINGPOINT'].rowsdict(['DataOwnerCode', 'UserStopCode']) if 'LINE' in c.ctx: result['LINE'] = c.ctx['LINE'].rowsdict(['DataOwnerCode', 'LinePlanningNumber']) if 'LOCALSERVICEGROUPPASSTIME' in c.ctx: result['LOCALSERVICEGROUPPASSTIME'] = {} for row in c.ctx['LOCALSERVICEGROUPPASSTIME'].rows(): localservicegrouppasstime = row['DataOwnerCode'] + '_' + row['LocalServiceLevelCode'] lineplanningnumber = '_'.join([row['DataOwnerCode'], row['LinePlanningNumber'], row['LineDirection']]) journeynumber = '_'.join([row['DataOwnerCode'], row['LocalServiceLevelCode'], row['LinePlanningNumber'], row['JourneyNumber'], row['FortifyOrderNumber']]) if localservicegrouppasstime not in result['LOCALSERVICEGROUPPASSTIME']: result['LOCALSERVICEGROUPPASSTIME'][localservicegrouppasstime] = { lineplanningnumber: { journeynumber: { int(row['UserStopOrderNumber']): row } } } elif lineplanningnumber not in result['LOCALSERVICEGROUPPASSTIME'][localservicegrouppasstime]: result['LOCALSERVICEGROUPPASSTIME'][localservicegrouppasstime][lineplanningnumber] = { journeynumber: { int(row['UserStopOrderNumber']): row } } elif journeynumber not in result['LOCALSERVICEGROUPPASSTIME'][localservicegrouppasstime][lineplanningnumber]: result['LOCALSERVICEGROUPPASSTIME'][localservicegrouppasstime][lineplanningnumber][journeynumber] = { int(row['UserStopOrderNumber']): row } else: result['LOCALSERVICEGROUPPASSTIME'][localservicegrouppasstime][lineplanningnumber][journeynumber][int(row['UserStopOrderNumber'])] = row if 'TIMINGPOINT' in c.ctx: result['TIMINGPOINT'] = c.ctx['TIMINGPOINT'].rowsdict(['TimingPointCode']) return result
def KV7planning(contents): result = {} c = ctx(contents) copy_table(c, 'LINE', [ 'DataOwnerCode', 'LinePlanningNumber', 'LinePublicNumber', 'LineName', 'LineVeTagNumber', 'TransportType' ]) copy_table(c, 'DESTINATION', [ 'DataOwnerCode', 'DestinationCode', 'DestinationName50', 'DestinationName30', 'DestinationName24', 'DestinationName19', 'DestinationName16', 'DestinationDetail24', 'DestinationDetail19', 'DestinationDetail16', 'DestinationDisplay16' ]) copy_table(c, 'DESTINATIONVIA', [ 'DataOwnerCode', 'DestinationCodeP', 'DestinationCodeC', 'DestinationViaOrderNr' ]) copy_table(c, 'TIMINGPOINT', [ 'DataOwnerCode', 'TimingPointCode', 'TimingPointName', 'TimingPointTown', 'StopAreaCode' ]) copy_table(c, 'USERTIMINGPOINT', [ 'DataOwnerCode', 'UserStopCode', 'TimingPointDataOwnerCode', 'TimingPointCode' ]) if 'LOCALSERVICEGROUPPASSTIME' in c.ctx: rows = c.ctx['LOCALSERVICEGROUPPASSTIME'].columns() print """COPY %d RECORDS INTO "sys".LOCALSERVICEGROUPPASSTIME FROM stdin USING DELIMITERS '\\t','\\n' NULL AS '';""" % ( len(rows['DataOwnerCode'])) for x in range(0, len(rows['DataOwnerCode'])): if rows['WheelChairAccessible'][x] == 'ACCESSIBLE': WheelChairAccessible = True elif rows['WheelChairAccessible'][x] == 'NOTACCESSIBLE': WheelChairAccessible = False else: WheelChairAccessible = None IsTimingStop = (rows['IsTimingStop'][x] == '1') print '\t'.join([ rows['DataOwnerCode'][x], rows['LocalServiceLevelCode'][x], rows['LinePlanningNumber'][x], rows['JourneyNumber'][x], rows['FortifyOrderNumber'][x], rows['UserStopCode'][x], rows['UserStopOrderNumber'][x], rows['LineDirection'][x], rows['DestinationCode'][x], rows['TargetArrivalTime'][x], rows['TargetDepartureTime'][x], rows['SideCode'][x], str(WheelChairAccessible or '').lower(), rows['JourneyStopType'][x], str(IsTimingStop).lower(), rows['ProductFormulaType'][x] ])
def KV7kalender(contents): c = ctx(contents) if 'LOCALSERVICEGROUP' in c.ctx: localservicegroup = [row['DataOwnerCode'] + '_' + row['LocalServiceLevelCode'] for row in c.ctx['LOCALSERVICEGROUP'].rows()] if 'LOCALSERVICEGROUPVALIDITY' in c.ctx: localservicegroupvalidity = {} for row in c.ctx['LOCALSERVICEGROUPVALIDITY'].rows(): localservicelevelcode = row['DataOwnerCode'] + '_' + row['LocalServiceLevelCode'] if localservicelevelcode in localservicegroup: if row['OperationDate'] not in localservicegroupvalidity: localservicegroupvalidity[row['OperationDate']] = [localservicelevelcode] else: localservicegroupvalidity[row['OperationDate']].append(localservicelevelcode) return localservicegroupvalidity
def KV7kalender(contents): c = ctx(contents) copy_table(c, 'LOCALSERVICEGROUP', ['DataOwnerCode', 'LocalServiceLevelCode']) copy_table(c, 'LOCALSERVICEGROUPVALIDITY', ['DataOwnerCode', 'LocalServiceLevelCode', 'OperationDate'])
client_annotate.bind(ZMQ_PUBSUB_KV8_ANNOTATE) # Set up a poller poller = zmq.Poller() poller.register(subscribe_kv8, zmq.POLLIN) poller.register(client_annotate, zmq.POLLIN) # Cache actuals = {} while True: socks = dict(poller.poll()) if socks.get(subscribe_kv8) == zmq.POLLIN: multipart = subscribe_kv8.recv_multipart() content = GzipFile('','r',0,StringIO(''.join(multipart[1:]))).read() c = ctx(content) if 'DATEDPASSTIME' in c.ctx: for row in c.ctx['DATEDPASSTIME'].rows(): if row['DataOwnerCode'] != 'GVB': continue # fid = '|'.join([row['DataOwnerCode'], row['LocalServiceLevelCode'], row['LinePlanningNumber'], row['JourneyNumber'], row['FortifyOrderNumber']]) + '_' + row['UserStopOrderNumber'] fid = row['JourneyNumber'] + '_' + row['UserStopOrderNumber'] hours, minutes, seconds = row['ExpectedDepartureTime'].split(':') departure = ((int(hours) * 60) + int(minutes)) * 60 + int(seconds) actuals[fid] = departure #sys.stderr.write('\r%d' % (len(actuals))) elif socks.get(client_annotate) == zmq.POLLIN: lookup = client_annotate.recv_json() result = {}
kv8.connect("tcp://83.98.158.170:7817") kv8.setsockopt(zmq.SUBSCRIBE, "/GOVI/KV8") poller = zmq.Poller() poller.register(client, zmq.POLLIN) poller.register(kv8, zmq.POLLIN) garbage = 0 while True: socks = dict(poller.poll()) if socks.get(kv8) == zmq.POLLIN: multipart = kv8.recv_multipart() content = GzipFile('', 'r', 0, StringIO(''.join(multipart[1:]))).read() c = ctx(content) if 'DATEDPASSTIME' in c.ctx: for row in c.ctx['DATEDPASSTIME'].rows(): storecurrect(row) sys.stdout.write('8') sys.stdout.flush() else: sys.stdout.write('.') sys.stdout.flush() elif socks.get(client) == zmq.POLLIN: url = client.recv() arguments = url.split('/') if arguments[0] == 'tpc': if len(arguments) == 1: