Skip to content

Commit 3656e0c

Browse files
committed
Add JSON Transformer example
1 parent 22d4439 commit 3656e0c

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

apps/docs/docs/how-to/hydroserverpy/hydroserverpy-examples.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,8 @@ data_connection = hs_api.dataconnections.get(uid='00000000-0000-0000-0000-000000
10491049

10501050
#### Example: Create Data Connection
10511051

1052-
```python
1053-
# Create a new data connection in HydroServer
1052+
```python
1053+
# Create a new data connection in HydroServer
10541054
new_data_connection = hs_api.dataconnections.create(
10551055
name='Example Data Connection',
10561056
data_connection_type='ETL',
@@ -1079,8 +1079,69 @@ new_data_connection = hs_api.dataconnections.create(
10791079
)
10801080
```
10811081

1082+
#### Example: Create Data Connection with JSON Transformer
1083+
1084+
```python
1085+
# Create a new HTTP + JSON data connection in HydroServer
1086+
new_json_data_connection = hs_api.dataconnections.create(
1087+
name='USGS Instantaneous Values',
1088+
data_connection_type='ETL',
1089+
workspace='00000000-0000-0000-0000-000000000000',
1090+
extractor_type='HTTP',
1091+
extractor_settings={
1092+
'sourceUri': (
1093+
'https://waterservices.usgs.gov/nwis/iv/'
1094+
'?format=json'
1095+
'&sites={site_code}'
1096+
'&parameterCd={param_code}'
1097+
'&startDT={start_date}'
1098+
'&endDT={end_date}'
1099+
),
1100+
'placeholderVariables': [
1101+
{'name': 'site_code', 'type': 'perTask'},
1102+
{'name': 'param_code', 'type': 'perTask'},
1103+
{
1104+
'name': 'start_date',
1105+
'type': 'runTime',
1106+
'runTimeValue': 'latestObservationTimestamp',
1107+
'timestamp': {
1108+
'format': 'ISO8601',
1109+
'timezoneMode': 'daylightSavings',
1110+
'timezone': 'America/Denver',
1111+
},
1112+
},
1113+
{
1114+
'name': 'end_date',
1115+
'type': 'runTime',
1116+
'runTimeValue': 'jobExecutionTime',
1117+
'timestamp': {
1118+
'format': 'ISO8601',
1119+
'timezoneMode': 'daylightSavings',
1120+
'timezone': 'America/Denver',
1121+
},
1122+
},
1123+
],
1124+
},
1125+
transformer_type='JSON',
1126+
transformer_settings={
1127+
'JMESPath': 'value.timeSeries[].values[].value[]',
1128+
'timestamp': {
1129+
'key': 'dateTime',
1130+
'format': 'ISO8601',
1131+
'timezoneMode': 'embeddedOffset',
1132+
},
1133+
},
1134+
loader_type='HydroServer',
1135+
loader_settings={}
1136+
)
1137+
```
1138+
10821139
`extractor_settings`, `transformer_settings`, and `loader_settings` should use the same nested JSON shape used by the Data Management app and TypeScript client. For example, HTTP extractors use `sourceUri` and `placeholderVariables` in camelCase.
10831140

1141+
The USGS Instantaneous Values service accepts ISO-8601 datetimes and assumes site-local time when no offset is provided. This example uses a daylight-savings aware local timezone (`America/Denver`). If your sites are in a different timezone, replace that value with the appropriate IANA timezone for your tasks.
1142+
1143+
The JSON transformer timestamp configuration also stays on `ISO8601` with `timezoneMode: 'embeddedOffset'` because USGS response `dateTime` values include their timezone offset. In HydroServer, ISO timestamps with embedded offsets are parsed directly; fixed-offset or daylight-savings transformer timezone settings are for sources whose timestamps do not already include timezone information.
1144+
10841145
Each of the methods above will return one or more DataConnection objects. The examples below show the main properties and methods available to a DataConnection object.
10851146

10861147
#### Example: Modify a Data Connection

0 commit comments

Comments
 (0)