Ejemplo n.º 1
0
 def setUp(self):
     self.FRC = OSIRulesChecker()
     orient3d = Orientation3d()
     orient3d.roll = 5
     orient3d.pitch = 2
     orient3d.yaw = 2
     self.linked_orient3d = LinkedProtoField(orient3d, "Orientation3d")
Ejemplo n.º 2
0
class TestIsSet(unittest.TestCase):
    def setUp(self):
        self.FRC = OSIRulesChecker()

        pb_ORIENTATION3D = Orientation3d()
        pb_ORIENTATION3D.roll = 1
        # pb_ORIENTATION3D.pitch = 2 --> pitch is not set
        pb_ORIENTATION3D.yaw = 2
        self.ORIENTATION3D = LinkedProtoField(pb_ORIENTATION3D,
                                              "Orientation3d")

    def tearDown(self):
        del self.FRC
        del self.ORIENTATION3D

    def test_comply_is_set(self):
        rule = Rule(verb="is_set", field_name="roll")
        compliance = self.FRC.is_set(self.ORIENTATION3D, rule)
        self.assertTrue(compliance)

        rule = Rule(verb="is_set", field_name="yaw")
        compliance = self.FRC.is_set(self.ORIENTATION3D, rule)
        self.assertTrue(compliance)

    def test_comply_is_not_set(self):
        rule = Rule(verb="is_set", field_name="pitch")
        compliance = self.FRC.is_set(self.ORIENTATION3D, rule)
        self.assertFalse(compliance)
Ejemplo n.º 3
0
    def setUp(self):
        self.FRC = OSIRulesChecker()

        pb_VECTOR3D = Vector3d()
        pb_VECTOR3D.x = 1
        pb_VECTOR3D.y = 2
        self.VECTOR3D = LinkedProtoField(pb_VECTOR3D, "Vector3D")
Ejemplo n.º 4
0
    def setUp(self):
        self.FRC = OSIRulesChecker()

        sv1 = SensorView()
        linked_sv1 = LinkedProtoField(sv1, name="SensorView")

        gt1 = sv1.global_ground_truth
        linked_gt1 = LinkedProtoField(gt1,
                                      name="global_ground_truth",
                                      parent=linked_sv1)

        gt1.host_vehicle_id.value = 0
        hvid1 = gt1.host_vehicle_id
        self.linked_hvid1 = LinkedProtoField(hvid1,
                                             name="host_vehicle_id",
                                             parent=linked_gt1)

        sv2 = SensorView()
        linked_sv2 = LinkedProtoField(sv2, name="SensorView")

        gt2 = sv2.global_ground_truth
        linked_gt2 = LinkedProtoField(gt2,
                                      name="global_ground_truth",
                                      parent=linked_sv2)

        gt2.host_vehicle_id.value = 1
        hvid1 = gt2.host_vehicle_id
        self.linked_hvid2 = LinkedProtoField(hvid1,
                                             name="host_vehicle_id",
                                             parent=linked_gt2)
class TestIsGreaterThan(unittest.TestCase):
    """ Test for rule is_greater_than """
    def setUp(self):
        self.FRC = OSIRulesChecker()

    def tearDown(self):
        del self.FRC

    def test_comply_greater(self):

        field_params_rule_params = [
            [2, 1],
            [0, -1],
            [1, 0],
            [1, -1],
            [-1, -2],
            [-1.3, -1.5],
            [0.9, -1.3],
        ]

        for fr_param in field_params_rule_params:
            with self.subTest(fr_param=fr_param):
                self.assertTrue(
                    self.FRC.is_greater_than(
                        LinkedProtoField(value=fr_param[0]),
                        Rule(verb="is_greater_than", params=fr_param[1]),
                    ))

    def test_not_comply_greater(self):
        field_params_rule_params = [
            [2, 1],
            [0, -1],
            [1, 0],
            [1, -1],
            [-1, -2],
            [-1.3, -1.5],
            [0.9, -1.3],
        ]

        for fr_param in field_params_rule_params:
            with self.subTest(fr_param=fr_param):
                self.assertFalse(
                    self.FRC.is_greater_than(
                        LinkedProtoField(value=fr_param[1]),
                        Rule(verb="is_greater_than", params=fr_param[0]),
                    ))

    def test_not_comply_equal(self):

        field_params_rule_params = [[3, 3], [0, 0], [-1, -1], [-1.5, -1.5],
                                    [2.3, 2.3]]

        for fr_param in field_params_rule_params:
            with self.subTest(fr_param=fr_param):
                self.assertFalse(
                    self.FRC.is_greater_than(
                        LinkedProtoField(value=fr_param[1]),
                        Rule(verb="is_greater_than", params=fr_param[0]),
                    ))
Ejemplo n.º 6
0
    def setUp(self):
        self.FRC = OSIRulesChecker()

        pb_ORIENTATION3D = Orientation3d()
        pb_ORIENTATION3D.roll = 1
        # pb_ORIENTATION3D.pitch = 2 --> pitch is not set
        pb_ORIENTATION3D.yaw = 2
        self.ORIENTATION3D = LinkedProtoField(pb_ORIENTATION3D,
                                              "Orientation3d")
class TestIsIsoCountryCode(unittest.TestCase):
    def setUp(self):
        self.FRC = OSIRulesChecker()

    def tearDown(self):
        del self.FRC

    def test_comply_iso_country_code(self):
        self.assertTrue(self.FRC.is_iso_country_code("DEU", None))

    def test_not_comply_iso_country_code(self):
        self.assertFalse(self.FRC.is_iso_country_code("1234", None))
Ejemplo n.º 8
0
    def setUp(self):
        self.FRC = OSIRulesChecker()

        sv1 = SensorView()
        linked_sv1 = LinkedProtoField(sv1, name="SensorView")
        gt1 = sv1.global_ground_truth
        linked_gt1 = LinkedProtoField(gt1,
                                      name="global_ground_truth",
                                      parent=linked_sv1)

        gtlb1 = gt1.lane_boundary.add()
        linked_gtlb1 = LinkedProtoField(gtlb1,
                                        name="lane_boundary",
                                        parent=linked_gt1)

        bladd1 = gtlb1.boundary_line.add()
        bladd1.position.x = 1699.2042678176733
        bladd1.position.y = 100.16895580204906
        bladd1.position.z = 0.0
        bladd1.width = 0.13
        bladd1.height = 0.0

        self.lb1 = LinkedProtoField(bladd1,
                                    name="boundary_line",
                                    parent=linked_gtlb1)
        self.lb1.path = 'SensorView.global_ground_truth.lane_boundary.boundary_line'
        # self.lb1.parent =

        sv2 = SensorView()
        linked_sv2 = LinkedProtoField(sv2, name="SensorView")

        gt2 = sv2.global_ground_truth
        linked_gt2 = LinkedProtoField(gt2,
                                      name="global_ground_truth",
                                      parent=linked_sv2)

        gtlb2 = gt2.lane_boundary.add()
        linked_gtlb2 = LinkedProtoField(gtlb2,
                                        name="lane_boundary",
                                        parent=linked_gt2)

        bladd2 = gtlb2.boundary_line.add()
        bladd2.position.x = 1699.2042678176733
        bladd2.position.y = 100.16895580204906
        bladd2.position.z = 0.0
        bladd2.width = 0.14
        bladd2.height = 0.13
        self.lb2 = LinkedProtoField(bladd2,
                                    name="boundary_line",
                                    parent=linked_gtlb2)
        self.lb2.path = 'SensorView.global_ground_truth.lane_boundary.boundary_line'
class TestIsGlobalUnique(unittest.TestCase):
    def setUp(self):
        self.FRC = OSIRulesChecker()

        sv = SensorView()
        linked_sv = LinkedProtoField(sv, name="SensorView")
        sid = sv.sensor_id
        sid.value = 0
        self.linked_sid = LinkedProtoField(sid,
                                           name="sensor_id",
                                           parent=linked_sv)

        sv2 = SensorView()
        linked_sv2 = LinkedProtoField(sv2, name="SensorView")
        sid2 = sv2.sensor_id
        sid2.value = 2
        self.linked_sid2 = LinkedProtoField(sid2,
                                            name="sensor_id",
                                            parent=linked_sv2)

    def tearDown(self):
        del self.FRC
        del self.linked_sid
        del self.linked_sid2

    def test_comply_is_globally_unique(self):
        """
        Test if the ID Manager has unique indices
        """
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(
            ["SensorView", "sensor_id", "is_globally_unique"])
        container.add_type_from_path(proto_path)

        rule = Rule(
            verb="is_globally_unique",
            field_name="sensor_id",
            extra_params=dict(),
            path=proto_path,
        )
        rule.root = container
        self.FRC.is_globally_unique(self.linked_sid, rule)
        self.FRC.is_globally_unique(self.linked_sid2, rule)
        self.FRC.is_globally_unique(self.linked_sid2, rule)
        index_dict = self.FRC.id_manager._index
        self.assertEqual(2, len(index_dict))
    def setUp(self):
        self.FRC = OSIRulesChecker()

        sv = SensorView()
        linked_sv = LinkedProtoField(sv, name="SensorView")
        sid = sv.sensor_id
        sid.value = 0
        self.linked_sid = LinkedProtoField(sid,
                                           name="sensor_id",
                                           parent=linked_sv)

        sv2 = SensorView()
        linked_sv2 = LinkedProtoField(sv2, name="SensorView")
        sid2 = sv2.sensor_id
        sid2.value = 2
        self.linked_sid2 = LinkedProtoField(sid2,
                                            name="sensor_id",
                                            parent=linked_sv2)
Ejemplo n.º 11
0
class TestIsDifferent(unittest.TestCase):
    """Test class of OSIDataContainer class"""
    def setUp(self):
        self.FRC = OSIRulesChecker()

    def tearDown(self):
        del self.FRC

    def test_comply(self):
        field = LinkedProtoField(value=3)
        rule = Rule(verb="is_different", params=2)
        compliance = self.FRC.is_different(field, rule)
        self.assertTrue(compliance)

    def test_not_comply(self):
        field = LinkedProtoField(value=2)
        rule = Rule(verb="is_different", params=2)
        compliance = self.FRC.is_different(field, rule)
        self.assertFalse(compliance)
Ejemplo n.º 12
0
def process_timestep(timestep):
    """Process one timestep"""
    message = MESSAGE_CACHE[timestep]
    rule_checker = OSIRulesChecker(LOGGER)
    timestamp = rule_checker.set_timestamp(message.value.timestamp, timestep)
    ID_TO_TS[timestep] = timestamp

    LOGGER.log_messages[timestep] = []
    LOGGER.debug_messages[timestep] = []
    LOGGER.info(None, f'Analyze message of timestamp {timestamp}', False)

    # Check if timestamp already exists
    if timestamp in TIMESTAMP_ANALYZED:
        LOGGER.error(timestep, f"Timestamp already exists")
    TIMESTAMP_ANALYZED.append(timestamp)

    BAR.goto(len(TIMESTAMP_ANALYZED))

    # Check common rules
    getattr(rule_checker, 'is_valid')(
        message, VALIDATION_RULES.get_rules().get_type(MESSAGE_TYPE.value))

    LOGS.extend(LOGGER.log_messages[timestep])
Ejemplo n.º 13
0
class TestIsOptional(unittest.TestCase):
    """
    This Unit test just checks if the rule is_optional is set to True
    because in protobuf 3 every message field is optional
    """
    def setUp(self):
        self.FRC = OSIRulesChecker()

    def tearDown(self):
        del self.FRC

    def test_comply_is_optional(self):
        self.assertTrue(
            self.FRC.is_optional(LinkedProtoField(value=1),
                                 Rule(verb="is_optional", params=None)))
Ejemplo n.º 14
0
class TestCheckIf(unittest.TestCase):
    """Test class of OSI Rule check_if class"""
    def setUp(self):
        self.FRC = OSIRulesChecker()

        pb_VECTOR3D = Vector3d()
        pb_VECTOR3D.x = 1
        pb_VECTOR3D.y = 2
        self.VECTOR3D = LinkedProtoField(pb_VECTOR3D, "Vector3D")

    def test_comply1(self):
        rule = Rule(verb="check_if",
                    field_name='x',
                    params=[{
                        'is_equal': 3,
                        'target': 'this.y'
                    }],
                    extra_params={'do_check': [{
                        'is_equal': 2
                    }]})
        compliance = self.FRC.check_if(self.VECTOR3D, rule)
        self.assertTrue(compliance)

    def test_comply2(self):
        rule = Rule(verb="check_if",
                    field_name='x',
                    params=[{
                        'is_equal': 2,
                        'target': 'this.y'
                    }],
                    extra_params={'do_check': [{
                        'is_equal': 1
                    }]})
        compliance = self.FRC.check_if(self.VECTOR3D, rule)
        self.assertTrue(compliance)

    def test_comply_is_set(self):
        rule = Rule(verb="check_if",
                    field_name='x',
                    params=[{
                        'is_equal': 2,
                        'target': 'this.y'
                    }],
                    extra_params={'do_check': [{
                        'is_set': None
                    }]})
        compliance = self.FRC.check_if(self.VECTOR3D, rule)
        self.assertTrue(compliance)

    def test_not_comply(self):
        rule = Rule(verb="check_if",
                    field_name='x',
                    params=[{
                        'is_equal': 2,
                        'target': 'this.y'
                    }],
                    extra_params={'do_check': [{
                        'is_equal': 2
                    }]})
        compliance = self.FRC.check_if(self.VECTOR3D, rule)
        self.assertFalse(compliance)

    def test_not_comply_is_set_if(self):
        rule = Rule(verb="check_if",
                    field_name='z',
                    params=[{
                        'is_equal': 2,
                        'target': 'this.y'
                    }],
                    extra_params={'do_check': [{
                        'is_set': None
                    }]})
        compliance = self.FRC.check_if(self.VECTOR3D, rule)
        self.assertFalse(compliance)
Ejemplo n.º 15
0
class TestRefersTo(unittest.TestCase):
    def setUp(self):
        self.FRC = OSIRulesChecker()

        sv1 = SensorView()
        linked_sv1 = LinkedProtoField(sv1, name="SensorView")

        gt1 = sv1.global_ground_truth
        linked_gt1 = LinkedProtoField(gt1,
                                      name="global_ground_truth",
                                      parent=linked_sv1)

        gt1.host_vehicle_id.value = 0
        hvid1 = gt1.host_vehicle_id
        self.linked_hvid1 = LinkedProtoField(hvid1,
                                             name="host_vehicle_id",
                                             parent=linked_gt1)

        sv2 = SensorView()
        linked_sv2 = LinkedProtoField(sv2, name="SensorView")

        gt2 = sv2.global_ground_truth
        linked_gt2 = LinkedProtoField(gt2,
                                      name="global_ground_truth",
                                      parent=linked_sv2)

        gt2.host_vehicle_id.value = 1
        hvid1 = gt2.host_vehicle_id
        self.linked_hvid2 = LinkedProtoField(hvid1,
                                             name="host_vehicle_id",
                                             parent=linked_gt2)

    def tearDown(self):
        del self.FRC
        del self.linked_hvid1
        del self.linked_hvid2

    def test_comply_refers_to(self):
        """
        Check if the message object is referenced correctly
        """
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(
            ["GroundTruth", "host_vehicle_id", "refers_to"])
        container.add_type_from_path(proto_path)

        rule = Rule(
            verb="refers_to",
            params="MovingObject",
            extra_params=dict(),
            path=proto_path,
            field_name="host_vehicle_id",
        )
        rule.root = container
        self.FRC.refers_to(self.linked_hvid1, rule)
        self.FRC.refers_to(self.linked_hvid2, rule)
        self.FRC.refers_to(self.linked_hvid1, rule)

        references_list = self.FRC.id_manager._references

        print(references_list)

        # Check the instance type of the reference
        self.assertIsInstance(references_list[0][0], GroundTruth)

        # Check the id assignment of the reference to the object
        self.assertEqual(references_list[0][0].host_vehicle_id.value, 0)
        self.assertEqual(references_list[0][1], 0)
        self.assertEqual(references_list[0][2], "MovingObject")
Ejemplo n.º 16
0
 def setUp(self):
     self.FRC = OSIRulesChecker()
Ejemplo n.º 17
0
class TestIsValid(unittest.TestCase):
    def setUp(self):
        self.FRC = OSIRulesChecker()
        orient3d = Orientation3d()
        orient3d.roll = 5
        orient3d.pitch = 2
        orient3d.yaw = 2
        self.linked_orient3d = LinkedProtoField(orient3d, "Orientation3d")

    def tearDown(self):
        del self.FRC
        del self.linked_orient3d

    def test_comply_is_valid(self):
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(['Orientation3d', 'roll'])
        container.add_type_from_path(proto_path)

        root_container = TypeRulesContainer()
        root_path = ProtoMessagePath(['Orientation3d'])
        root_container.add_type_from_path(root_path)

        rule1 = Rule(verb="is_greater_than",
                     field_name='roll',
                     params=0,
                     path=proto_path,
                     extra_params=dict())
        rule2 = Rule(verb="is_less_than",
                     field_name='roll',
                     params=10,
                     path=proto_path,
                     extra_params=dict())

        rules = FieldRules("roll",
                           rules=[rule1, rule2],
                           path=proto_path,
                           root=root_container)

        rule = MessageTypeRules(name="Orientation3d")
        rule.add_field(rules)
        rule.add_type_from_path(rules)

        rule.root = container
        rule._path = proto_path
        rule.path = proto_path

        compliance = self.FRC.is_valid(self.linked_orient3d, rule)
        self.assertTrue(compliance)

    def test_comply_is_not_valid(self):
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(['Orientation3d', 'roll'])
        container.add_type_from_path(proto_path)

        root_container = TypeRulesContainer()
        root_path = ProtoMessagePath(['Orientation3d'])
        root_container.add_type_from_path(root_path)

        rule1 = Rule(verb="is_greater_than",
                     field_name='roll',
                     params=6,
                     path=proto_path,
                     extra_params=dict())
        rule2 = Rule(verb="is_less_than",
                     field_name='roll',
                     params=10,
                     path=proto_path,
                     extra_params=dict())

        rules = FieldRules("roll",
                           rules=[rule1, rule2],
                           path=proto_path,
                           root=root_container)

        rule = MessageTypeRules(name="Orientation3d")
        rule.add_field(rules)
        rule.add_type_from_path(rules)

        rule.root = container
        rule._path = proto_path
        rule.path = proto_path

        compliance = self.FRC.is_valid(self.linked_orient3d, rule)
        self.assertFalse(compliance)
Ejemplo n.º 18
0
class TestFirstElement(unittest.TestCase):

    def setUp(self):
        self.FRC = OSIRulesChecker()

        sv1 = SensorView()
        linked_sv1 = LinkedProtoField(sv1, name="SensorView")
        gt1 = sv1.global_ground_truth
        linked_gt1 = LinkedProtoField(gt1, name="global_ground_truth", parent=linked_sv1)

        gtlb1 = gt1.lane_boundary.add()
        linked_gtlb1 = LinkedProtoField(gtlb1, name="lane_boundary", parent=linked_gt1)

        bladd1 = gtlb1.boundary_line.add()
        bladd1.position.x = 1699.2042678176733
        bladd1.position.y = 100.16895580204906
        bladd1.position.z = 0.0
        bladd1.width = 0.13
        bladd1.height = 0.0

        self.lb1 = LinkedProtoField(bladd1, name="boundary_line", parent=linked_gtlb1)
        self.lb1.path = 'SensorView.global_ground_truth.lane_boundary.boundary_line'
        # self.lb1.parent =

        sv2 = SensorView()
        linked_sv2 = LinkedProtoField(sv2, name="SensorView")

        gt2 = sv2.global_ground_truth
        linked_gt2 = LinkedProtoField(gt2, name="global_ground_truth", parent=linked_sv2)

        gtlb2 = gt2.lane_boundary.add()
        linked_gtlb2 = LinkedProtoField(gtlb2, name="lane_boundary", parent=linked_gt2)

        bladd2 = gtlb2.boundary_line.add()
        bladd2.position.x = 1699.2042678176733
        bladd2.position.y = 100.16895580204906
        bladd2.position.z = 0.0
        bladd2.width = 0.14
        bladd2.height = 0.13
        self.lb2 = LinkedProtoField(bladd2, name="boundary_line", parent=linked_gtlb2)
        self.lb2.path = 'SensorView.global_ground_truth.lane_boundary.boundary_line'

    def tearDown(self):
        del self.FRC

    def test_comply_last_element(self):
        field_list = [self.lb1, self.lb2]
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(['LaneBoundary', 'BoundaryPoint'])
        container.add_type_from_path(proto_path)
        container.add_type_from_path(ProtoMessagePath(['Vector3d']))

        rule = Rule(verb="last_element",
                    params={'width': [{'is_equal': 0.14}],
                            'height': [{'is_equal': 0.13}]},
                    path=proto_path,
                    extra_params=dict(),
                    field_name='boundary_line')
        rule.root = container
        compliance = self.FRC.last_element(field_list, rule)
        self.assertTrue(compliance)

    def test_not_comply_last_element(self):
        field_list = [self.lb1, self.lb2]
        container = TypeRulesContainer()
        proto_path = ProtoMessagePath(['LaneBoundary', 'BoundaryPoint'])
        container.add_type_from_path(proto_path)
        container.add_type_from_path(ProtoMessagePath(['Vector3d']))

        rule = Rule(verb="last_element",
                    params={'width': [{'is_equal': 0.11}],
                            'height': [{'is_equal': 0.13}]},
                    path=proto_path,
                    extra_params=dict(),
                    field_name='boundary_line')
        rule.root = container
        compliance = self.FRC.last_element(field_list, rule)
        self.assertFalse(compliance)