Register¤
An equipment register can be stored in a single XML file or distributed across multiple XML files. In this example we load a single XML file.
>>> from msl.equipment import Register
>>> register = Register("tests/data/mass/register.xml")
Printing the register object shows the name of the team that is responsible for the equipment register and the number of Equipment items that are in the register.
>>> register
Register(team='Mass' (2 equipment))
>>> register.team
'Mass'
A register behaves like a sequence of Equipment items. You can get the number of items in the sequence and iterate over the sequence,
>>> len(register)
2
>>> for equipment in register:
... print(equipment.id)
...
MSLE.M.001
MSLE.M.092
access equipment by its index, its equipment id or its alias.
>>> register[1].id # index
'MSLE.M.092'
>>> register["MSLE.M.092"].id # equipment id
'MSLE.M.092'
>>> register["Bob"].id # alias
'MSLE.M.092'
The get method will attempt to get the Equipment at the specified index, id or alias, but will return None (instead of raising an exception) if the Equipment cannot be found in the register.
>>> assert register.get(4) is None # invalid index
>>> assert register.get("MSLE.M.999") is None # invalid equipment id
>>> register.get("Bob") # valid alias
Equipment(id='MSLE.M.092', manufacturer='XYZ', model='A', serial='b' (4 reports))
The find method searches the register to find equipment that contain certain text. You may use a regular-expression pattern to find matching equipment items. Here we find all equipment that have the text Hygrometer in one of the Equipment attribute values that are considered in the search.
>>> for hygrometer in register.find("Hygrometer"):
... print(hygrometer)
Equipment(id='MSLE.M.092', manufacturer='XYZ', model='A', serial='b' (4 reports))
We see that one equipment was found and that there are four calibration reports associated with the equipment. From the Equipment instance, we can get the latest calibration report for a certain Component name and Measurand quantity.
Tip
If the equipment contains only one Measurand and one Component you do not need to specify the name and quantity keyword arguments.
>>> report = hygrometer.latest_report(name="Probe 1", quantity="Humidity")
>>> report
LatestReport(name='Probe 1', quantity='Humidity', id='Humidity/2023/583' (1 equation))
We see that the calibration report contains one Equation. We can use the equation to apply a correction to measured values and to calculate the uncertainty.
>>> value = report.equation.value
>>> value.equation
'R - 7.131e-2 - 3.951e-2*R + 3.412e-4*pow(R,2) + 2.465e-3*t + 1.034e-3*R*t - 5.297e-6*pow(R,2)*t'
>>> value(R=[45.5, 46.1], t=[20.1, 20.0])
array([45.1121266, 45.7099039])
>>> report.equation.uncertainty(R=[45.5, 46.1], t=[20.1, 20.0])
array([0.355, 0.355])
>>> report.equation.unit
'%rh'
From the LatestReport instance, we can, for example, get the date when the next calibration is due.
>>> report.next_calibration_date
datetime.date(2028, 8, 14)
Register
¤
Represents the register element in an equipment register.
Specifying multiple sources allows for storing an equipment register across multiple files for the same team. Not specifying a source creates a new (empty) register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
XMLSource | Element[str]
|
()
|
Source code in src/msl/equipment/schema.py
2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 | |
NAMESPACE
class-attribute
instance-attribute
¤
NAMESPACE: str = 'https://measurement.govt.nz/equipment-register'
Default XML namespace.
team
property
writable
¤
team: str
str — The name of the team that is responsible for the equipment register.
add
¤
add(equipment: Equipment) -> None
Add equipment to the register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
equipment
|
Equipment
|
The equipment to add. |
required |
Source code in src/msl/equipment/schema.py
2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 | |
find
¤
Find equipment in the register.
The following values are used in the search:
- keywords: Equipment
- description: Equipment
- manufacturer: Equipment
- model: Equipment
- serial: Equipment
- id: Equipment, Report, DigitalReport
- location: Equipment
- quantity: Measurand
- name: Component
- entered_by: Equipment, PerformanceCheck, Report
- checked_by: Equipment, PerformanceCheck, Report
- performed_by: Alteration, CompletedTask, PlannedTask
- comment: CVDEquation, Equation, File, Table, Deserialised, DigitalReport
- format: DigitalReport
- details: Alteration, Adjustment
- task: CompletedTask, PlannedTask
- asset_number: CapitalExpenditure
- service_agent: QualityManual
- technical_procedures: QualityManual
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str | Pattern[str]
|
A regular-expression pattern to use to find equipment. |
required |
flags
|
int
|
The flags to use to compile the |
0
|
Yields:
| Type | Description |
|---|---|
Equipment
|
Equipment that match the |
Source code in src/msl/equipment/schema.py
2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 | |
get
¤
Get an Equipment item from the register.
This method will ignore all errors if the register does not contain the requested Equipment item.
Tip
You can also treat a register instance as a sequence of Equipment items.
Using the indexable notation on a register instance to access an Equipment item by using the alias of the equipment or the index within the register could raise an exception
>>> register["unknown-alias"]
Traceback (most recent call last):
...
ValueError: No equipment exists with the alias or id 'unknown-alias'
>>> register[243]
Traceback (most recent call last):
...
IndexError: list index out of range
whereas these errors can be silenced by using the get method
>>> assert register.get("unknown") is None
>>> assert register.get(243) is None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
int | str
|
The index number, equipment id value or the equipment alias value in the register. |
required |
Returns:
| Type | Description |
|---|---|
Equipment | None
|
The Equipment item if |
Source code in src/msl/equipment/schema.py
2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 | |
tree
¤
tree(
namespace: str | None = "DEFAULT", indent: int = 4
) -> ElementTree[Element[str]]
Convert the Register class into an XML element tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
str | None
|
The namespace to associate with the root element. If the value is
|
'DEFAULT'
|
indent
|
int
|
The number of spaces to indent sub elements. The value must be ≥ 0. This parameter is ignored if the version of Python is < 3.9. |
4
|
Returns:
| Type | Description |
|---|---|
ElementTree[Element[str]]
|
The Register as an ElementTree. |
Source code in src/msl/equipment/schema.py
3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 | |