Skip to content

Commit

Permalink
Update locations missing implementation
Browse files Browse the repository at this point in the history
Signed-off-by: patrickpa <[email protected]>
  • Loading branch information
patrickpa committed Jun 11, 2024
1 parent 7e08efa commit 48d2314
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
14 changes: 8 additions & 6 deletions qc_baselib/models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class XMLLocationType(BaseXmlModel, tag="XMLLocation"):


class InertialLocationType(BaseXmlModel, tag="InertialLocation"):
x: float
y: float
z: float
x: float = attr(name="x")
y: float = attr(name="y")
z: float = attr(name="z")


class FileLocationType(BaseXmlModel, tag="FileLocation"):
Expand All @@ -34,16 +34,18 @@ class FileLocationType(BaseXmlModel, tag="FileLocation"):
file_type: str = attr(name="fileType")


class LocationType(BaseXmlModel, tag="Location"):
class LocationType(BaseXmlModel, tag="Locations"):
file_location: List[FileLocationType] = []
xml_location: List[XMLLocationType] = []
road_location: List[InertialLocationType] = []
inertial_location: List[InertialLocationType] = []
description: str = attr(name="description")

@model_validator(mode="after")
def check_at_least_one_element(self) -> Any:
if (
len(self.file_location) + len(self.xml_location) + len(self.road_location)
len(self.file_location)
+ len(self.xml_location)
+ len(self.inertial_location)
< 1
):
raise ValueError(
Expand Down
23 changes: 23 additions & 0 deletions qc_baselib/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,29 @@ def add_xml_location(
result.LocationType(xml_location=[xml_location], description=description)
)

def add_inertial_location(
self,
checker_bundle_name: str,
checker_id: str,
issue_id: int,
x: float,
y: float,
z: float,
description: str,
) -> None:
inertial_location = result.InertialLocationType(x=x, y=y, z=z)

bundle = self._get_checker_bundle(checker_bundle_name=checker_bundle_name)

checker = self._get_checker(bundle=bundle, checker_id=checker_id)
issue = self._get_issue(checker=checker, issue_id=issue_id)

issue.locations.append(
result.LocationType(
inertial_location=[inertial_location], description=description
)
)

def add_domain_specific_info(
self,
checker_bundle_name: str,
Expand Down
5 changes: 5 additions & 0 deletions tests/data/demo_checker_bundle_extended.xqar
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<Checker checkerId="exampleIssueRuleChecker" description="This is a description of checker with issue and the involved ruleUID" status="completed" summary="">
<AddressedRule ruleUID="test.com:qc:1.0.0:qwerty.qwerty"/>
<Issue description="This is an information from the demo usecase" issueId="2" level="1" ruleUID="test.com:qc:1.0.0:qwerty.qwerty">

<Locations description="inertial position">
<InertialLocation x="1.000000" y="2.000000" z="3.000000"/>
</Locations>
<DomainSpecificInfo name="test_domain">
<RoadLocation b="5.4" c="0.0" id="aa" />
<RoadLocation b="5.4" c="0.0" id="aa" />
Expand All @@ -33,6 +37,7 @@
</InternalElementNested>
</TestTagFor>
</DomainSpecificInfo>

</Issue>
</Checker>
<Checker checkerId="exampleSkippedChecker" description="This is a description of checker with skipped status" status="skipped" summary="Skipped execution"/>
Expand Down
8 changes: 4 additions & 4 deletions tests/data/result_test_output.xqar
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<Checker status="completed" checkerId="TestChecker" description="Test checker" summary="Executed evaluation">
<AddressedRule ruleUID="test.com:qc:1.0.0:qwerty.qwerty"/>
<Issue issueId="0" description="Issue found at odr" level="3" ruleUID="test.com:qc:1.0.0:qwerty.qwerty">
<Location description="Location for issue">
<Locations description="Location for issue">
<FileLocation column="0" row="1" fileType="odr"/>
</Location>
<Location description="Location for issue">
</Locations>
<Locations description="Location for issue">
<XMLLocation xpath="/foo/test/path"/>
</Location>
</Locations>
</Issue>
</Checker>
</CheckerBundle>
Expand Down
24 changes: 24 additions & 0 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ def test_domain_specific_load(loaded_extended_result: Result):
)
)

# Evaluate if loading of issues with domain elements is properly done
assert (
xml_text
== b'<Issue issueId="2" description="This is an information from the demo usecase" level="1" ruleUID="test.com:qc:1.0.0:qwerty.qwerty"><Locations description="inertial position"><InertialLocation x="1.0" y="2.0" z="3.0"/></Locations><DomainSpecificInfo name="test_domain">\n <RoadLocation b="5.4" c="0.0" id="aa"/>\n <RoadLocation b="5.4" c="0.0" id="aa"/>\n <TestTagFor>\n <InternalElementA a="1.0"/>\n <InternalElementA a="1.0"/>\n <InternalElementNested a="1.0">\n <NestedElement/>\n </InternalElementNested>\n </TestTagFor>\n </DomainSpecificInfo>\n \n </Issue>\n'
)


def test_domain_specific_info_add():
result = Result()
Expand Down Expand Up @@ -407,6 +413,14 @@ def test_domain_specific_info_add():
xml_info.append(etree.Element("NestedCustomTag", attrib={"test": "value"}))
xml_info.append(etree.Element("NestedCustomTag", attrib={"test": "value"}))

result.add_xml_location(
checker_bundle_name="TestBundle",
checker_id="TestChecker",
issue_id=issue_id,
xpath="/foo/test/path",
description="Location for issue",
)

result.add_domain_specific_info(
checker_bundle_name="TestBundle",
checker_id="TestChecker",
Expand All @@ -415,6 +429,16 @@ def test_domain_specific_info_add():
xml_info=xml_info,
)

result.add_file_location(
checker_bundle_name="TestBundle",
checker_id="TestChecker",
issue_id=issue_id,
row=1,
column=0,
file_type="odr",
description="Location for issue",
)

result.write_to_file(TEST_REPORT_OUTPUT_PATH)

output_result = Result()
Expand Down

0 comments on commit 48d2314

Please sign in to comment.