-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresource_datamodels.py
More file actions
209 lines (158 loc) · 7.2 KB
/
Copy pathresource_datamodels.py
File metadata and controls
209 lines (158 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# ==============================================================================
# Copyright (c) 2024 Botts Innovative Research, Inc.
# Date: 2024/6/26
# Author: Ian Patterson
# Contact Email: ian@botts-inc.com
# ==============================================================================
from __future__ import annotations
from typing import List
from timemanagement import TimeInstant
from .geometry import Geometry
from .api_utils import Link
from pydantic import BaseModel, ConfigDict, Field, SerializeAsAny, model_validator
from shapely import Point
from .schema_datamodels import DatastreamRecordSchema, CommandSchema
from .timemanagement import TimePeriod
class BoundingBox(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True)
lower_left_corner: Point = Field(..., description="The lower left corner of the bounding box.")
upper_right_corner: Point = Field(..., description="The upper right corner of the bounding box.")
min_value: float = Field(None, description="The minimum value of the bounding box.")
max_value: float = Field(None, description="The maximum value of the bounding box.")
# @model_validator(mode='before')
# def validate_minmax(self) -> Self:
# if self.min_value > self.max_value:
# raise ValueError("min_value must be less than max_value")
# return self
class SecurityConstraints:
constraints: list
class LegalConstraints:
constraints: list
class Characteristics:
characteristics: list
class Capabilities:
capabilities: list
class Contact:
contact: list
class Documentation:
documentation: list
class HistoryEvent:
history_event: list
class ConfigurationSettings:
settings: list
class FeatureOfInterest:
feature: list
class Input:
input: list
class Output:
output: list
class Parameter:
parameter: list
class Mode:
mode: list
class ProcessMethod:
method: list
class BaseResource(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True)
id: str = Field(..., alias="id")
name: str = Field(...)
description: str = Field(None)
type: str = Field(None)
links: List[Link] = Field(None)
class SystemResource(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True)
feature_type: str = Field(None, alias="type")
system_id: str = Field(None, alias="id")
properties: dict = Field(None)
geometry: Geometry | None = Field(None)
bbox: BoundingBox = Field(None)
links: List[Link] = Field(None)
description: str = Field(None)
uid: str = Field(None, alias="uniqueId")
label: str = Field(None)
lang: str = Field(None)
keywords: List[str] = Field(None)
identifiers: List[str] = Field(None)
classifiers: List[str] = Field(None)
valid_time: TimePeriod = Field(None, alias="validTime")
security_constraints: List[SecurityConstraints] = Field(None, alias="securityConstraints")
legal_constraints: List[LegalConstraints] = Field(None, alias="legalConstraints")
characteristics: List[Characteristics] = Field(None)
capabilities: List[Capabilities] = Field(None)
contacts: List[Contact] = Field(None)
documentation: List[Documentation] = Field(None)
history: List[HistoryEvent] = Field(None)
definition: str = Field(None)
type_of: str = Field(None, alias="typeOf")
configuration: ConfigurationSettings = Field(None)
features_of_interest: List[FeatureOfInterest] = Field(None, alias="featuresOfInterest")
inputs: List[Input] = Field(None)
outputs: List[Output] = Field(None)
parameters: List[Parameter] = Field(None)
modes: List[Mode] = Field(None)
method: ProcessMethod = Field(None)
class DatastreamResource(BaseModel):
"""
The DatastreamResource class is a Pydantic model that represents a datastream resource in the OGC SensorThings API.
It contains all the necessary and optional properties listed in the OGC Connected Systems API documentation. Note
that, depending on the format of the request, the fields needed may differ. There may be derived models in a later
release that will have different sets of required fields to ease the validation process for users.
"""
model_config = ConfigDict(populate_by_name=True)
ds_id: str = Field(..., alias="id")
name: str = Field(...)
description: str = Field(None)
valid_time: TimePeriod = Field(..., alias="validTime")
output_name: str = Field(None, alias="outputName")
procedure_link: Link = Field(None, alias="procedureLink@link")
deployment_link: Link = Field(None, alias="deploymentLink@link")
feature_of_interest_link: Link = Field(None, alias="featureOfInterest@link")
sampling_feature_link: Link = Field(None, alias="samplingFeature@link")
parameters: dict = Field(None)
phenomenon_time: TimePeriod = Field(None, alias="phenomenonTimeInterval")
result_time: TimePeriod = Field(None, alias="resultTimeInterval")
ds_type: str = Field(None, alias="type")
result_type: str = Field(None, alias="resultType")
links: List[Link] = Field(None)
record_schema: SerializeAsAny[DatastreamRecordSchema] = Field(None, alias="schema")
@classmethod
@model_validator(mode="before")
def handle_aliases(cls, values):
if isinstance(values, dict):
if 'ds_id' not in values:
for alias in ('id', 'datastream_id'):
if alias in values:
values['ds_id'] = values[alias]
break
if 'valid_time' not in values:
for alias in ('validTime', 'time_interval'):
if alias in values:
values['valid_time'] = values[alias]
break
return values
class ObservationResource(BaseModel):
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
sampling_feature_id: str = Field(None, alias="samplingFeature@Id")
procedure_link: Link = Field(None, alias="procedure@link")
phenomenon_time: TimeInstant = Field(None, alias="phenomenonTime")
result_time: TimeInstant = Field(..., alias="resultTime")
parameters: dict = Field(None)
result: dict = Field(...)
result_link: Link = Field(None, alias="result@link")
class ControlStreamResource(BaseModel):
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
cs_id: str = Field(None, alias="id")
name: str = Field(...)
description: str = Field(None)
valid_time: TimePeriod = Field(None, alias="validTime")
input_name: str = Field(None, alias="inputName")
procedure_link: Link = Field(None, alias="procedureLink@link")
deployment_link: Link = Field(None, alias="deploymentLink@link")
feature_of_interest_link: Link = Field(None, alias="featureOfInterest@link")
sampling_feature_link: Link = Field(None, alias="samplingFeature@link")
issue_time: TimePeriod = Field(None, alias="issueTime")
execution_time: TimePeriod = Field(None, alias="executionTime")
live: bool = Field(None)
asynchronous: bool = Field(True, alias="async")
command_schema: SerializeAsAny[CommandSchema] = Field(None, alias="schema")
links: List[Link] = Field(None)