def setUp(self): # Does Not send a Request (Send data) to ODE. # Just Connects to ODE & processes the message received in # in the client On_message handler ode = client.ODEClient(self.host, on_open=lambda ws: None) ode.get_token(self.userName, self.password) self.client = None self.client = client.AsyncODEClient(odeClient=ode) self.region = testRunnerHelper.build_region(self.service_region)
def initialize(self, full_config_path): self.config = config = testRunnerHelper.parse_config_file( full_config_path) self.config['START_DATE'] = "2014-01-13T19:52:45.500Z" self.config['END_DATE'] = "2015-09-17T17:52:45.500Z" self.logger.info(config['TEST_NAME']) ode = client.ODEClient(self.config['HOST']) ode.get_token(self.config['USERNAME'], self.config['PASSWORD']) self.client = None self.client = client.AsyncODEClient(odeClient=ode) self.config['TEST_REQUEST'] = None
def create_asyncClient_and_request(self, the_config, **kwargs): ode = client.ODEClient(the_config['HOST']) ode.get_token(the_config['USERNAME'], the_config['PASSWORD']) asycODE = client.AsyncODEClient(odeClient=ode) if the_config['REQUEST_TYPE'] in [ 'sub', ]: request = testRunnerHelper.build_subscription_request( the_config, **kwargs) else: request = testRunnerHelper.build_query_request( the_config, **kwargs) self.logger.info("Request: %s", request.toJson()) asycODE.setRequest(request) return asycODE
def setUp(self): self.logger.addHandler( logging.FileHandler( os.path.join('.', 'log_outputs', 'ODE_Query_Downloads_Tests.log'))) self.l2.addHandler( logging.FileHandler( os.path.join('.', 'log_outputs', 'ODE_Query_Downloads_Tests.log'))) ode = client.ODEClient(self.config['HOST']) ode.get_token(self.config['USERNAME'], self.config['PASSWORD']) date_format = timehelpers.date_format dateTime_now = datetime.datetime.now(timehelpers.ZULU()) dateTime_prev = dateTime_now - datetime.timedelta(weeks=52) self.config['START_DATE'] = dateTime_prev.strftime( timehelpers.date_format) self.config['END_DATE'] = dateTime_now.strftime( timehelpers.date_format) self.client = None self.client = client.AsyncODEClient(odeClient=ode)
def eadsim(self, username, password, server, intersectionId, lanesetId): #1. subscribe self.logger.debug('EAD is using Simulated Data.') nwLat = random.uniform(42.544480787298, 42.544480787299) nwLon = -83.52218627929688 seLat = 42.3021981769316 seLon = -82.78610229492188 region = client.GeographicRegion(nwLat, nwLon, seLat, seLon) test_request = client.BaseRequest("tst", "veh", region) host = str(server) userName = str(username) password = str(password) ode = client.ODEClient(host) ode.get_token(userName, password) ode.setRequest(test_request) #2. upload and async client async = client.AsyncODEClient(odeClient=ode) async .start() config = {} config['HOST'] = host config['REQUEST_TYPE'] = 'sub' config['DATA'] = 'veh' config['TEST_REQUEST'] = None config['INPUT_FILE'] = './/fulldata.json' intlat, intlon, uslat, uslon, angle = self.intMapping(intersectionId) if angle < 45 or angle > 315: #north facing direction = 'N' elif 45 < angle < 135: #east facing direction = 'E' elif 135 < angle < 225: direction = 'S' else: direction = 'W' #3. inflo application while True: items = async .get_all_messages() CVData = [] #stores raw data uniqueData = [] #stores processed data #items = async.get_messages(4) # Specify number of items to process # reset current counts self.messages, self.case5 = len(items), 0 for record in items: if record.get_payload_type() in ( 'status', ) and record.get_payload_value('requestId'): config['TEST_REQUEST'] = record.get_payload_value( 'requestId') depositClient.update_config(config) thread.start_new_thread(depositClient._run_main, (config, )) else: # new method self.logger.info("%s", record.get_payload_value('dateTime')) vehList = [0, 0, 0, 0, 0, 0, 0] vehList[0] = record.get_payload_value('tempId') vehList[1] = record.get_payload_value('latitude') vehList[2] = record.get_payload_value('longitude') vehList[3] = record.get_payload_value('speed') vehList[4] = record.get_payload_value('heading') vehList[5] = record.get_payload_value('dateTime') vehList[6] = record.get_payload_value('groupId') self.logger.debug('Data Received: %s' % str(vehList)) CVData.append(vehList) #print record.get_payload_value(key) #Get latest data from a vehicle. vehIDs = [] for i in range(1, len(CVData)): vehData = CVData[i] if vehData[0] not in vehIDs: uniqueData.append(vehData) vehIDs.append(vehData[0]) #print uniqueData TTC = timeToChange.get() CS = currState.get() self.logger.debug('Unique Data Submitted to EAD App %s' % str(uniqueData)) self.eadalgorithm(uniqueData, intersectionId, TTC, CS, intlat, intlon, uslat, uslon, angle, direction) #print uniqueData, intersectionId, TTC, CS self.signal.emit([self.messages, self.case5]) time.sleep(2)
def eadfield(self, username, password, server, intersectionId, lanesetId): self.logger.debug('EAD is using Field Data at %s.' % intersectionId) intlat, intlon, uslat, uslon, angle = self.intMapping(intersectionId) if angle < 45 or angle > 315: #north facing direction = 'N' elif 45 < angle < 135: #east facing direction = 'E' elif 135 < angle < 225: direction = 'S' else: direction = 'W' #if intersectionId == "00000085" or intersectionId == "00000088": #nwLat=42.3344144 #nwLon=-83.0565548 #seLat=42.326815989 #seLon=-83.033766755 #else: nwLat = 42.53790 nwLon = -83.47790 seLat = 42.30575 seLon = -82.84275 region = client.GeographicRegion(nwLat, nwLon, seLat, seLon) sub_data_type = "veh" # veh, int, agg sub_request = client.SubscriptionRequest(sub_data_type, region) host = str(server) userName = str(username) password = str(password) ode = client.ODEClient(host) ode.get_token(userName, password) ode.setRequest(sub_request) self.logger.debug('VSD Subscription Requested.') async = client.AsyncODEClient(odeClient=ode) async .start() # will connect to the ODE in a separate thread. while True: CVData = [] #stores raw data uniqueData = [] #stores processed data # reset current counts self.messages, self.case5 = 0, 0 if not async .is_buffer_empty(): items = async .get_all_messages() #items = async.get_messages(10) # Specifiy number of items to process # update current number of messages self.messages = math.log(len(items), 10) for record in items: #logger.info("%s", record.get_payload_value('dateTime')) vehList = [0, 0, 0, 0, 0, 0, 0] vehList[0] = record.get_payload_value('tempId') vehList[1] = record.get_payload_value('latitude') vehList[2] = record.get_payload_value('longitude') vehList[3] = record.get_payload_value('speed') vehList[4] = record.get_payload_value('heading') vehList[5] = record.get_payload_value('dateTime') vehList[6] = record.get_payload_value('groupId') self.logger.debug('Data Received: %s' % str(vehList)) if vehList[3] != None: CVData.append(vehList) #print record.get_payload_value(key) #Get latest data from a vehicle. vehIDs = [] for i in range(1, len(CVData)): vehData = CVData[i] if vehData[0] not in vehIDs: uniqueData.append(vehData) vehIDs.append(vehData[0]) print len(vehIDs) TTC = timeToChange.get() CS = currState.get() self.logger.debug('Unique Data Submitted to EAD App %s' % str(uniqueData)) self.eadalgorithm(uniqueData, intersectionId, TTC, CS, intlat, intlon, uslat, uslon, angle, direction) #print uniqueData, intersectionId, TTC, CS self.signal.emit([self.messages, self.case5]) time.sleep(2)
def inczonefield(self, username, password, server, location): #self.logger = logger.getLogger('ODEApplication.inczonefield') if location == 0: Loc = 'Congress Street' incLatitude = 42.329226 incLongitude = -83.048201 heading = 60 speedlimit = 25 nwLat = 42.53790 nwLon = -83.47790 seLat = 42.30575 seLon = -82.84275 elif location == 1: Loc = 'NB Telegraph Road' incLatitude = 42.500625 incLongitude = -83.284654 heading = 180 speedlimit = 50 nwLat = 42.517880 nwLon = -83.306150 seLat = 42.448888 seLon = -83.259115 else: Loc = 'SB Telegraph Road' incLatitude = 42.472016 incLongitude = -83.282423 heading = 0 speedlimit = 50 nwLat = 42.517880 nwLon = -83.306150 seLat = 42.448886 seLon = -83.259115 self.logger.debug('INC-ZONE is using Field Data on %s.' % Loc) z1lat, z1lon, z2lat, z2lon, z3lat, z3lon = self.zoning( incLatitude, incLongitude, heading, speedlimit) self.logger.debug('INC-ZONE Zoning Done.') region = client.GeographicRegion(nwLat, nwLon, seLat, seLon) sub_data_type = "veh" # veh, int, agg sub_request = client.SubscriptionRequest(sub_data_type, region) host = str(server) userName = str(username) password = str(password) ode = client.ODEClient(host) ode.get_token(userName, password) ode.setRequest(sub_request) self.logger.debug('VSD Subscription Requested.') async = client.AsyncODEClient(odeClient=ode) async .start() # will connect to the ODE in a separate thread. import time while True: CVData = [] #stores raw data uniqueData = [] #stores processed data # reset current counts self.messages, self.advisories, self.alerts, self.warnings = [0 ] * 4 if not async .is_buffer_empty(): items = async .get_all_messages() # update current number of messages self.messages = math.log(len(items), 10) #items = async.get_messages(10) # Specifiy number of items to process for record in items: #logger.info("%s", record.get_payload_value('dateTime')) vehList = [0, 0, 0, 0, 0, 0, 0] vehList[0] = record.get_payload_value('tempId') vehList[1] = record.get_payload_value('latitude') vehList[2] = record.get_payload_value('longitude') vehList[3] = record.get_payload_value('speed') vehList[4] = record.get_payload_value('heading') vehList[5] = record.get_payload_value('dateTime') vehList[6] = record.get_payload_value('groupId') self.logger.debug('Data Received: %s' % str(vehList)) if vehList[3] != None: CVData.append(vehList) vehIDs = [] for i in range(1, len(CVData)): vehData = CVData[i] if vehData[0] not in vehIDs: uniqueData.append(vehData) vehIDs.append(vehData[0]) #print uniqueData self.logger.debug('Unique Data Submitted to INC-ZONE %s' % str(uniqueData)) self.inczonemanage(uniqueData, location, incLatitude, incLongitude, z1lat, z1lon, z2lat, z2lon, z3lat, z3lon) time.sleep(1) # emit counts self.signal.emit([ self.messages, self.advisories, self.alerts, self.warnings ])
def inczonesim(self, username, password, server, location): #1. subscribe #self.logger = logging.getLogger('ODEApplication.inczonesim') if location == 0: Loc = 'Congress Street' incLatitude = 42.329226 incLongitude = -83.048201 heading = 60 speedlimit = 25 elif location == 1: Loc = 'NB Telegraph Road' incLatitude = 42.500625 incLongitude = -83.284654 heading = 180 speedlimit = 50 else: Loc = 'SB Telegraph Road' incLatitude = 42.472016 incLongitude = -83.282423 heading = 0 speedlimit = 50 self.logger.debug('INC-ZONE is using Simulated Data on %s.' % Loc) z1lat, z1lon, z2lat, z2lon, z3lat, z3lon = self.zoning( incLatitude, incLongitude, heading, speedlimit) self.logger.debug('INC-ZONE Zoning Done.') nwLat = uniform(42.544480787298, 42.544480787299) nwLon = -83.52218627929688 seLat = 42.3021981769316 seLon = -82.78610229492188 region = client.GeographicRegion(nwLat, nwLon, seLat, seLon) test_request = client.BaseRequest("tst", "veh", region) host = str(server) userName = str(username) password = str(password) ode = client.ODEClient(host) ode.get_token(userName, password) ode.setRequest(test_request) #2. upload and async client async = client.AsyncODEClient(odeClient=ode) async .start() config = {} config['HOST'] = host config['REQUEST_TYPE'] = 'sub' config['DATA'] = 'veh' config['TEST_REQUEST'] = None config['INPUT_FILE'] = './/dry_run_data.json' #3. inflo application while True: items = async .get_all_messages() # reset current counts self.messages, self.advisories, self.alerts, self.warnings = [0 ] * 4 # update current number of messages self.messages = len(items) CVData = [] #stores raw data uniqueData = [] #stores processed data #items = async.get_messages(4) # Specify number of items to process for record in items: if record.get_payload_type() in ( 'status', ) and record.get_payload_value('requestId'): config['TEST_REQUEST'] = record.get_payload_value( 'requestId') depositClient.update_config(config) thread.start_new_thread(depositClient._run_main, (config, )) else: # new method #self.logger.info("%s", record.get_payload_value('dateTime')) vehList = [0, 0, 0, 0, 0, 0, 0] vehList[0] = record.get_payload_value('tempId') vehList[1] = record.get_payload_value('latitude') vehList[2] = record.get_payload_value('longitude') vehList[3] = record.get_payload_value('speed') vehList[4] = record.get_payload_value('heading') vehList[5] = record.get_payload_value('dateTime') vehList[6] = record.get_payload_value('groupId') self.logger.debug('Data Received: %s' % str(vehList)) CVData.append(vehList) #print record.get_payload_value(key) #Get latest data from a vehicle. vehIDs = [] for i in range(1, len(CVData)): vehData = CVData[i] if vehData[0] not in vehIDs: uniqueData.append(vehData) vehIDs.append(vehData[0]) #print uniqueData self.logger.debug('Unique Data Submitted to INC-ZONE %s' % str(uniqueData)) self.inczonemanage(uniqueData, location, incLatitude, incLongitude, z1lat, z1lon, z2lat, z2lon, z3lat, z3lon) time.sleep(1) # emit counts #self.signal.emit([randint(18, 36), randint(0, 16), randint(0, 12), randint(0, 8)]) self.signal.emit( [self.messages, self.advisories, self.alerts, self.warnings])
def inflofield(self, username, password, server, frequency, location): #self.logger = logger.getLogger('ODEApplication.inflofield') if location == 0: Loc = 'Larned Street' nwLat = 42.53790 nwLon = -83.47790 seLat = 42.30575 seLon = -82.84275 else: Loc = 'Telegraph Road' nwLat = 42.517879 nwLon = -83.306150 seLat = 42.448886 seLon = -83.259115 self.logger.debug('INFLO is using Field Data on %s.' % Loc) region = client.GeographicRegion(nwLat, nwLon, seLat, seLon) sub_data_type = "veh" # veh, int, agg sub_request = client.SubscriptionRequest(sub_data_type, region) host = str(server) userName = str(username) password = str(password) ode = client.ODEClient(host) ode.get_token(userName, password) ode.setRequest(sub_request) self.logger.debug('VSD Subscription Requested.') async = client.AsyncODEClient(odeClient=ode) async .start() # will connect to the ODE in a separate thread. while True: CVData = [] #stores raw data uniqueData = [] #stores processed data # reset current counts self.messages, self.triggers = 0, 0 if not async .is_buffer_empty(): items = async .get_all_messages() # update current number of messages self.messages = math.log(len(items), 10) #items = async.get_messages(10) # Specifiy number of items to process for record in items: #logger.info("%s", record.get_payload_value('dateTime')) vehList = [0, 0, 0, 0, 0, 0, 0] vehList[0] = record.get_payload_value('tempId') vehList[1] = record.get_payload_value('latitude') vehList[2] = record.get_payload_value('longitude') vehList[3] = record.get_payload_value('speed') vehList[4] = record.get_payload_value('heading') vehList[5] = record.get_payload_value('dateTime') vehList[6] = record.get_payload_value('groupId') self.logger.debug('Data Received: %s' % str(vehList)) if vehList[1] != None: CVData.append(vehList) #print record.get_payload_value(key) #Get latest data from a vehicle. vehIDs = [] for i in range(1, len(CVData)): vehData = CVData[i] if vehData[0] not in vehIDs: uniqueData.append(vehData) vehIDs.append(vehData[0]) self.logger.debug('Unique Data Submitted to INFLO %s' % str(uniqueData)) self.inflomanage(uniqueData, location) self.signal.emit([self.messages, self.triggers]) time.sleep(frequency)
def inflosim(self, username, password, server, frequency, location): #1. subscribe #self.logger = logging.getLogger('ODEApplication.inflosim') self.logger.debug('INFLO is using Simulated Data.') nwLat = uniform(42.544480787298, 42.544480787299) nwLon = -83.52218627929688 seLat = 42.3021981769316 seLon = -82.78610229492188 region = client.GeographicRegion(nwLat, nwLon, seLat, seLon) test_request = client.BaseRequest("tst", "veh", region) host = str(server) userName = str(username) password = str(password) ode = client.ODEClient(host) ode.get_token(userName, password) ode.setRequest(test_request) #2. upload and async client async = client.AsyncODEClient(odeClient=ode) async .start() config = {} config['HOST'] = host config['REQUEST_TYPE'] = 'sub' config['DATA'] = 'veh' config['TEST_REQUEST'] = None config['INPUT_FILE'] = './/BSM_Stream.json' #3. inflo application while True: items = async .get_all_messages() CVData = [] #stores raw data uniqueData = [] #stores processed data #items = async.get_messages(4) # Specify number of items to process # reset current counts self.messages, self.triggers = len(items), 0 for record in items: if record.get_payload_type() in ( 'status', ) and record.get_payload_value('requestId'): config['TEST_REQUEST'] = record.get_payload_value( 'requestId') depositClient.update_config(config) thread.start_new_thread(depositClient._run_main, (config, )) else: # new method #logger.info("%s", record.get_payload_value('dateTime')) vehList = [0, 0, 0, 0, 0, 0, 0] vehList[0] = record.get_payload_value('tempId') vehList[1] = record.get_payload_value('latitude') vehList[2] = record.get_payload_value('longitude') vehList[3] = record.get_payload_value('speed') vehList[4] = record.get_payload_value('heading') vehList[5] = record.get_payload_value('dateTime') vehList[6] = record.get_payload_value('groupId') self.logger.debug('Data Received: %s' % str(vehList)) CVData.append(vehList) #print record.get_payload_value(key) #Get latest data from a vehicle. vehIDs = [] for i in range(1, len(CVData)): vehData = CVData[i] if vehData[0] not in vehIDs: uniqueData.append(vehData) vehIDs.append(vehData[0]) self.logger.debug('Unique Data Submitted to INFLO %s' % str(uniqueData)) self.inflomanage(uniqueData, location) self.signal.emit([self.messages, self.triggers]) time.sleep(frequency)
def createClient(self): ode = client.ODEClient(self.config['HOST']) ode.get_token(self.config['USERNAME'], self.config['PASSWORD']) self.client = None self.client = client.AsyncODEClient(odeClient=ode)
def setUp(self): ode = client.ODEClient(self.host, self.userName, self.password) self.client = client.AsyncODEClient(odeClient=ode) self.region = simulatedclient2.build_region(self.service_region)
def on_message(ws,message): print message """ #ode.connect(on_message=client.on_message) """ The Asynchronous ODE Client behaves like the regular ODE Client with the following differences: * The Asynchronous client will buffer the ODE Output in a thread safe internal Queue * The get_message(N number of messages) will return up to N message from the internal Queue ** If the Queue contains less then N message, then you receive however many messages that are present at request time. * The current output from the get_messages function is a list of ODE Response Objects """ async = client.AsyncODEClient(odeClient=ode) async .start() # will connect to the ODE in a separate thread. import time import thread import depositClient config = {} config['HOST'] = host config['REQUEST_TYPE'] = 'sub' config['DATA'] = 'veh' config['TEST_REQUEST'] = None config['INPUT_FILE'] = './/BSM_Trans_small_test.json' while True: items = async .get_all_messages()