Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for special data groups (SDGs) #99

Merged
merged 3 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 44 additions & 26 deletions odxtools/admindata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from .companydata import CompanyData, TeamMember
from .odxlink import OdxLinkId, OdxLinkRef, OdxLinkDatabase, OdxDocFragment
from .utils import read_description_from_odx
from .specialdata import SpecialDataGroup, read_sdgs_from_odx

from xml.etree import ElementTree
from dataclasses import dataclass, field
from typing import Optional, Any, Dict, List

Expand All @@ -14,14 +16,30 @@ class CompanyDocInfo:
company_data_ref: OdxLinkRef
company_data: Optional[CompanyData] = None
team_member_ref: Optional[OdxLinkRef] = None
team_member: Optional[TeamMember] = None
doc_label: Optional[str] = None
sdgs: List[SpecialDataGroup] = field(default_factory=list)

_team_member: Optional[TeamMember] = None
@property
def team_member(self) -> Optional[TeamMember]:
return self._team_member

def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
result = { }

for sdg in self.sdgs:
result.update(sdg._build_odxlinks())

return result

def _resolve_references(self, odxlinks: OdxLinkDatabase):
self.company_data = odxlinks.resolve(self.company_data_ref)

if self.team_member_ref is not None:
self.team_member = odxlinks.resolve(self.team_member_ref)
self._team_member = odxlinks.resolve(self.team_member_ref)

for sdg in self.sdgs:
sdg._resolve_references(odxlinks)

@dataclass()
class Modification:
Expand All @@ -48,12 +66,15 @@ def _resolve_references(self, odxlinks: OdxLinkDatabase):
@dataclass()
class AdminData:
language: Optional[str] = None
company_doc_infos: Optional[List[CompanyDocInfo]] = None
company_doc_infos: List[CompanyDocInfo] = field(default_factory=list)
doc_revisions: Optional[List[DocRevision]] = None

def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
result: Dict[OdxLinkId, Any] = {}

for cdi in self.company_doc_infos:
result.update(cdi._build_odxlinks())

return result

def _resolve_references(self, odxlinks: OdxLinkDatabase):
Expand All @@ -65,38 +86,41 @@ def _resolve_references(self, odxlinks: OdxLinkDatabase):
for dr in self.doc_revisions:
dr._resolve_references(odxlinks)

def read_admin_data_from_odx(et_element, doc_frags: List[OdxDocFragment]):
for cdi in self.company_doc_infos:
cdi._resolve_references(odxlinks)

def read_admin_data_from_odx(et_element: Optional[ElementTree.Element],
doc_frags: List[OdxDocFragment]) \
-> Optional[AdminData]:

if et_element is None:
return None

language = et_element.findtext("LANGUAGE")

company_doc_infos = et_element.find("COMPANY-DOC-INFOS")
if company_doc_infos is not None:
cdilist = list()
for cdi in company_doc_infos.iterfind("COMPANY-DOC-INFO"):
company_doc_infos = list()
if cdis_elem := et_element.find("COMPANY-DOC-INFOS"):
for cdi in cdis_elem.iterfind("COMPANY-DOC-INFO"):
# the company data reference is mandatory
company_data_ref = OdxLinkRef.from_et(cdi.find("COMPANY-DATA-REF"), doc_frags)
assert company_data_ref is not None
team_member_ref = OdxLinkRef.from_et(cdi.find("TEAM-MEMBER-REF"), doc_frags)
assert team_member_ref is not None

doc_label = cdi.findtext("DOC-LABEL")
sdgs = read_sdgs_from_odx(cdi.find("SDGS"), doc_frags)

cdilist.append(CompanyDocInfo(company_data_ref=company_data_ref,
team_member_ref=team_member_ref,
doc_label=doc_label))
company_doc_infos.append(CompanyDocInfo(company_data_ref=company_data_ref,
team_member_ref=team_member_ref,
doc_label=doc_label,
sdgs=sdgs))

company_doc_infos = cdilist

doc_revisions = et_element.find("DOC-REVISIONS")
if doc_revisions is not None:
drlist = list()
for dr in doc_revisions.iterfind("DOC-REVISION"):
doc_revisions = []
if drs_elem := et_element.find("DOC-REVISIONS"):
for dr in drs_elem.iterfind("DOC-REVISION"):
team_member_ref = OdxLinkRef.from_et(dr.find("TEAM-MEMBER-REF"), doc_frags)
revision_label = dr.findtext("REVISION-LABEL")
state = dr.findtext("STATE")
date = dr.findtext("DATE")
assert date is not None
tool = dr.findtext("TOOL")

modlist = None
Expand All @@ -110,19 +134,13 @@ def read_admin_data_from_odx(et_element, doc_frags: List[OdxDocFragment]):
modlist.append(Modification(change=m_change,
reason=m_reason))

drlist.append(DocRevision(team_member_ref=team_member_ref,
doc_revisions.append(DocRevision(team_member_ref=team_member_ref,
revision_label=revision_label,
state=state,
date=date,
tool=tool,
modifications=modlist))


doc_revisions = drlist

else:
doc_revisions = []

return AdminData(language=language,
company_doc_infos=company_doc_infos,
doc_revisions=doc_revisions)
8 changes: 7 additions & 1 deletion odxtools/audience.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2022 MBition GmbH

from dataclasses import dataclass, field
from typing import Optional, List
from typing import Optional, List, Dict, Any
from odxtools.utils import read_description_from_odx
from .odxlink import OdxLinkRef, OdxLinkId, OdxDocFragment, OdxLinkDatabase

Expand Down Expand Up @@ -44,6 +44,12 @@ class AdditionalAudience:
long_name: Optional[str] = None
description: Optional[str] = None

def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
return { self.odx_id: self }

def _resolve_references(self, odxlinks: OdxLinkDatabase) -> None:
pass


def read_audience_from_odx(et_element, doc_frags: List[OdxDocFragment]):
enabled_audience_refs = [OdxLinkRef.from_et(ref, doc_frags)
Expand Down
25 changes: 23 additions & 2 deletions odxtools/companydata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .utils import read_description_from_odx
from .odxlink import OdxLinkId, OdxLinkDatabase, OdxDocFragment
from .utils import short_name_as_id
from .specialdata import SpecialDataGroup, read_sdgs_from_odx

from dataclasses import dataclass, field
from typing import Optional, Any, Dict, List
Expand All @@ -29,6 +30,19 @@ class RelatedDoc:
@dataclass()
class CompanySpecificInfo:
related_docs: Optional[List[RelatedDoc]]
sdgs: List[SpecialDataGroup] = field(default_factory=list)

def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
result = { }

for sdg in self.sdgs:
result.update(sdg._build_odxlinks())

return result

def _resolve_references(self, odxlinks: OdxLinkDatabase):
for sdg in self.sdgs:
sdg._resolve_references(odxlinks)

@dataclass()
class TeamMember:
Expand Down Expand Up @@ -63,10 +77,14 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
for tm in self.team_members:
result[tm.odx_id] = tm

if self.company_specific_info:
result.update(self.company_specific_info._build_odxlinks())

return result

def _resolve_references(self, odxlinks: OdxLinkDatabase):
pass
if self.company_specific_info:
self.company_specific_info._resolve_references(odxlinks)

def read_xdoc_from_odx(xdoc):
short_name = xdoc.findtext("SHORT-NAME")
Expand Down Expand Up @@ -170,7 +188,10 @@ def read_company_datas_from_odx(et_element, doc_frags: List[OdxDocFragment]) \

related_docs = rdlist

company_specific_info = CompanySpecificInfo(related_docs=related_docs)
sdgs = read_sdgs_from_odx(company_specific_info.find("SDGS"), doc_frags)

company_specific_info = CompanySpecificInfo(related_docs=related_docs,
sdgs=sdgs)

cdl.append(CompanyData(odx_id=odx_id,
short_name=short_name,
Expand Down
25 changes: 24 additions & 1 deletion odxtools/comparam_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .admindata import AdminData, read_admin_data_from_odx
from .companydata import CompanyData, read_company_datas_from_odx
from .utils import read_description_from_odx, short_name_as_id

from .specialdata import SpecialDataGroup, read_sdgs_from_odx

StandardizationLevel = Literal[
"STANDARD",
Expand Down Expand Up @@ -102,6 +102,7 @@ class ComparamSubset:
description: Optional[str] = None
admin_data: Optional[AdminData] = None
company_datas: Optional[NamedItemList[CompanyData]] = None
sdgs: List[SpecialDataGroup] = field(default_factory=list)

def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
odxlinks: Dict[OdxLinkId, Any] = {}
Expand All @@ -117,6 +118,16 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
if self.unit_spec:
odxlinks.update(self.unit_spec._build_odxlinks())

if self.admin_data is not None:
odxlinks.update(self.admin_data._build_odxlinks())

if self.company_datas is not None:
for cd in self.company_datas:
odxlinks.update(cd._build_odxlinks())

for sdg in self.sdgs:
odxlinks.update(sdg._build_odxlinks())

return odxlinks

def _resolve_references(self, odxlinks: OdxLinkDatabase):
Expand All @@ -129,6 +140,15 @@ def _resolve_references(self, odxlinks: OdxLinkDatabase):
if self.unit_spec:
self.unit_spec._resolve_references(odxlinks)

if self.admin_data is not None:
self.admin_data._resolve_references(odxlinks)

if self.company_datas is not None:
for cd in self.company_datas:
cd._resolve_references(odxlinks)

for sdg in self.sdgs:
sdg._resolve_references(odxlinks)

def read_comparam_from_odx(et_element, doc_frags: List[OdxDocFragment]) -> BaseComparam:
odx_id = OdxLinkId.from_et(et_element, doc_frags)
Expand Down Expand Up @@ -217,6 +237,8 @@ def read_comparam_subset_from_odx(et_element: Element) -> ComparamSubset:
else:
unit_spec = None

sdgs = read_sdgs_from_odx(et_element.find("SDGS"), doc_frags)

return ComparamSubset(
odx_id=odx_id,
category=category,
Expand All @@ -228,4 +250,5 @@ def read_comparam_subset_from_odx(et_element: Element) -> ComparamSubset:
data_object_props=NamedItemList(short_name_as_id, data_object_props),
comparams=NamedItemList(short_name_as_id, comparams),
unit_spec=unit_spec,
sdgs=sdgs,
)
12 changes: 6 additions & 6 deletions odxtools/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,24 @@ def finalize_init(self) -> None:
self._odxlinks = OdxLinkDatabase()

for subset in self.comparam_subsets:
self.odxlinks.update(subset._build_odxlinks())
self._odxlinks.update(subset._build_odxlinks())

for dlc in self.diag_layer_containers:
self.odxlinks.update(dlc._build_odxlinks())
self._odxlinks.update(dlc._build_odxlinks())

for dl in self.diag_layers:
self.odxlinks.update(dl._build_odxlinks())
self._odxlinks.update(dl._build_odxlinks())

# Resolve references
for subset in self.comparam_subsets:
subset._resolve_references(self.odxlinks)
subset._resolve_references(self._odxlinks)
for dlc in self.diag_layer_containers:
dlc._resolve_references(self.odxlinks)
dlc._resolve_references(self._odxlinks)

for dl_type_name in ["ECU-SHARED-DATA", "PROTOCOL", "FUNCTIONAL-GROUP", "BASE-VARIANT", "ECU-VARIANT"]:
for dl in self.diag_layers:
if dl.variant_type == dl_type_name:
dl._resolve_references(self.odxlinks)
dl._resolve_references(self._odxlinks)

@property
def odxlinks(self) -> OdxLinkDatabase:
Expand Down
Loading