def _run_main(this_config, config_file=None): config.update(this_config) if 'LOGGER_NAME' in config: logger = logging.getLogger(config['LOGGER_NAME']) config['REQUEST_TYPE'] = 'dep' global input_file if config.get('INPUT_FILE'): input_file = config.get('INPUT_FILE') else: logger.warn('No input file provided') sys.exit(-1) global batchPeriod if config['BP']: batchPeriod = config['BP'] global batchRecords if config['BR']: batchRecords = config['BR'] ode = client.ODEClient(config['HOST'], config['USERNAME'], config['PASSWORD'], on_open=on_open) request = build_request(config) logger.info("ODE Request: %s", request.toJson() ) ode.setRequest(request) ode.connect(on_message=on_message, on_open=on_open) # open continuous connection.
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 _run_main(this_config, config_file=None): ode = client.ODEClient(this_config['HOST'], this_config['USERNAME'], this_config['PASSWORD']) request = build_request(this_config) logger.info("ODE Request: %s", request.toJson()) ode.setRequest(request) ode.connect(on_message=on_message) # open continuous connection.
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 _run_main(config, config_file=None): ode = client.ODEClient(config['HOST'], config['USERNAME'], config['PASSWORD']) request = build_request(config) logger.info("Validation File: %s", config['VALIDATION_FILE']) if config['VALIDATION_FILE'] is not None: extract_json_objects(config['VALIDATION_FILE']) logger.info("Subscriptions Params: %s", request.toJson()) ode.setRequest(request) ode.connect(on_message=on_message) # open continuous connection.
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 updateIntData(self, username, password, server, intersectionId, lanesetId): self.logger.debug('Intersection Update Thread started.') #if intersectionId == "00000085" or intersectionId == "00000088": # nwLat=42.333181 # nwLon=-83.051523 # seLat=42.327089 # seLon=-83.037940 #else: # nwLat=42.517880 # nwLon=-83.306152 # seLat=42.448886 # seLon=-83.259115 nwLat = 42.53790 nwLon = -83.47790 seLat = 42.30575 seLon = -82.84275 region = client.GeographicRegion(nwLat, nwLon, seLat, seLon) sub_data_type = "int" # 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) def on_message(ws, message): try: msg = json.loads(message) #self.logger.debug("Intersection Message Received: %s", message) if msg.get('payload', { 'code': None }).get('code', None) is not None and msg.get('payload').get( 'code').upper() == 'SUCCESS': # send_file(ws,config['INPUT_FILE']) self.logger.info('Message from the Test API: %s', message) elif msg.get('payload', { 'code': None }).get('code', None) is not None and msg.get('payload').get( 'code').upper() == 'FAILURE': ws.close() else: pass #logger.debug('Message from the Test API: %s', message) if msg.get("payload", {'code': None}).get("code") == 'FAILURE': ws.close() except: # logger.warn(message) self.logger.exception("Exception convert Message to JSON: %s", message) if msg['payload']['spatData']['intersections'][ 'id'] == intersectionId: TTC = int(msg['payload']['spatData']['intersections']['states'] [lanesetId]['timeToChange']) CS = int(msg['payload']['spatData']['intersections']['states'] [lanesetId]['currState']) timeToChange.put(TTC) currState.put(CS) self.logger.debug( 'SPAT for specific intersection received. time to change = %s. current state = %s' % (str(TTC), str(CS))) ode.connect(on_message=on_message)
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 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)
logger.addHandler(ch) nwLat = 42.3344143862 nwLon = -83.056554794 seLat = 42.326815989116625 seLon = -83.033766746521 region = client.GeographicRegion(nwLat, nwLon, seLat, seLon) sub_data_type = "veh" # veh, int, agg sub_request = client.SubscriptionRequest(sub_data_type, region) host = "52.90.45.32:8080/ode" userName = "******" password = "******" ode = client.ODEClient(host) #ode = client.ODEClient(host,userName,password) # only required if no userName or password is # provided in the constructor. # # Access Token is short lived token that will expire. # A new Token will need to be requested if the websocket is stopped ode.get_token(userName, password) # set Request Object ode.setRequest(sub_request) #ode.setRequest(qry_request) logger.debug('VSD Subscription Requested') """ The connect method will start the Websocket connection.
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 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 test_exception_returned_with_invalid_UserName(self): ode = client.ODEClient(self.host, "*****@*****.**", self.password) self.assertRaises(exceptions.ODEConnectionException, ode.connect, None)
def test_exception_returned_with_invalid_Password(self): ode = client.ODEClient(self.host, self.userName, "Wrong Password") self.assertRaises(exceptions.ODEConnectionException, ode.connect, None)
def test_access_token_with_valid_UserName_Password(self): ode = client.ODEClient(self.host, self.userName, self.password) self.assertIsNotNone(ode.token)
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 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 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)