numerous.sdk.connect.writer module#
Functionality related to writing data series and the Writer.
- exception numerous.sdk.connect.writer.TagsNotAllowed(tags)#
Bases:
ExceptionAn error raised when written tags are invalid according to the data series.
- class numerous.sdk.connect.writer.Writer(spm_stub, job_identity, start_time, execution_id, max_size_bytes, flush_margin_bytes)#
Bases:
objectThe
Writerenables writing rows and series to the server. It manages a buffer, which is automatically flushed when it is full.- flush()#
Flushes the buffer of the writer.
- Return type:
None
- row(time, data, flush=False)#
Write a row of data into the data series.
Each row written to the
Writermust have same keys as previously written series or rows.- Parameters:
time¶ (
Union[float,datetime]) – The time, at which the data is indexed. If a float value, it is interpreted as an offset in seconds since the start time of the job, otherwise if it is a datetime, it is interpreted as the time within the job runtime.data¶ (
dict[str,float]) – The row of data to write into the data stream.flush¶ (
bool) – If true, will flush the buffer of the writer upon writing.
- Raises:
TagsNotAllowed – If tags that have not been previously written, are written.
- Return type:
None
Writing rows can be used alongside
numerous.sdk.JobClient.read_inputs(), which will also iterate over the jobs runtime:>>> for t, data in job_client.read_inputs(step=3600.0): ... job_client.writer.row(t, {"output": data["input1"] * 2})
The type of the time values does not have to be the same type for each call:
>>> job_client.job_time.start datetime(2023, 6, 1, 12, 0 ,0) >>> job_client.writer.row(datetime(2023, 6, 1, 12, 0, 0), {"value": 1.0}) >>> job_client.writer.row(3600.0, {"value": 2.0}) >>> job_client.writer.row(datetime(2023, 6, 1, 14, 0, 0), {"value": 4.0})
- series(times, data, flush=False)#
Write a series of data to the data stream.
Each series written to the
Writermust have same keys as previously written series or rows.- Parameters:
times¶ (
Sequence[Union[float,datetime]]) – The time values of the series, like forrow(), they can be either offsets from the start time, or a point in time.data¶ (
dict[str,list[float]]) – The data series to write. The keys are validated against previously written keys.flush¶ (
bool) – If true, will flush the buffer of the writer upon writing.
- Raises:
TagsNotAllowed – If tags that have not been previously written, are written.
- Return type:
None