Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ common \ data_quality.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
1# =====================================================
2# Imports
3# =====================================================
4from typing import Annotated
6from pydantic import Field, field_validator, ValidationInfo
8from mt_metadata.base import MetadataBase
9from mt_metadata.common import Comment, Rating
12# =====================================================
13class DataQuality(MetadataBase):
14 warnings: Annotated[
15 str | None,
16 Field(
17 default=None,
18 description="any warnings about the data that should be noted",
19 alias=None,
20 json_schema_extra={
21 "units": None,
22 "required": False,
23 "examples": ["periodic pipeline noise"],
24 },
25 ),
26 ]
28 good_from_period: Annotated[
29 float | None,
30 Field(
31 default=None,
32 description="Data are good for periods larger than this number",
33 alias=None,
34 json_schema_extra={
35 "units": None,
36 "required": False,
37 "examples": ["0.01"],
38 },
39 ),
40 ]
42 good_to_period: Annotated[
43 float | None,
44 Field(
45 default=None,
46 description="Data are good for periods smaller than this number",
47 alias=None,
48 json_schema_extra={
49 "units": None,
50 "required": False,
51 "examples": ["1000"],
52 },
53 ),
54 ]
56 flag: Annotated[
57 int | None,
58 Field(
59 default=None,
60 description="Flag for data quality",
61 alias=None,
62 json_schema_extra={
63 "units": None,
64 "required": False,
65 "examples": ["0"],
66 },
67 ),
68 ]
70 comments: Annotated[
71 Comment,
72 Field(
73 default_factory=Comment, # type: ignore
74 description="any comments about the data quality",
75 alias=None,
76 json_schema_extra={
77 "units": None,
78 "required": False,
79 "examples": ["0"],
80 },
81 ),
82 ]
84 rating: Annotated[
85 Rating,
86 Field(
87 default_factory=Rating, # type: ignore
88 description="rating of the data quality",
89 alias=None,
90 json_schema_extra={
91 "units": None,
92 "required": False,
93 "examples": ["0"],
94 },
95 ),
96 ]
98 @field_validator("comments", mode="before")
99 @classmethod
100 def validate_comments(cls, value, info: ValidationInfo) -> Comment:
101 """
102 Validate that the value is a valid string.
103 """
104 if isinstance(value, str):
105 return Comment(value=value) # type: ignore[return-value]
106 return value