Example #1
0
    def run_test_with_input(self):
        request = client.BaseRequest(
            "tst", self.config['DATA'],
            testRunnerHelper.build_region(self.config['SERVICE_REGION']))
        self.logger.info("Request: %s", request.toJson())
        self.client.setRequest(request)
        self.client.start()
        time.sleep(5)

        self.run_validation_test()
Example #2
0
def build_request(config):
    request = None

    area = config.get('SERVICE_REGION', None)
    region = None
    if area is not None:
        region = build_region(area)
    else:
        region = simulatedClientPresets.pre_built_region()

    if config.get('REQUEST_TYPE',
                  None) and config.get('REQUEST_TYPE') == 'sub':
        request = client.SubscriptionRequest(config.get('DATA'), region)
    # TEST REQUEST Manager
    if config.get('UPLOAD_TEST_DATA',
                  False) and config.get('REQUEST_TYPE') == 'sub':
        request = client.BaseRequest("tst", "veh", region)

    elif config.get('REQUEST_TYPE',
                    None) and config.get('REQUEST_TYPE') == 'qry':
        request = client.QueryRequest(config.get('DATA_TYPE'), region,
                                      config.get('START_DATE', start_date),
                                      config.get('END_DATE', end_date),
                                      config.get('SKIP', skip),
                                      config.get('LIMIT', limit))
    if config.get('ROAD_SEGMENTS', False):
        for segment in config['ROAD_SEGMENTS']:
            if segment.get('startPoint'):
                startPoint = client.OdePoint(
                    *tuple(segment['startPoint'].split(',')))
            else:
                startPoint = None

            endpoint = client.OdePoint(*tuple(segment['endPoint'].split(',')))
            rs = client.RoadSegment(segment['id'],
                                    startPoint=startPoint,
                                    endPoint=endpoint,
                                    previousSegmentId=segment.get(
                                        'previousSegmentId', None))
            request.add_road_segments(rs)
    return request
Example #3
0
def build_request(config):
    request = None

    area = config.get('SERVICE_REGION', None)

    if area is not None:
        region = build_region(area)

    if config.get('REQUEST_TYPE', None):
        if config.get('REQUEST_TYPE') == 'sub':
            request = client.SubscriptionRequest(config.get('DATA_TYPE'),
                                                 region)
        elif config.get('REQUEST_TYPE') == 'qry':
            request = client.QueryRequest(config.get('DATA_TYPE'), region,
                                          config.get('START_DATE', start_date),
                                          config.get('END_DATE', end_date),
                                          config.get('SKIP', skip),
                                          config.get('LIMIT', limit))
        elif "INPUT_FILE" in config and (config.get('REQUEST_TYPE') == 'tst' or
                                         config.get('REQUEST_TYPE') == 'dep'):
            request = client.BaseRequest(config.get('REQUEST_TYPE'),
                                         config.get('DATA_TYPE'), region)

    if config.get('ROAD_SEGMENTS', False):
        for segment in config['ROAD_SEGMENTS']:
            if segment.get('startPoint'):
                startPoint = client.OdePoint(
                    *tuple(segment['startPoint'].split(',')))
            else:
                startPoint = None

            endpoint = client.OdePoint(*tuple(segment['endPoint'].split(',')))
            rs = client.RoadSegment(segment['id'],
                                    startPoint=startPoint,
                                    endPoint=endpoint,
                                    previousSegmentId=segment.get(
                                        'previousSegmentId', None))
            request.add_road_segments(rs)
    return request
Example #4
0
    def test_Veh_Subscription_with_Upload_Test_Data(self):
        self.config['DATA'] = "veh"
        self.config['VALIDATION_FILE'] = os.path.join('.', 'test_json', 'sub_veh_200_records.json')
        self.config['INPUT_FILE'] = os.path.join('.', 'test_json', 'sub_veh_200_records.json')
        simulatedclient2.config.update(self.config)
        request = client.BaseRequest("tst", self.config['DATA'],
                                     simulatedclient2.build_region(self.config['SERVICE_REGION']))

        self.client.setRequest(request)
        self.client.start()
        time.sleep(5)
        self.config['TEST_REQUEST'] = None
        while not self.client.is_buffer_empty() and self.config['TEST_REQUEST'] is None:
            responses = self.client.get_messages(1)
            for msg in responses:
                if msg.get_payload_type() in dataType.Status and msg.get_payload_value('requestId', False):
                    self.config['TEST_REQUEST'] = msg.get_payload_value('requestId')
                    depositClient.update_config(self.config)
                    thread.start_new_thread(depositClient._run_main, (self.config,))

        # Pause to allow data upload to commence
        # in separate thread, and to allow spark to process the data.
        # Spark may introduce some unknown delay.
        time.sleep(15)
        while not self.client.is_buffer_empty():
            responses = self.client.get_all_messages()
            for msg in responses:
                print msg
                if msg.get_payload_type() in dataType.Status:
                    self.assertIsNotNone(msg.get_payload_value('code', None))
                    self.assertEqual(msg.get_payload_value('code'), 'SUCCESS')

                if msg.get_payload_type() in dataType.VehicleData:
                    self.assertEqual(msg.get_payload_value('dataType', None), 'veh')
                    self.assertTrue(simulatedclient2.validate_location(msg.payload),
                                    msg="Error Validating Spatial Region Lat: {0} Long: {0}".format(
                                        msg.get_payload_value("latitude"), msg.get_payload_value("longitude")))
            time.sleep(5)
Example #5
0
    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)
Example #6
0
    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])
Example #7
0
    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)
Example #8
0
                             day=1,
                             hour=23,
                             minute=59,
                             second=59,
                             microsecond=999,
                             tzinfo=timehelpers.ZULU())

qry_data_type = "veh"  # veh, int,  adv
qry_request = client.QueryRequest(qry_data_type, region,
                                  start_date.strftime(timehelpers.date_format),
                                  end_date.strftime(timehelpers.date_format),
                                  skip, limit)

sub_data_type = "int"  # veh, int, agg
sub_request = client.SubscriptionRequest(sub_data_type, region)
test_request = client.BaseRequest("tst", "veh", region)

#host =  "54.88.79.115:8080/ode"
#host=  "52.20.100.211:8080/ode"
#userName="******"
#password="******"

host = "192.168.22.12: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.