Tagging

Tagging provides a way for users to augment log data with easy-to-use labels. Tags are always assigned to one, and only one, log as well as one, and only one, label. Tags can optionally be assigned to a specific topic within the assigned log. Tags can be given a start time and end time representating a range of time for which the tag applies, a start time representating a specific instant in time in which a tag applies, or no time at all which represents that a tag applies to the entirety of the log.

Tutorial: Tagging Based on Record Query Data

Tags work well in combination with record querying in that record querying allows you to find interesting points-in-time in your logs and tags can be used to mark those points-in-time. This tutorial will show you how to use LogQS to tag interesting points-in-time in your logs based on record query data.

1. Fetch a Topic with Records We’re Interested In

Here, we assume we have a specific log in mind and are interesting in querying the record’s for the log’s IMU data:

imu_topic = lqs.list.topic(
    log_id=log_id,
    type_name="sensor_msgs/Imu",
).data[0]

2. Query for Records in the Topic

Next, we find all the records in the topic which meet specific criteria. In this case, we’re finding all IMU records where the linear acceleration in the z direction is less than -18.0 m/s^2.

res = lqs.list.record(
    topic_id=imu_topic.id,
    query_data_filter={
        "var": "linear_acceleration.z",
        "op": "<",
        "val": -18.0,
    }
)

print(f"Found {res.count} records matching the query.")

>> Found 7 records matching the query.

records = res.data

3. Fetch the Label we Want to Use

We assume the label already exists, so we fetch it by its value.

label = lqs.list.label(value="Extreme Vertical Acceleration").data[0]

4. Create Tags for Each Record

For each of our records, we create a tag using the label we fetched with a start time set to the record’s timestamp. We also populate the tag with some extra data, such as a note indicating that the tag was created with a demo script and some context data from the record’s query data.

Tags are unique per label, log, topic, start_time, and end_time. If a tag already exists for the same label, log, topic, start_time, and end_time, a ConflictException will be raised. In this case, we catch the exception and skip creating the tag.

from lqs.common.exceptions import ConflictException

for record in records:
    print(f"Creating tag at timestamp {record.timestamp}")
    try:
        lqs.create.tag(
            label_id=label.id,
            topic_id=imu_topic.id,
            log_id=log_id,
            start_time=record.timestamp,
            note="Created with demo script",
            context={
                "x": record.query_data["linear_acceleration"]["x"],
                "y": record.query_data["linear_acceleration"]["y"],
                "z": record.query_data["linear_acceleration"]["z"],
            }
        )
    except ConflictException:
        # tags are unique per label, log, topic, start_time, and end_time
        print("Tag already exists, skipping")
        continue

In Studio, these tags will appear in the Player view for the log.

../_images/tagging_demo.png