Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ print(json)
['2024-04-23T10:00:00', 86.57999999999997, 3]],
'version-date': None}
```

## TimeSeries Profile API Compatibility Warning

Currently, the TimeSeries Profile API may not be fully supported
until a new version of cwms-data-access is released with the updated
endpoint implementation.
3 changes: 3 additions & 0 deletions cwms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from cwms.timeseries.timerseries_identifier import *
from cwms.timeseries.timeseries import *
from cwms.timeseries.timeseries_bin import *
from cwms.timeseries.timeseries_profile import *
from cwms.timeseries.timeseries_profile_instance import *
from cwms.timeseries.timeseries_profile_parser import *
from cwms.timeseries.timeseries_txt import *

try:
Expand Down
166 changes: 166 additions & 0 deletions cwms/timeseries/timeseries_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Copyright (c) 2024
# United States Army Corps of Engineers - Hydrologic Engineering Center (USACE/HEC)
# All Rights Reserved. USACE PROPRIETARY/CONFIDENTIAL.
# Source may not be released without written approval from HEC

from typing import Optional

import cwms.api as api
from cwms.cwms_types import Data


def get_timeseries_profile(office_id: str, location_id: str, parameter_id: str) -> Data:
"""
Retrieves a timeseries profile.

Compatibility Warning:
Currently, the TimeSeries Profile API may not be fully supported
until a new version of cwms-data-access is released with the updated
endpoint implementation.

Parameters
----------
office_id: string
The owning office of the timeseries profile
location_id: string
The location associated with the timeseries profile parser
parameter_id: string
Name of the key parameter associated with the timeseries profile

Returns
-------
cwms data type
"""

endpoint = f"timeseries/profile/{location_id}/{parameter_id}"
params = {
"office": office_id,
}

response = api.get(endpoint, params)
return Data(response)


def get_timeseries_profiles(
office_mask: Optional[str],
location_mask: Optional[str],
parameter_id_mask: Optional[str],
page: Optional[str] = None,
page_size: Optional[int] = 1000,
) -> Data:
"""
Retrieves all timeseries profiles that fit the provided masks. Does not include time series values.

Compatibility Warning:
Currently, the TimeSeries Profile API may not be fully supported
until a new version of cwms-data-access is released with the updated
endpoint implementation.

Parameters
----------
office_mask: string
A mask to limit the results based on office. Uses regex to compare with office IDs in the database.
Default value is '*'
location_mask: string
A mask to limit the results based on location. Uses regex to compare with location IDs in the database.
Default value is '*'
parameter_id_mask: string
A mask to limit the results based on the parameter associated with the timeseries profile. Uses regex to
compare the parameter IDs in the database. Default value is '*'

Returns
-------
cwms data type
"""

endpoint = "timeseries/profile"
params = {
"office-mask": office_mask,
"location-mask": location_mask,
"parameter-id-mask": parameter_id_mask,
"page": page,
"page-size": page_size,
}

response = api.get(endpoint, params)
return Data(response)


def delete_timeseries_profile(
office_id: str, parameter_id: str, location_id: str
) -> None:
"""
Deletes a specified timeseries profile

Compatibility Warning:
Currently, the TimeSeries Profile API may not be fully supported
until a new version of cwms-data-access is released with the updated
endpoint implementation.

Parameters
----------
office_id: string
The owning office of the timeseries profile
parameter_id: string
Name of the key parameter associated with the timeseries profile
location_id: string
The location associated with the timeseries profile

Returns
-------
None
"""

endpoint = f"timeseries/profile/{location_id}/{parameter_id}"
params = {
"office": office_id,
}

return api.delete(endpoint, params)


def store_timeseries_profile(data: str, fail_if_exists: Optional[bool] = True) -> None:
"""
Stores a new timeseries profile

Compatibility Warning:
Currently, the TimeSeries Profile API may not be fully supported
until a new version of cwms-data-access is released with the updated
endpoint implementation.

Parameters
----------
data: string
json for storing a timeseries profile
{
"description": "string",
"parameter-list": [
"string",
...
],
"location-id": {
"office-id": "string",
"name": "string"
},
"reference-ts-id": {
"office-id": "string",
"name": "string"
},
"key-parameter": "string"
}

fail_if_exists: boolean, optional
Throw a ClientError if the profile already exists
Default is `True`

Returns
-------
None
"""

endpoint = "timeseries/profile"
params = {
"fail-if-exists": fail_if_exists,
}

return api.post(endpoint, data, params)
Loading
Loading