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
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
@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
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
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