Skip to content

Commit 50985f7

Browse files
author
Novotny
committed
added clobs, blobs, location_groups, timeseries_groups
1 parent 93534d2 commit 50985f7

File tree

14 files changed

+724
-236
lines changed

14 files changed

+724
-236
lines changed

cwms/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from importlib.metadata import PackageNotFoundError, version
22

33
from cwms.api import *
4+
from cwms.catalog.blobs import *
45
from cwms.catalog.catalog import *
6+
from cwms.catalog.clobs import *
57
from cwms.datafile_imports.shef_critfile_import import *
68
from cwms.forecast.forecast_instance import *
79
from cwms.forecast.forecast_spec import *
810
from cwms.levels.location_levels import *
911
from cwms.levels.specified_levels import *
1012
from cwms.locations.gate_changes import *
13+
from cwms.locations.location_groups import *
1114
from cwms.locations.physical_locations import *
1215
from cwms.outlets.outlets import *
1316
from cwms.outlets.virtual_outlets import *
@@ -21,6 +24,7 @@
2124
from cwms.timeseries.timerseries_identifier import *
2225
from cwms.timeseries.timeseries import *
2326
from cwms.timeseries.timeseries_bin import *
27+
from cwms.timeseries.timeseries_group import *
2428
from cwms.timeseries.timeseries_profile import *
2529
from cwms.timeseries.timeseries_profile_instance import *
2630
from cwms.timeseries.timeseries_profile_parser import *

cwms/catalog/blobs.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from typing import Optional
2+
3+
import cwms.api as api
4+
from cwms.cwms_types import JSON, Data
5+
6+
7+
def get_blob(blob_id: str, office_id: str) -> Data:
8+
"""Get a single clob.
9+
10+
Parameters
11+
----------
12+
blob_id: string
13+
Specifies the id of the blob
14+
office_id: string
15+
Specifies the office of the blob.
16+
17+
18+
Returns
19+
-------
20+
cwms data type. data.json will return the JSON output and data.df will return a dataframe
21+
"""
22+
23+
endpoint = f"blobs/{blob_id}"
24+
params = {"office": office_id}
25+
response = api.get(endpoint, params, api_version=1)
26+
return Data(response)
27+
28+
29+
def get_blobs(
30+
office_id: Optional[str] = None,
31+
page_size: Optional[int] = 100,
32+
blob_id_like: Optional[str] = None,
33+
) -> Data:
34+
"""Get a subset of Blobs
35+
36+
Parameters
37+
----------
38+
office_id: Optional[string]
39+
Specifies the office of the blob.
40+
page_sie: Optional[Integer]
41+
How many entries per page returned. Default 100.
42+
blob_id_like: Optional[string]
43+
Posix regular expression matching against the clob id
44+
45+
Returns
46+
-------
47+
cwms data type. data.json will return the JSON output and data.df will return a dataframe
48+
"""
49+
50+
endpoint = "clobs"
51+
params = {"office": office_id, "page-size": page_size, "like": blob_id_like}
52+
53+
response = api.get(endpoint, params, api_version=1)
54+
return Data(response, selector="blobs")
55+
56+
57+
def store_blobs(data: JSON, fail_if_exists: Optional[bool] = True) -> None:
58+
"""Create New Blob
59+
60+
Parameters
61+
----------
62+
Data: JSON dictionary
63+
JSON containing information of Blob to be updated
64+
{
65+
"office-id": "string",
66+
"id": "string",
67+
"description": "string",
68+
"media-type-id": "string",
69+
"value": "string"
70+
}
71+
fail_if_exists: Boolean
72+
Create will fail if provided ID already exists. Default: true
73+
74+
Returns
75+
-------
76+
None
77+
"""
78+
79+
if not isinstance(data, dict):
80+
raise ValueError("Cannot store a Blob without a JSON data dictionary")
81+
82+
endpoint = f"blobs"
83+
params = {"fail-if-exists": fail_if_exists}
84+
85+
return api.post(endpoint, data, params, api_version=1)

cwms/catalog/clobs.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
from typing import Optional
2+
3+
import cwms.api as api
4+
from cwms.cwms_types import JSON, Data
5+
6+
7+
def get_clob(clob_id: str, office_id: str, clob_id_query: Optional[str] = None) -> Data:
8+
"""Get a single clob.
9+
10+
Parameters
11+
----------
12+
clob_id: string
13+
Specifies the id of the clob
14+
office_id: string
15+
Specifies the office of the clob.
16+
clob_id_query: string
17+
If this query parameter is provided the id path parameter is ignored and the
18+
value of the query parameter is used. Note: this query parameter is necessary
19+
for id's that contain '/' or other special characters. Because of abuse even
20+
properly escaped '/' in url paths are blocked. When using this query parameter
21+
a valid path parameter must still be provided for the request to be properly
22+
routed. If your clob id contains '/' you can't specify the clob-id query
23+
parameter and also specify the id path parameter because firewall and/or server
24+
rules will deny the request even though you are specifying this override. "ignored"
25+
is suggested.
26+
27+
28+
Returns
29+
-------
30+
cwms data type. data.json will return the JSON output and data.df will return a dataframe
31+
"""
32+
33+
endpoint = f"clobs/{clob_id}"
34+
params = {
35+
"office": office_id,
36+
"clob-id-query": clob_id_query,
37+
}
38+
response = api.get(endpoint, params)
39+
return Data(response)
40+
41+
42+
def get_clobs(
43+
office_id: Optional[str] = None,
44+
page_size: Optional[int] = 100,
45+
include_values: Optional[bool] = False,
46+
clob_id_like: Optional[str] = None,
47+
) -> Data:
48+
"""Get a subset of Clobs
49+
50+
Parameters
51+
----------
52+
office_id: Optional[string]
53+
Specifies the office of the clob.
54+
page_sie: Optional[Integer]
55+
How many entries per page returned. Default 100.
56+
include_values: Optional[Boolean]
57+
Do you want the value associated with this particular clob (default: false)
58+
clob_id_like: Optional[string]
59+
Posix regular expression matching against the clob id
60+
61+
Returns
62+
-------
63+
cwms data type. data.json will return the JSON output and data.df will return a dataframe
64+
"""
65+
66+
endpoint = "clobs"
67+
params = {
68+
"office": office_id,
69+
"page-size": page_size,
70+
"include-values": include_values,
71+
"like": clob_id_like,
72+
}
73+
74+
response = api.get(endpoint, params)
75+
return Data(response, selector="clobs")
76+
77+
78+
def delete_clob(clob_id: str, office_id: str) -> None:
79+
"""Deletes requested clob
80+
81+
Parameters
82+
----------
83+
clob_id: string
84+
Specifies the id of the clob to be deleted
85+
office_id: string
86+
Specifies the office of the clob.
87+
88+
Returns
89+
-------
90+
None
91+
"""
92+
93+
endpoint = f"clobs/{clob_id}"
94+
params = {"office": office_id}
95+
96+
return api.delete(endpoint, params=params, api_version=1)
97+
98+
99+
def update_clob(data: JSON, clob_id: str, ignore_nulls: Optional[bool] = True) -> None:
100+
"""Updates clob
101+
102+
Parameters
103+
----------
104+
Data: JSON dictionary
105+
JSON containing information of Clob to be updated
106+
{
107+
"office-id": "string",
108+
"id": "string",
109+
"description": "string",
110+
"value": "string"
111+
}
112+
clob_id: string
113+
Specifies the id of the clob to be deleted
114+
ignore_nulls: Boolean
115+
If true, null and empty fields in the provided clob will be ignored and the existing value of those fields left in place. Default: true
116+
117+
Returns
118+
-------
119+
None
120+
"""
121+
122+
if not isinstance(data, dict):
123+
raise ValueError("Cannot store a Clob without a JSON data dictionary")
124+
125+
endpoint = f"clobs/{clob_id}"
126+
params = {"ignore-nulls": ignore_nulls}
127+
128+
return api.patch(endpoint, data, params, api_version=1)
129+
130+
131+
def store_clobs(data: JSON, fail_if_exists: Optional[bool] = True) -> None:
132+
"""Create New Clob
133+
134+
Parameters
135+
----------
136+
Data: JSON dictionary
137+
JSON containing information of Clob to be updated
138+
{
139+
"office-id": "string",
140+
"id": "string",
141+
"description": "string",
142+
"value": "string"
143+
}
144+
fail_if_exists: Boolean
145+
Create will fail if provided ID already exists. Default: true
146+
147+
Returns
148+
-------
149+
None
150+
"""
151+
152+
if not isinstance(data, dict):
153+
raise ValueError("Cannot store a Clob without a JSON data dictionary")
154+
155+
endpoint = f"clobs"
156+
params = {"fail-if-exists": fail_if_exists}
157+
158+
return api.post(endpoint, data, params, api_version=1)

cwms/datafile_imports/shef_critfile_import.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
import pandas as pd
55

6-
from cwms.timeseries.timeseries import (
7-
timeseries_group_df_to_json,
8-
update_timeseries_groups,
9-
)
6+
import cwms
107

118

129
def import_critfile_to_ts_group(
@@ -15,6 +12,7 @@ def import_critfile_to_ts_group(
1512
group_id: str = "SHEF Data Acquisition",
1613
category_id: str = "Data Acquisition",
1714
group_office_id: str = "CWMS",
15+
category_office_id: str = "CWMS",
1816
replace_assigned_ts: bool = False,
1917
) -> None:
2018
"""
@@ -116,9 +114,15 @@ def append_df(
116114
df = append_df(df, office_id, data["Timeseries ID"], data["Alias"])
117115

118116
# Generate JSON dictionary
119-
json_dict = timeseries_group_df_to_json(df, group_id, group_office_id, category_id)
117+
json_dict = cwms.timeseries_group_df_to_json(
118+
data=df,
119+
group_id=group_id,
120+
group_office_id=group_office_id,
121+
category_office_id=category_office_id,
122+
category_id=category_id,
123+
)
120124

121-
update_timeseries_groups(
125+
cwms.update_timeseries_groups(
122126
group_id=group_id,
123127
office_id=office_id,
124128
replace_assigned_ts=replace_assigned_ts,

0 commit comments

Comments
 (0)