m3resp.DataModelRecorder#
- class m3resp.DataModelRecorder(session, store=None, *, case=None)[source]#
Store a session’s recordings, results and processing provenance.
Construction creates or registers a case and a recording session in the store. Assign the recorder to session.datamodel to record session actions and workflow results automatically.
- Variables:
session – Runtime session being recorded.
store – DataModelStore receiving records.
case – Case associated with the session.
recording_session – Stored session record.
- Parameters:
session (M3Session)
store (DataModelStore | None)
case (Case | None)
Methods
Add values per interval or event to the store as derived features.
Materialize a
ParameterResultas aDerivedFeature.Record an exported array file and link it to its processing run.
Add a pixel map or mask to the store as a derived-feature record.
Store one processing step as a ProcessingRun with kind=step.
Store one session action as a ProcessingRun with kind=session_action.
Convert a
QualityFlaginto a storedQualityAnnotation.Record a
Signalas aSignalStream(+DataFile).Copy each recording's synchronization onto its recorded streams.
Store a workflow run and its recognized output values.
- record_interval_data(interval_data, *, processing_run_id)[source]#
Add values per interval or event to the store as derived features.
Scalar values create one feature per item. Times are copied in seconds on the input’s clock; an event uses the same time for both ends of its window. Missing
Noneor NaN values are stored asNone. Values that fail numeric conversion are stored asNonewith a logged warning.A result containing any array values creates one feature for the whole result, with
value=None. Array data is kept in the separate export archive.- Parameters:
interval_data (IntervalData | EventData) –
IntervalDataorEventDatawith values in item order and their physical unit.processing_run_id (str) – Identifier of the run already in the store.
- Returns:
- Stored features in item order for scalar
values, or one feature for a result containing arrays.
- Return type:
- Raises:
DataModelStoreError – If the processing run is absent from the store.
- record_parameter(parameter, *, processing_run_id)[source]#
Materialize a
ParameterResultas aDerivedFeature.- Parameters:
parameter (ParameterResult)
processing_run_id (str)
- Return type:
- record_parameter_file(path, *, processing_run_id)[source]#
Record an exported array file and link it to its processing run.
Exporting again to the same path replaces the earlier link to that path in the run’s
parameter_file_ids. The earlierDataFileremains in the store as a record of the earlier export.- Parameters:
- Returns:
- Stored file record with role
'parameter', a SHA-256 checksum and file size in bytes.
- Stored file record with role
- Return type:
- Raises:
- record_pixel_grid(grid, *, processing_run_id)[source]#
Add a pixel map or mask to the store as a derived-feature record.
- Parameters:
- Returns:
- Stored record with
value=None. The numeric grid is kept in a separate export archive.
- Stored record with
- Return type:
- Raises:
DataModelStoreError – If the processing run is absent from the store.
- record_processing_step(step)[source]#
Store one processing step as a ProcessingRun with kind=step.
- Parameters:
step (ProcessingStep) – ProcessingStep with a name, timestamp, input keys and settings.
- Returns:
- Record added to the store with the step’s name, parsed
timestamp and JSON-compatible settings. Known input-file keys are linked. Other run fields use ProcessingRun defaults.
- Return type:
- record_provenance(provenance)[source]#
Store one session action as a ProcessingRun with kind=session_action.
Loading actions first record the raw signal and source file when available. The session’s current synchronization settings are also copied to recorded streams.
- Parameters:
provenance (ProvenanceRecord) – Session action with a timestamp, modality and settings.
- Returns:
- Stored action record with converted settings and any
known source-file link for its modality.
- Return type:
- record_quality_flag(flag, *, target_type=None, target_id=None)[source]#
Convert a
QualityFlaginto a storedQualityAnnotation.One flag gives one annotation. The flag’s fields are copied as follows:
QualityFlag
QualityAnnotation
Notes
start_time,end_timetime_window_start,time_window_endSeconds.
breath_idorbreath_idsbreath_idsOne
breath_idbecomes a list of one. None if no breath is set.passedquality_label"valid"or"suspect".nameannotator_refannotation_sourceis always"automated".If
target_idis None, the annotation points to theSignalStreamrecorded for the flag’smodality, matched oncategorywhen the flag sets one. If the flag has no modality, or no stream is recorded for it yet, the annotation points to the session, withtarget_type"session"and the session ID astarget_id.- Parameters:
flag (QualityFlag) – The
QualityFlagto convert.target_type (Literal['signal', 'file', 'session', 'event', 'feature'] | None) – Kind of record the annotation points to. Defaults to
"signal".target_id (str | None) – ID of the record the annotation points to. If None, it is looked up from the flag as described above.
- Returns:
The annotation added to the store.
- Return type:
- record_signal(signal, *, file_path=None, file_role='raw')[source]#
Record a
Signalas aSignalStream(+DataFile).A signal whose modality is not one the data model has a stream type for (for example the default
"unknown"modality, before the signal has been tagged as EIT/EMG/ventilator) cannot be stored, so it is skipped with a warning rather than stopping the whole recording. Returns the new stream, orNonewhen the signal was skipped.- Parameters:
- Return type:
SignalStream | None
- record_synchronization()[source]#
Copy each recording’s synchronization onto its recorded streams.
Sets SignalStream.sync_method from session.sync_methods (
"manual","none") and SignalStream.time_offset_ms from the recording’s start time on the shared clock. A stream whose recording was never synchronized gets None for both. Ventilator data from the EIT or EMG file takes that file’s synchronization.- Return type:
None
- record_workflow_result(result)[source]#
Store a workflow run and its recognized output values.
Nested lists, tuples and dictionaries are visited recursively. Signals, measurements, per-event/per-interval results, pixel grids and quality flags use their corresponding recorder methods. Bare numeric outputs become derived features named by context key; booleans and unsupported objects are skipped.
- Parameters:
result (WorkflowResult) – Completed WorkflowResult containing named outputs.
- Returns:
- Stored record with kind=workflow and the workflow name.
Native measurement, signal and grouped-result provenance is kept in parameters[“outputs”]. Array values remain in exported archives. All input files known to this recorder are linked, including files from earlier runs on the same session. Status and run_time use ProcessingRun defaults.
- Return type: