Skip to content

Commit 2905ea4

Browse files
committed
Rating curves to be on Thing
1 parent 6a6b4e4 commit 2905ea4

File tree

3 files changed

+5
-165
lines changed

3 files changed

+5
-165
lines changed

src/hydroserverpy/api/models/iam/workspace.py

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Union, Optional, ClassVar, TYPE_CHECKING, IO, Dict, Any
1+
from typing import List, Union, Optional, ClassVar, TYPE_CHECKING
22
from uuid import UUID
33
from datetime import datetime
44
from pydantic import Field, EmailStr, AliasPath
@@ -52,7 +52,6 @@ def __init__(self, client: "HydroServer", **data):
5252
self._orchestrationsystems = None
5353
self._dataconnections = None
5454
self._tasks = None
55-
self._file_attachments = None
5655

5756
@classmethod
5857
def get_route(cls):
@@ -184,17 +183,6 @@ def tasks(self) -> List["Task"]:
184183

185184
return self._tasks
186185

187-
@property
188-
def file_attachments(self) -> List[Dict[str, Any]]:
189-
"""Workspace-level file attachments."""
190-
191-
if self._file_attachments is None:
192-
self._file_attachments = self.client.workspaces.list_file_attachments(
193-
uid=self.uid
194-
)
195-
196-
return self._file_attachments
197-
198186
def create_api_key(
199187
self,
200188
role: Union["Role", UUID, str],
@@ -290,62 +278,6 @@ def remove_collaborator(self, email: EmailStr) -> None:
290278
self.client.workspaces.remove_collaborator(uid=self.uid, email=email)
291279
self._collaborators = None
292280

293-
def get_file_attachments(
294-
self, attachment_type: Optional[str] = None
295-
) -> List[Dict[str, Any]]:
296-
"""List file attachments associated with this workspace."""
297-
298-
self._file_attachments = self.client.workspaces.list_file_attachments(
299-
uid=self.uid, attachment_type=attachment_type
300-
)
301-
return self._file_attachments
302-
303-
def add_file_attachment(
304-
self,
305-
file: IO[bytes],
306-
attachment_type: str,
307-
name: Optional[str] = None,
308-
description: Optional[str] = None,
309-
) -> Dict[str, Any]:
310-
"""Add a workspace file attachment."""
311-
312-
response = self.client.workspaces.add_file_attachment(
313-
uid=self.uid,
314-
file=file,
315-
attachment_type=attachment_type,
316-
name=name,
317-
description=description,
318-
)
319-
self._file_attachments = None
320-
return response
321-
322-
def update_file_attachment(
323-
self,
324-
file_attachment_id: Union[UUID, str],
325-
attachment_type: str = ...,
326-
name: str = ...,
327-
description: Optional[str] = ...,
328-
) -> Dict[str, Any]:
329-
"""Update metadata for a workspace file attachment."""
330-
331-
response = self.client.workspaces.update_file_attachment(
332-
uid=self.uid,
333-
file_attachment_id=file_attachment_id,
334-
attachment_type=attachment_type,
335-
name=name,
336-
description=description,
337-
)
338-
self._file_attachments = None
339-
return response
340-
341-
def delete_file_attachment(self, file_attachment_id: Union[UUID, str]) -> None:
342-
"""Delete a workspace file attachment."""
343-
344-
self.client.workspaces.delete_file_attachment(
345-
uid=self.uid, file_attachment_id=file_attachment_id
346-
)
347-
self._file_attachments = None
348-
349281
def transfer_ownership(self, email: EmailStr) -> None:
350282
"""Transfer ownership of this workspace to another HydroServer user."""
351283

src/hydroserverpy/api/services/iam/workspace.py

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import TYPE_CHECKING, Union, List, Tuple, Optional, IO, Dict, Any
2+
from typing import TYPE_CHECKING, Optional, Union, List, Tuple
33
from pydantic import EmailStr
44
from uuid import UUID
55
from datetime import datetime
@@ -160,98 +160,6 @@ def create_api_key(
160160
client=self.client, **response
161161
), response["key"]
162162

163-
@staticmethod
164-
def _normalize_file_attachment(payload: dict) -> Dict[str, Any]:
165-
return {
166-
"id": payload.get("id"),
167-
"type": payload.get("type"),
168-
"name": payload.get("name"),
169-
"description": payload.get("description", ""),
170-
"content_type": payload.get("contentType")
171-
or payload.get("content_type")
172-
or "",
173-
"size_bytes": payload.get("sizeBytes") or payload.get("size_bytes") or 0,
174-
"link": payload.get("link"),
175-
"created_at": payload.get("createdAt") or payload.get("created_at"),
176-
"updated_at": payload.get("updatedAt") or payload.get("updated_at"),
177-
}
178-
179-
def list_file_attachments(
180-
self, uid: Union[UUID, str], attachment_type: Optional[str] = None
181-
) -> List[Dict[str, Any]]:
182-
"""List file attachments associated with a workspace."""
183-
184-
path = f"/{self.client.base_route}/{self.model.get_route()}/{str(uid)}/file-attachments"
185-
params = {"type": attachment_type} if attachment_type else None
186-
response = self.client.request("get", path, params=params).json()
187-
if not isinstance(response, list):
188-
return []
189-
return [
190-
self._normalize_file_attachment(item)
191-
for item in response
192-
if isinstance(item, dict)
193-
]
194-
195-
def add_file_attachment(
196-
self,
197-
uid: Union[UUID, str],
198-
file: IO[bytes],
199-
attachment_type: str,
200-
name: Optional[str] = None,
201-
description: Optional[str] = None,
202-
) -> Dict[str, Any]:
203-
"""Add a file attachment to a workspace."""
204-
205-
path = f"/{self.client.base_route}/{self.model.get_route()}/{str(uid)}/file-attachments"
206-
data = {"type": attachment_type}
207-
if name is not None:
208-
data["name"] = name
209-
if description is not None:
210-
data["description"] = description
211-
212-
response = self.client.request("post", path, data=data, files={"file": file}).json()
213-
return self._normalize_file_attachment(response)
214-
215-
def update_file_attachment(
216-
self,
217-
uid: Union[UUID, str],
218-
file_attachment_id: Union[UUID, str],
219-
attachment_type: str = ...,
220-
name: str = ...,
221-
description: Optional[str] = ...,
222-
) -> Dict[str, Any]:
223-
"""Update workspace file attachment metadata."""
224-
225-
path = (
226-
f"/{self.client.base_route}/{self.model.get_route()}/"
227-
f"{str(uid)}/file-attachments/{str(file_attachment_id)}"
228-
)
229-
body = {
230-
"type": attachment_type,
231-
"name": name,
232-
"description": description,
233-
}
234-
body = {k: v for k, v in body.items() if v is not ...}
235-
headers = {"Content-type": "application/json"}
236-
response = self.client.request(
237-
"patch",
238-
path,
239-
headers=headers,
240-
data=json.dumps(body, default=self.default_serializer),
241-
).json()
242-
return self._normalize_file_attachment(response)
243-
244-
def delete_file_attachment(
245-
self, uid: Union[UUID, str], file_attachment_id: Union[UUID, str]
246-
) -> None:
247-
"""Delete a file attachment from a workspace."""
248-
249-
path = (
250-
f"/{self.client.base_route}/{self.model.get_route()}/"
251-
f"{str(uid)}/file-attachments/{str(file_attachment_id)}"
252-
)
253-
self.client.request("delete", path)
254-
255163
def update_api_key(
256164
self,
257165
uid: Union[UUID, str],

src/hydroserverpy/etl/transformers/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def needs_datastreams(self) -> bool:
202202
def apply_rating_curve(
203203
values: Union[pd.Series, np.ndarray, List[float]], rating_curve_url: str
204204
) -> pd.Series:
205-
"""Apply a rating curve to numeric values using linear interpolation."""
205+
"""Apply a rating curve using linear interpolation with endpoint clamping."""
206206

207207
source = (
208208
values
@@ -221,8 +221,8 @@ def apply_rating_curve(
221221
source_values[finite_mask],
222222
lookup_input,
223223
lookup_output,
224-
left=np.nan,
225-
right=np.nan,
224+
left=lookup_output[0],
225+
right=lookup_output[-1],
226226
)
227227

228228
return pd.Series(transformed, index=source.index, dtype="float64")

0 commit comments

Comments
 (0)