hydroserverpy 0.3.0__py3-none-any.whl → 0.5.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hydroserverpy might be problematic. Click here for more details.
- hydroserverpy/__init__.py +3 -4
- hydroserverpy/api/http.py +24 -0
- hydroserverpy/api/main.py +152 -0
- hydroserverpy/api/models/__init__.py +18 -0
- hydroserverpy/api/models/base.py +74 -0
- hydroserverpy/api/models/etl/__init__.py +0 -0
- hydroserverpy/api/models/iam/__init__.py +0 -0
- hydroserverpy/api/models/iam/account.py +12 -0
- hydroserverpy/api/models/iam/collaborator.py +34 -0
- hydroserverpy/api/models/iam/role.py +10 -0
- hydroserverpy/api/models/iam/workspace.py +203 -0
- hydroserverpy/api/models/sta/__init__.py +0 -0
- hydroserverpy/api/models/sta/datastream.py +336 -0
- hydroserverpy/api/models/sta/observed_property.py +72 -0
- hydroserverpy/api/models/sta/processing_level.py +50 -0
- hydroserverpy/api/models/sta/result_qualifier.py +49 -0
- hydroserverpy/api/models/sta/sensor.py +105 -0
- hydroserverpy/api/models/sta/thing.py +217 -0
- hydroserverpy/api/models/sta/unit.py +49 -0
- hydroserverpy/api/services/__init__.py +8 -0
- hydroserverpy/api/services/base.py +92 -0
- hydroserverpy/api/services/etl/__init__.py +0 -0
- hydroserverpy/api/services/iam/__init__.py +0 -0
- hydroserverpy/api/services/iam/workspace.py +126 -0
- hydroserverpy/api/services/sta/__init__.py +0 -0
- hydroserverpy/api/services/sta/datastream.py +354 -0
- hydroserverpy/api/services/sta/observed_property.py +98 -0
- hydroserverpy/api/services/sta/processing_level.py +78 -0
- hydroserverpy/api/services/sta/result_qualifier.py +74 -0
- hydroserverpy/api/services/sta/sensor.py +116 -0
- hydroserverpy/api/services/sta/thing.py +188 -0
- hydroserverpy/api/services/sta/unit.py +82 -0
- hydroserverpy/etl/__init__.py +21 -0
- hydroserverpy/etl/extractors/__init__.py +0 -0
- hydroserverpy/etl/extractors/base.py +13 -0
- hydroserverpy/etl/extractors/ftp_extractor.py +50 -0
- hydroserverpy/etl/extractors/http_extractor.py +84 -0
- hydroserverpy/etl/extractors/local_file_extractor.py +25 -0
- hydroserverpy/etl/hydroserver_etl.py +40 -0
- hydroserverpy/etl/loaders/__init__.py +0 -0
- hydroserverpy/etl/loaders/base.py +13 -0
- hydroserverpy/etl/loaders/hydroserver_loader.py +68 -0
- hydroserverpy/etl/transformers/__init__.py +0 -0
- hydroserverpy/etl/transformers/base.py +52 -0
- hydroserverpy/etl/transformers/csv_transformer.py +88 -0
- hydroserverpy/etl/transformers/json_transformer.py +62 -0
- hydroserverpy/etl/types.py +7 -0
- hydroserverpy/etl_csv/__init__.py +0 -0
- hydroserverpy/{etl/service.py → etl_csv/hydroserver_etl_csv.py} +93 -55
- hydroserverpy/quality/service.py +84 -70
- hydroserverpy-0.5.0b1.dist-info/METADATA +19 -0
- hydroserverpy-0.5.0b1.dist-info/RECORD +59 -0
- {hydroserverpy-0.3.0.dist-info → hydroserverpy-0.5.0b1.dist-info}/WHEEL +1 -1
- hydroserverpy/core/endpoints/__init__.py +0 -9
- hydroserverpy/core/endpoints/base.py +0 -133
- hydroserverpy/core/endpoints/data_loaders.py +0 -92
- hydroserverpy/core/endpoints/data_sources.py +0 -92
- hydroserverpy/core/endpoints/datastreams.py +0 -188
- hydroserverpy/core/endpoints/observed_properties.py +0 -93
- hydroserverpy/core/endpoints/processing_levels.py +0 -93
- hydroserverpy/core/endpoints/result_qualifiers.py +0 -93
- hydroserverpy/core/endpoints/sensors.py +0 -93
- hydroserverpy/core/endpoints/things.py +0 -240
- hydroserverpy/core/endpoints/units.py +0 -93
- hydroserverpy/core/schemas/__init__.py +0 -9
- hydroserverpy/core/schemas/base.py +0 -117
- hydroserverpy/core/schemas/data_loaders.py +0 -71
- hydroserverpy/core/schemas/data_sources.py +0 -206
- hydroserverpy/core/schemas/datastreams.py +0 -299
- hydroserverpy/core/schemas/observed_properties.py +0 -35
- hydroserverpy/core/schemas/processing_levels.py +0 -27
- hydroserverpy/core/schemas/result_qualifiers.py +0 -23
- hydroserverpy/core/schemas/sensors.py +0 -53
- hydroserverpy/core/schemas/things.py +0 -309
- hydroserverpy/core/schemas/units.py +0 -30
- hydroserverpy/core/service.py +0 -186
- hydroserverpy-0.3.0.dist-info/METADATA +0 -18
- hydroserverpy-0.3.0.dist-info/RECORD +0 -36
- /hydroserverpy/{core → api}/__init__.py +0 -0
- /hydroserverpy/{etl → etl_csv}/exceptions.py +0 -0
- {hydroserverpy-0.3.0.dist-info → hydroserverpy-0.5.0b1.dist-info/licenses}/LICENSE +0 -0
- {hydroserverpy-0.3.0.dist-info → hydroserverpy-0.5.0b1.dist-info}/top_level.txt +0 -0
- {hydroserverpy-0.3.0.dist-info → hydroserverpy-0.5.0b1.dist-info}/zip-safe +0 -0
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from typing import Union, List, IO, TYPE_CHECKING
|
|
3
|
-
from uuid import UUID
|
|
4
|
-
from hydroserverpy.core.endpoints.base import HydroServerEndpoint, expand_docstring
|
|
5
|
-
from hydroserverpy.core.endpoints.datastreams import DatastreamEndpoint
|
|
6
|
-
from hydroserverpy.core.schemas import Thing, Datastream, Tag, Photo, Archive
|
|
7
|
-
|
|
8
|
-
if TYPE_CHECKING:
|
|
9
|
-
from hydroserverpy.core.service import HydroServer
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class ThingEndpoint(HydroServerEndpoint):
|
|
13
|
-
"""
|
|
14
|
-
An endpoint for interacting with thing entities in the HydroServer service.
|
|
15
|
-
|
|
16
|
-
:ivar _model: The model class associated with this endpoint, set to `Thing`.
|
|
17
|
-
:ivar _api_route: The base route of the API, derived from the service.
|
|
18
|
-
:ivar _endpoint_route: The specific route of the endpoint, set to `'things'`.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
def __init__(self, service: 'HydroServer'):
|
|
22
|
-
"""
|
|
23
|
-
Initialize the ThingEndpoint.
|
|
24
|
-
|
|
25
|
-
:param service: The HydroServer service instance to use for requests.
|
|
26
|
-
:type service: HydroServer
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
super().__init__(service)
|
|
30
|
-
self._model = Thing
|
|
31
|
-
self._api_route = self._service.api_route
|
|
32
|
-
self._endpoint_route = 'things'
|
|
33
|
-
|
|
34
|
-
def list(self, owned_only: bool = False, primary_owned_only: bool = False) -> List[Thing]:
|
|
35
|
-
"""
|
|
36
|
-
Retrieve a collection of things owned by the logged-in user.
|
|
37
|
-
|
|
38
|
-
:param owned_only: Only list things owned by the logged-in user.
|
|
39
|
-
:param primary_owned_only: Only list things primary owned by the logged-in user.
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
return super()._get(params={
|
|
43
|
-
'owned_only': owned_only,
|
|
44
|
-
'primary_owned_only': primary_owned_only,
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
@expand_docstring(include_uid=True)
|
|
48
|
-
def get(self, uid: Union[UUID, str]) -> Thing:
|
|
49
|
-
"""
|
|
50
|
-
Retrieve a thing owned by the logged-in user.
|
|
51
|
-
"""
|
|
52
|
-
|
|
53
|
-
return super()._get(uid)
|
|
54
|
-
|
|
55
|
-
@expand_docstring(model=Thing)
|
|
56
|
-
def create(self, **kwargs) -> Thing:
|
|
57
|
-
"""
|
|
58
|
-
Create a new thing in HydroServer.
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
return super()._post(**kwargs)
|
|
62
|
-
|
|
63
|
-
@expand_docstring(model=Thing, include_uid=True)
|
|
64
|
-
def update(self, uid: Union[UUID, str], **kwargs) -> Thing:
|
|
65
|
-
"""
|
|
66
|
-
Update an existing thing in HydroServer.
|
|
67
|
-
"""
|
|
68
|
-
|
|
69
|
-
return super()._patch(uid=uid, **kwargs)
|
|
70
|
-
|
|
71
|
-
@expand_docstring(include_uid=True)
|
|
72
|
-
def delete(self, uid: Union[UUID, str]) -> None:
|
|
73
|
-
"""
|
|
74
|
-
Delete an existing thing in HydroServer.
|
|
75
|
-
"""
|
|
76
|
-
|
|
77
|
-
super()._delete(uid=uid)
|
|
78
|
-
|
|
79
|
-
def list_datastreams(self, uid: Union[UUID, str]) -> List[Datastream]:
|
|
80
|
-
"""
|
|
81
|
-
List all datastreams associated with a specific thing.
|
|
82
|
-
|
|
83
|
-
:param uid: The unique identifier of the thing.
|
|
84
|
-
:type uid: UUID or str
|
|
85
|
-
:returns: A list of datastream instances.
|
|
86
|
-
:rtype: List[Datastream]
|
|
87
|
-
"""
|
|
88
|
-
|
|
89
|
-
response = getattr(self._service, '_request')(
|
|
90
|
-
'get', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/datastreams'
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
endpoint = DatastreamEndpoint(self._service)
|
|
94
|
-
|
|
95
|
-
return [
|
|
96
|
-
Datastream(_endpoint=endpoint, _uid=UUID(str(entity.pop('id'))), **entity)
|
|
97
|
-
for entity in json.loads(response.content)
|
|
98
|
-
]
|
|
99
|
-
|
|
100
|
-
def list_tags(self, uid: Union[UUID, str]) -> List[Tag]:
|
|
101
|
-
"""
|
|
102
|
-
List all tags associated with a specific thing.
|
|
103
|
-
|
|
104
|
-
:param uid: The unique identifier of the thing.
|
|
105
|
-
:type uid: UUID or str
|
|
106
|
-
:returns: A list of tag instances.
|
|
107
|
-
:rtype: List[Tag]
|
|
108
|
-
"""
|
|
109
|
-
|
|
110
|
-
response = getattr(self._service, '_request')(
|
|
111
|
-
'get', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/tags'
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
return [Tag(_uid=UUID(str(entity.pop('id'))), **entity) for entity in json.loads(response.content)]
|
|
115
|
-
|
|
116
|
-
def create_tag(self, uid: Union[UUID, str], key: str, value: str) -> Tag:
|
|
117
|
-
"""
|
|
118
|
-
Create a new tag for a specific thing.
|
|
119
|
-
|
|
120
|
-
:param uid: The unique identifier of the thing.
|
|
121
|
-
:type uid: UUID or str
|
|
122
|
-
:param key: The key of the tag.
|
|
123
|
-
:type key: str
|
|
124
|
-
:param value: The value of the tag.
|
|
125
|
-
:type value: str
|
|
126
|
-
:returns: The created tag instance.
|
|
127
|
-
:rtype: Tag
|
|
128
|
-
"""
|
|
129
|
-
|
|
130
|
-
response = getattr(self._service, '_request')(
|
|
131
|
-
'post', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/tags',
|
|
132
|
-
headers={'Content-type': 'application/json'},
|
|
133
|
-
data=Tag(key=key, value=value).json(exclude_unset=True, by_alias=True),
|
|
134
|
-
)
|
|
135
|
-
entity = json.loads(response.content)
|
|
136
|
-
|
|
137
|
-
return Tag(_uid=UUID(str(entity.pop('id'))), **entity)
|
|
138
|
-
|
|
139
|
-
def update_tag(self, uid: Union[UUID, str], tag_uid: Union[UUID, str], value: str) -> Tag:
|
|
140
|
-
"""
|
|
141
|
-
Update an existing tag for a specific thing.
|
|
142
|
-
|
|
143
|
-
:param uid: The unique identifier of the thing.
|
|
144
|
-
:type uid: UUID or str
|
|
145
|
-
:param tag_uid: The unique identifier of the tag.
|
|
146
|
-
:type tag_uid: UUID or str
|
|
147
|
-
:param value: The new value for the tag.
|
|
148
|
-
:type value: str
|
|
149
|
-
:returns: The updated tag instance.
|
|
150
|
-
:rtype: Tag
|
|
151
|
-
"""
|
|
152
|
-
|
|
153
|
-
response = getattr(self._service, '_request')(
|
|
154
|
-
'patch', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/tags/{str(tag_uid)}',
|
|
155
|
-
headers={'Content-type': 'application/json'},
|
|
156
|
-
data=json.dumps({'value': str(value)}),
|
|
157
|
-
)
|
|
158
|
-
entity = json.loads(response.content)
|
|
159
|
-
|
|
160
|
-
return Tag(_uid=UUID(str(entity.pop('id'))), **entity)
|
|
161
|
-
|
|
162
|
-
def delete_tag(self, uid: Union[UUID, str], tag_uid: Union[UUID, str]) -> None:
|
|
163
|
-
"""
|
|
164
|
-
Delete a tag from a specific thing.
|
|
165
|
-
|
|
166
|
-
:param uid: The unique identifier of the thing.
|
|
167
|
-
:type uid: UUID or str
|
|
168
|
-
:param tag_uid: The unique identifier of the tag.
|
|
169
|
-
:type tag_uid: UUID or str
|
|
170
|
-
"""
|
|
171
|
-
|
|
172
|
-
getattr(self._service, '_request')(
|
|
173
|
-
'delete', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/tags/{str(tag_uid)}'
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
def list_photos(self, uid: Union[UUID, str]) -> List[Photo]:
|
|
177
|
-
"""
|
|
178
|
-
List all photos associated with a specific thing.
|
|
179
|
-
|
|
180
|
-
:param uid: The unique identifier of the thing.
|
|
181
|
-
:type uid: UUID or str
|
|
182
|
-
:returns: A list of photo instances.
|
|
183
|
-
:rtype: List[Photo]
|
|
184
|
-
"""
|
|
185
|
-
|
|
186
|
-
response = getattr(self._service, '_request')(
|
|
187
|
-
'get', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/photos'
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
return [Photo(_uid=UUID(str(entity.pop('id'))), **entity) for entity in json.loads(response.content)]
|
|
191
|
-
|
|
192
|
-
def upload_photo(self, uid: Union[UUID, str], file: IO) -> List[Photo]:
|
|
193
|
-
"""
|
|
194
|
-
Upload a new photo to a specific thing.
|
|
195
|
-
|
|
196
|
-
:param uid: The unique identifier of the thing.
|
|
197
|
-
:type uid: UUID or str
|
|
198
|
-
:param file: The file-like object representing the photo to upload.
|
|
199
|
-
:type file: IO
|
|
200
|
-
:returns: A list of photo instances created by the upload.
|
|
201
|
-
:rtype: List[Photo]
|
|
202
|
-
"""
|
|
203
|
-
|
|
204
|
-
response = getattr(self._service, '_request')(
|
|
205
|
-
'post', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/photos',
|
|
206
|
-
files={'files': file}
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
return [Photo(_uid=UUID(str(entity.pop('id'))), **entity) for entity in json.loads(response.content)]
|
|
210
|
-
|
|
211
|
-
def delete_photo(self, uid: Union[UUID, str], photo_uid: Union[UUID, str]) -> None:
|
|
212
|
-
"""
|
|
213
|
-
Delete a photo from a specific thing.
|
|
214
|
-
|
|
215
|
-
:param uid: The unique identifier of the thing.
|
|
216
|
-
:type uid: UUID or str
|
|
217
|
-
:param photo_uid: The unique identifier of the photo.
|
|
218
|
-
:type photo_uid: UUID or str
|
|
219
|
-
"""
|
|
220
|
-
|
|
221
|
-
getattr(self._service, '_request')(
|
|
222
|
-
'delete', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/photos/{str(photo_uid)}'
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
def get_archive(self, uid: Union[UUID, str]) -> Archive:
|
|
226
|
-
"""
|
|
227
|
-
Retrieve the archive associated with a specific thing.
|
|
228
|
-
|
|
229
|
-
:param uid: The unique identifier of the thing.
|
|
230
|
-
:type uid: UUID or str
|
|
231
|
-
:returns: The archive instance associated with the thing.
|
|
232
|
-
:rtype: Archive
|
|
233
|
-
"""
|
|
234
|
-
|
|
235
|
-
response = getattr(self._service, '_request')(
|
|
236
|
-
'get', f'{self._api_route}/data/{self._endpoint_route}/{str(uid)}/archive'
|
|
237
|
-
)
|
|
238
|
-
entity = json.loads(response.content)
|
|
239
|
-
|
|
240
|
-
return Archive(_uid=UUID(str(entity.pop('id'))), **entity)
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
from typing import List, Union, TYPE_CHECKING
|
|
2
|
-
from uuid import UUID
|
|
3
|
-
from hydroserverpy.core.endpoints.base import HydroServerEndpoint, expand_docstring
|
|
4
|
-
from hydroserverpy.core.schemas import Unit
|
|
5
|
-
|
|
6
|
-
if TYPE_CHECKING:
|
|
7
|
-
from hydroserverpy.core.service import HydroServer
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class UnitEndpoint(HydroServerEndpoint):
|
|
11
|
-
"""
|
|
12
|
-
An endpoint for interacting with unit entities in the HydroServer service.
|
|
13
|
-
|
|
14
|
-
:ivar _model: The model class associated with this endpoint, set to `Unit`.
|
|
15
|
-
:ivar _api_route: The base route of the API, derived from the service.
|
|
16
|
-
:ivar _endpoint_route: The specific route of the endpoint, set to `'units'`.
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
def __init__(self, service: 'HydroServer'):
|
|
20
|
-
"""
|
|
21
|
-
Initialize the UnitEndpoint.
|
|
22
|
-
|
|
23
|
-
:param service: The HydroServer service instance to use for requests.
|
|
24
|
-
:type service: HydroServer
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
super().__init__(service)
|
|
28
|
-
self._model = Unit
|
|
29
|
-
self._api_route = self._service.api_route
|
|
30
|
-
self._endpoint_route = 'units'
|
|
31
|
-
|
|
32
|
-
def list(
|
|
33
|
-
self,
|
|
34
|
-
include_owned: bool = True,
|
|
35
|
-
include_unowned: bool = True,
|
|
36
|
-
include_templates: bool = True
|
|
37
|
-
) -> List[Unit]:
|
|
38
|
-
"""
|
|
39
|
-
Retrieve a collection of units.
|
|
40
|
-
|
|
41
|
-
:param include_owned: Whether to include owned observed properties.
|
|
42
|
-
:param include_unowned: Whether to include unowned observed properties.
|
|
43
|
-
:param include_templates: Whether to include template observed properties.
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
if include_owned is True and include_unowned is True and include_templates is True:
|
|
47
|
-
owner = 'anyUserOrNoUser'
|
|
48
|
-
elif include_owned is True and include_unowned is True and include_templates is False:
|
|
49
|
-
owner = 'anyUser'
|
|
50
|
-
elif include_owned is True and include_unowned is False and include_templates is True:
|
|
51
|
-
owner = 'currentUserOrNoUser'
|
|
52
|
-
elif include_owned is True and include_unowned is False and include_templates is False:
|
|
53
|
-
owner = 'currentUser'
|
|
54
|
-
elif include_owned is False and include_unowned is False and include_templates is True:
|
|
55
|
-
owner = 'noUser'
|
|
56
|
-
else:
|
|
57
|
-
return []
|
|
58
|
-
|
|
59
|
-
return super()._get(params={
|
|
60
|
-
'owner': owner
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
@expand_docstring(include_uid=True)
|
|
64
|
-
def get(self, uid: Union[UUID, str]) -> Unit:
|
|
65
|
-
"""
|
|
66
|
-
Retrieve a unit owned by the logged-in user.
|
|
67
|
-
"""
|
|
68
|
-
|
|
69
|
-
return super()._get(uid)
|
|
70
|
-
|
|
71
|
-
@expand_docstring(model=Unit)
|
|
72
|
-
def create(self, **kwargs) -> Unit:
|
|
73
|
-
"""
|
|
74
|
-
Create a new unit in HydroServer.
|
|
75
|
-
"""
|
|
76
|
-
|
|
77
|
-
return super()._post(**kwargs)
|
|
78
|
-
|
|
79
|
-
@expand_docstring(model=Unit, include_uid=True)
|
|
80
|
-
def update(self, uid: Union[UUID, str], **kwargs) -> Unit:
|
|
81
|
-
"""
|
|
82
|
-
Update an existing unit in HydroServer.
|
|
83
|
-
"""
|
|
84
|
-
|
|
85
|
-
return super()._patch(uid=uid, **kwargs)
|
|
86
|
-
|
|
87
|
-
@expand_docstring(include_uid=True)
|
|
88
|
-
def delete(self, uid: Union[UUID, str]) -> None:
|
|
89
|
-
"""
|
|
90
|
-
Delete an existing unit in HydroServer.
|
|
91
|
-
"""
|
|
92
|
-
|
|
93
|
-
super()._delete(uid=uid)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
from .data_loaders import DataLoader
|
|
2
|
-
from .data_sources import DataSource
|
|
3
|
-
from .datastreams import Datastream
|
|
4
|
-
from .observed_properties import ObservedProperty
|
|
5
|
-
from .processing_levels import ProcessingLevel
|
|
6
|
-
from .result_qualifiers import ResultQualifier
|
|
7
|
-
from .sensors import Sensor
|
|
8
|
-
from .things import Thing, Tag, Photo, Archive
|
|
9
|
-
from .units import Unit
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
from pydantic import BaseModel, PrivateAttr, AliasGenerator, AliasChoices, computed_field
|
|
2
|
-
from pydantic.alias_generators import to_camel
|
|
3
|
-
from uuid import UUID
|
|
4
|
-
from typing import Optional
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
base_alias_generator = AliasGenerator(
|
|
8
|
-
serialization_alias=lambda field_name: to_camel(field_name),
|
|
9
|
-
validation_alias=lambda field_name: AliasChoices(to_camel(field_name), field_name),
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class HydroServerBaseModel(BaseModel):
|
|
14
|
-
"""
|
|
15
|
-
A base model for HydroServer entities that provides common attributes and functionality for HydroServer data.
|
|
16
|
-
|
|
17
|
-
:ivar _uid: A private attribute for storing the unique identifier (UUID) of the model.
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
_uid: Optional[UUID] = PrivateAttr()
|
|
21
|
-
|
|
22
|
-
def __init__(self, _uid: Optional[UUID] = None, **data):
|
|
23
|
-
"""
|
|
24
|
-
Initialize a HydroServerBaseModel instance.
|
|
25
|
-
|
|
26
|
-
:param _uid: The unique identifier for the model.
|
|
27
|
-
:type _uid: Optional[UUID]
|
|
28
|
-
:param data: Additional attributes for the model.
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
super().__init__(**data)
|
|
32
|
-
self._uid = _uid
|
|
33
|
-
|
|
34
|
-
@computed_field
|
|
35
|
-
@property
|
|
36
|
-
def uid(self) -> Optional[UUID]:
|
|
37
|
-
"""
|
|
38
|
-
The unique identifier (UUID) of the model.
|
|
39
|
-
|
|
40
|
-
:return: The UUID of the model.
|
|
41
|
-
:rtype: Optional[UUID]
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
return self._uid
|
|
45
|
-
|
|
46
|
-
class Config:
|
|
47
|
-
alias_generator = base_alias_generator
|
|
48
|
-
validate_assignment = True
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class HydroServerCoreModel(HydroServerBaseModel):
|
|
52
|
-
"""
|
|
53
|
-
A core model for HydroServer entities that includes methods for data manipulation and persistence.
|
|
54
|
-
|
|
55
|
-
:ivar _original_data: A private attribute storing the original data used to initialize the model.
|
|
56
|
-
"""
|
|
57
|
-
|
|
58
|
-
_original_data: Optional[dict] = PrivateAttr()
|
|
59
|
-
|
|
60
|
-
def __init__(self, _endpoint, _uid: Optional[UUID] = None, **data):
|
|
61
|
-
"""
|
|
62
|
-
Initialize a HydroServerCoreModel instance.
|
|
63
|
-
|
|
64
|
-
:param _endpoint: The endpoint associated with the model.
|
|
65
|
-
:param _uid: The unique identifier for the model.
|
|
66
|
-
:type _uid: Optional[UUID]
|
|
67
|
-
:param data: Additional attributes for the model.
|
|
68
|
-
"""
|
|
69
|
-
|
|
70
|
-
super().__init__(_uid=_uid, **data)
|
|
71
|
-
self._endpoint = _endpoint
|
|
72
|
-
self._original_data = self.dict(by_alias=False).copy()
|
|
73
|
-
|
|
74
|
-
@property
|
|
75
|
-
def _patch_data(self) -> dict:
|
|
76
|
-
"""
|
|
77
|
-
Generate a dictionary of modified data that needs to be patched on the server.
|
|
78
|
-
|
|
79
|
-
:return: A dictionary of modified attributes.
|
|
80
|
-
:rtype: dict
|
|
81
|
-
"""
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
key: getattr(self, key) for key, value in self._original_data.items()
|
|
85
|
-
if hasattr(self, key) and getattr(self, key) != value
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
def refresh(self) -> None:
|
|
89
|
-
"""
|
|
90
|
-
Refresh the model with the latest data from the server.
|
|
91
|
-
"""
|
|
92
|
-
|
|
93
|
-
entity = self._endpoint.get(uid=self.uid).model_dump(exclude=['uid'])
|
|
94
|
-
self._original_data = entity.dict(by_alias=False, exclude=['uid'])
|
|
95
|
-
self.__dict__.update(self._original_data)
|
|
96
|
-
|
|
97
|
-
def save(self) -> None:
|
|
98
|
-
"""
|
|
99
|
-
Save the current state of the model to the server by updating modified attributes.
|
|
100
|
-
"""
|
|
101
|
-
|
|
102
|
-
if self._patch_data:
|
|
103
|
-
entity = self._endpoint.update(uid=self.uid, **self._patch_data)
|
|
104
|
-
self._original_data = entity.dict(by_alias=False, exclude=['uid'])
|
|
105
|
-
self.__dict__.update(self._original_data)
|
|
106
|
-
|
|
107
|
-
def delete(self) -> None:
|
|
108
|
-
"""
|
|
109
|
-
Delete the model from the server.
|
|
110
|
-
|
|
111
|
-
:raises AttributeError: If the model's UID is not set.
|
|
112
|
-
"""
|
|
113
|
-
|
|
114
|
-
if not self._uid:
|
|
115
|
-
raise AttributeError('This resource cannot be deleted: UID is not set.')
|
|
116
|
-
self._endpoint.delete(uid=self._uid)
|
|
117
|
-
self._uid = None
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
from pydantic import BaseModel, Field
|
|
2
|
-
from typing import Optional, List, TYPE_CHECKING
|
|
3
|
-
from uuid import UUID
|
|
4
|
-
from hydroserverpy.core.schemas.base import HydroServerCoreModel
|
|
5
|
-
|
|
6
|
-
if TYPE_CHECKING:
|
|
7
|
-
from hydroserverpy.core.schemas.data_sources import DataSource
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class DataLoaderFields(BaseModel):
|
|
11
|
-
name: str = Field(
|
|
12
|
-
..., strip_whitespace=True, max_length=255,
|
|
13
|
-
description='The name of the data loader.'
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class DataLoader(HydroServerCoreModel, DataLoaderFields):
|
|
18
|
-
"""
|
|
19
|
-
A model representing a DataLoader, extending the core functionality of HydroServerCoreModel with additional
|
|
20
|
-
properties and methods.
|
|
21
|
-
|
|
22
|
-
:ivar _data_sources: A private attribute to cache the list of data sources associated with the DataLoader.
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
def __init__(self, _endpoint, _uid: Optional[UUID] = None, **data):
|
|
26
|
-
"""
|
|
27
|
-
Initialize a DataLoader instance.
|
|
28
|
-
|
|
29
|
-
:param _endpoint: The endpoint associated with the data loader.
|
|
30
|
-
:type _endpoint: str
|
|
31
|
-
:param _uid: The unique identifier for the data loader.
|
|
32
|
-
:type _uid: Optional[UUID]
|
|
33
|
-
:param data: Additional attributes for the data loader.
|
|
34
|
-
"""
|
|
35
|
-
|
|
36
|
-
super().__init__(_endpoint=_endpoint, _uid=_uid, **data)
|
|
37
|
-
self._data_sources = None
|
|
38
|
-
|
|
39
|
-
@property
|
|
40
|
-
def data_sources(self) -> List['DataSource']:
|
|
41
|
-
"""
|
|
42
|
-
The data sources associated with the data loader. If not already cached, fetch the data sources from the server.
|
|
43
|
-
|
|
44
|
-
:return: A list of data sources associated with the data loader.
|
|
45
|
-
:rtype: List[DataSource]
|
|
46
|
-
"""
|
|
47
|
-
|
|
48
|
-
if self._data_sources is None:
|
|
49
|
-
self._data_sources = self._endpoint.list_data_sources(uid=self.uid)
|
|
50
|
-
|
|
51
|
-
return self._data_sources
|
|
52
|
-
|
|
53
|
-
def refresh(self) -> None:
|
|
54
|
-
"""
|
|
55
|
-
Refresh the data loader with the latest data from the server and update cached data sources.
|
|
56
|
-
"""
|
|
57
|
-
|
|
58
|
-
entity = self._endpoint.get(uid=self.uid).model_dump(exclude=['uid'])
|
|
59
|
-
self._original_data = entity
|
|
60
|
-
self.__dict__.update(entity)
|
|
61
|
-
if self._data_sources is not None:
|
|
62
|
-
self._data_sources = self._endpoint.list_data_sources(uid=self.uid)
|
|
63
|
-
|
|
64
|
-
def load_observations(self) -> None:
|
|
65
|
-
"""
|
|
66
|
-
Load observations data from a local file or a remote URL into HydroServer using all data sources associated with
|
|
67
|
-
this data loader.
|
|
68
|
-
"""
|
|
69
|
-
|
|
70
|
-
for data_source in self.data_sources:
|
|
71
|
-
data_source.load_observations()
|