Querying Event datapoints

In the previous articles, we covered the main principles of an Event/batch solution, including the creation and usage of group systems, linking them with their respective twins, and we also prepared a dataset file containing 24-hours of a batch processing log data.

In this article, we will demonstrate how you can Query event data and interpret the values received from the queries.

We have a whole dedicated article regarding queries, their structure and their different parameters.

Event datapoint queries structure

Querying event datapoints allows you to track specific information for a particular machine, regardless of the timestamp. By attaching a group system to the twin, we can track data from sensors at the exact time a specific event occurred, using the unique event ID.

The query structure is similar to querying telemetry datapoints, with minor adjustments to accommodate event-specific requirements.

Group

To start creating an event query, you need to provide a group system ID and a list of event IDs.

In our concrete example, we already created a group system of keybearings_track, to track all the related events happening on our motor bearings when there is batch activity in process.

At the same time, we will add an event ID JFJO4NF to track the results happening at the time that batch was being processed. This is how the group dict would look like:

    group={
        "system_id": "bearings_track",
        "event_ids": ["JFJO4NF"]
    },

Note: The event_ids field accepts a list, allowing you to query multiple batches by ID simultaneously if needed.

We still need to add the rest of the structure for the telemetry datapoints (In our example, these would be the bearings vibration from each motor).

Query structure example

In the introductory article we proposed a schema showing an example of multiple batches running on a certain time T, with average bearing vibration values of our motors that we got from a query . Let's analyze this results in details.

You can find this schema on this article: Design your Event/Batch solution

The following query was used to get track (using the dataset from the previous article) of the vibration from our motors bearings, for the first three event batches ID's.

df_case03 = wizata_dsapi.api().query(
    group={
        "system_id": "bearings_track",
        "event_ids": [
        "H423F01", "JFJO4NF", "FJ39DD3"
        ]
    },
    interval=None,
    agg_method=None,
    field=['valueStr', "eventId", "value"],
    datapoints=[
        "mt1_bearing1",
        "mt1_bearing2",
        "mt2_bearing1",
        "mt2_bearing2"],
    options={
        "null": "ignore"
    }
)

The result will be a raw dataframe containing all the bearing values at the specified event timestamps.

For instance, the first two rows illustrate the timestamps for event H423F01 , showing the exact bearing values when the batch began processing on different motors:

eventIdTimestampvaluesensorId
H423F012024-12-23 00:00:00+00:000.060816mt1_bearing1
H423F012024-12-23 01:48:45+00:000.030947mt2_bearing1
............

Analyzing query results

After doing some data pivoting with the result query dataframe (calculating the average bearing vibration with all the raw values and grouping them by event interval), we can divide them into three distinct event times:

  • At 00:00:00, when batch H423F01 is being processed by the first motor.
  • At 01:48:31, when batch H423F01 transitions to the second motor, and a new batch, JFJO4NF, begins on the first motor.
  • At 03:54:31 , when batch JFJO4NF is being processed on the second motor bearings, while a third batch FJ39DD3 starts on the first motor.
TimestampeventId on motor1mt1_bearing1mt1_bearing2eventId on motor2mt2_bearing1mt2_bearing2
00:00:00H423F010.0615990.075657NaNNaNNaN
01:48:31JFJO4NF0.0606450.075734H423F010.03060.055704
03:54:31FJ39DD30.0607300.074881JFJO4NF0.0306880.055005

What’s Next