Skip to content

Commit 3ffd9ea

Browse files
update examples in tutorials
1 parent bfb9efd commit 3ffd9ea

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

docs/source/index.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
.. conSys4Py documentation master file, created by
2-
sphinx-quickstart on Tue Jul 9 21:22:00 2024.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
51

6-
Welcome to conSys4Py's documentation!
2+
ConSys4Py Documentation
73
=====================================
84

95
.. toctree::

docs/source/tutorials.rst

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ building a library on top of this project.
2424
-----------------------------------------
2525
If you need the most flexibility, you can create custom requests using the request builder and API helper objects
2626

27+
.. note::
28+
29+
The following examples will not convert the responses back into Objects, but it is possible to do so
30+
using the appropriate class's `model_validate` method on the response object's string representation.
31+
2732
Interacting with Systems
2833
============================
2934

@@ -64,4 +69,47 @@ Just be sure to convert them to a JSON string before passing them to the `create
6469
6570
sml_as_str = sml.model_dump_json(exclude_none=True, by_alias=True)
6671
Systems.create_new_systems(server_url, sml_as_str, uname="test", pword="test",
67-
headers=sml_json_headers)
72+
headers=sml_json_headers)
73+
74+
Datastreams and Observations
75+
============================
76+
77+
Add a Datastream and Observation
78+
------------------------------------------------------------
79+
.. note::
80+
81+
This assumes that the user knows the system id and the datastream id
82+
83+
.. code-block:: python
84+
85+
from consys4py import Datastreams
86+
87+
time_schema = TimeSchema(label="Test Datastream Time", definition="http://test.com/Time", name="timestamp",
88+
uom=URI(href="http://test.com/TimeUOM"))
89+
bool_schema = BooleanSchema(label="Test Datastream Boolean", definition="http://test.com/Boolean",
90+
name="testboolean")
91+
datarecord_schema = SWEDatastreamSchema(encoding=JSONEncoding(), obs_format=ObservationFormat.SWE_JSON.value,
92+
record_schema=DataRecordSchema(label="Test Datastream Record",
93+
definition="http://test.com/Record",
94+
fields=[time_schema, bool_schema]))
95+
96+
datastream_body = DatastreamBodyJSON(name="Test Datastream", output_name="Test Output #1", datastream_schema=datarecord_schema)
97+
temp_test_json = datastream_body.model_dump_json(exclude_none=True, by_alias=True)
98+
99+
resp = Datastreams.add_datastreams_to_system(server_url, retrieved_systems[1]['id'],
100+
datastream_body.model_dump_json(exclude_none=True, by_alias=True),
101+
headers=json_headers)
102+
103+
the_time = datetime.utcnow().isoformat() + 'Z'
104+
time_millis = test_time_start.timestamp() * 1000
105+
106+
obs = ObservationOMJSONInline(phenomenon_time=the_time,
107+
result_time=the_time,
108+
result={
109+
"timestamp": time_millis,
110+
"testboolean": True
111+
})
112+
print(f'Observation: {obs.model_dump_json(exclude_none=True, by_alias=True)}')
113+
resp = Observations.add_observations_to_datastream(server_url, ds_id,
114+
obs.model_dump_json(exclude_none=True, by_alias=True),
115+
headers=json_headers)

0 commit comments

Comments
 (0)