@@ -24,6 +24,11 @@ building a library on top of this project.
2424-----------------------------------------
2525If 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+
2732Interacting 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