Skip to content

Component¤

Component dataclass ¤

Component(
    name: str = "",
    adjustments: tuple[Adjustment, ...] = (),
    digital_reports: tuple[DigitalReport, ...] = (),
    performance_checks: tuple[PerformanceCheck, ...] = (),
    reports: tuple[Report, ...] = (),
)

Represents the component element in an equipment register.

Parameters:

Name Type Description Default
name str

The name to associate with this component. The value must be unique amongst the other component elements within the same measurand element. An empty string is permitted.

''
adjustments tuple[Adjustment, ...]

The history of adjustments.

()
digital_reports tuple[DigitalReport, ...]

The history of digital calibration reports.

()
performance_checks tuple[PerformanceCheck, ...]

The history of performance checks.

()
reports tuple[Report, ...]

The history of calibration reports.

()

adjustments class-attribute instance-attribute ¤

adjustments: tuple[Adjustment, ...] = ()

The history of adjustments.

digital_reports class-attribute instance-attribute ¤

digital_reports: tuple[DigitalReport, ...] = ()

The history of digital calibration reports.

name class-attribute instance-attribute ¤

name: str = ''

The name associated with this component.

performance_checks class-attribute instance-attribute ¤

performance_checks: tuple[PerformanceCheck, ...] = ()

The history of performance checks.

reports class-attribute instance-attribute ¤

reports: tuple[Report, ...] = ()

The history of calibration reports.

from_xml classmethod ¤

from_xml(element: Element[str]) -> Component

Convert an XML element into a Component instance.

Parameters:

Name Type Description Default
element Element[str]

A component XML element from an equipment register.

required

Returns:

Type Description
Component

The Component instance.

Source code in src/msl/equipment/schema.py
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
@classmethod
def from_xml(cls, element: Element[str]) -> Component:
    """Convert an XML element into a [Component][msl.equipment.schema.Component] instance.

    Args:
        element: A [component][type_component] XML element from an equipment register.

    Returns:
        The [Component][msl.equipment.schema.Component] instance.
    """
    # Schema defines <component> using xsd:choice, which allows sub-elements to appear (or not appear) in any order
    # Using str.endswith() allows for ignoring XML namespaces that may be associated with each tag
    a: list[Adjustment] = []
    dr: list[DigitalReport] = []
    pc: list[PerformanceCheck] = []
    r: list[Report] = []
    for child in element:
        tag = child.tag
        if tag.endswith("report"):
            r.append(Report.from_xml(child))
        elif tag.endswith("performanceCheck"):
            pc.append(PerformanceCheck.from_xml(child))
        elif tag.endswith("adjustment"):
            a.append(Adjustment.from_xml(child))
        else:
            dr.append(DigitalReport.from_xml(child))

    return cls(
        name=element.attrib["name"],
        adjustments=tuple(a),
        digital_reports=tuple(dr),
        performance_checks=tuple(pc),
        reports=tuple(r),
    )

to_xml ¤

to_xml() -> Element[str]

Convert the Component class into an XML element.

Returns:

Type Description
Element[str]

The Component as an XML element.

Source code in src/msl/equipment/schema.py
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
def to_xml(self) -> Element[str]:
    """Convert the [Component][msl.equipment.schema.Component] class into an XML element.

    Returns:
        The [Component][msl.equipment.schema.Component] as an XML element.
    """
    e = Element("component", attrib={"name": self.name})

    # the order is not important since xsd:choice is used
    e.extend(r.to_xml() for r in self.reports)
    e.extend(p.to_xml() for p in self.performance_checks)
    e.extend(a.to_xml() for a in self.adjustments)
    e.extend(d.to_xml() for d in self.digital_reports)
    return e