AnnotatedRecording Class

The AnnotatedRecording class is a container for a sequence of Measurement objects, along with a set of TimedAnnotations that mark specific events within the recording.

Properties

  • measurements (list[Measurement]): A list of Measurement objects, sorted by timestamp.
  • annotations (list[TimedAnnotation]): A list of TimedAnnotation objects, sorted by time.

Methods

from_json_entry(json)

Creates an AnnotatedRecording object from a JSON entry. This is useful for deserializing data.

split_by_annotations()

Splits the recording into segments based on the annotations. It returns a list of tuples, where each tuple contains the annotation label and the list of Measurement objects that fall within that annotation’s time range (until the next annotation).

to_json_entry()

Converts the AnnotatedRecording object into a JSON-serializable dictionary.

Usage Example

from flexlib.models.flex_reader import FlexReader
from flexlib.models.timed_annotation import TimedAnnotation
import datetime

# Load a recording
recording = FlexReader.parse('your_recording.csv')

# Add annotations manually
recording.annotations.append(TimedAnnotation(time=recording.measurements[10].time, label="Lift Start"))
recording.annotations.append(TimedAnnotation(time=recording.measurements[50].time, label="Lift End"))
recording.annotations.sort(key=lambda a: a.time)

# Split the recording by annotations
split_data = recording.split_by_annotations()

for label, measurements in split_data:
    print(f"Segment '{label}': {len(measurements)} measurements")

# Example output:
# Segment 'Lift Start': 40 measurements
# Segment 'Lift End': ... measurements