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:
eventId | Timestamp | value | sensorId |
---|---|---|---|
H423F01 | 2024-12-23 00:00:00+00:00 | 0.060816 | mt1_bearing1 |
H423F01 | 2024-12-23 01:48:45+00:00 | 0.030947 | mt2_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 batchH423F01
is being processed by the first motor. - At
01:48:31
, when batchH423F01
transitions to the second motor, and a new batch,JFJO4NF
, begins on the first motor. - At
03:54:31
, when batchJFJO4NF
is being processed on the second motor bearings, while a third batchFJ39DD3
starts on the first motor.
Timestamp | eventId on motor1 | mt1_bearing1 | mt1_bearing2 | eventId on motor2 | mt2_bearing1 | mt2_bearing2 |
---|---|---|---|---|---|---|
00:00:00 | H423F01 | 0.061599 | 0.075657 | NaN | NaN | NaN |
01:48:31 | JFJO4NF | 0.060645 | 0.075734 | H423F01 | 0.0306 | 0.055704 |
03:54:31 | FJ39DD3 | 0.060730 | 0.074881 | JFJO4NF | 0.030688 | 0.055005 |
Updated about 1 month ago