Tutorial: Calculating the time spent in a specific state
In this tutorial, you define which state to aggregate for devices. Use the PrepareTimeInState
built-in function to specify the state. Using the AggregateTimeInState
, you calculate the amount of time that the device
spends in each state. Build a dashboard to monitor the time spent in each state.
About this task
In this tutorial, you calculate the amount of time per day that robots traveled too fast. Select a robot and review the time that the robot spent traveling too fast over the past week.
Steps
Complete these tutorial steps:
Step 1: Create a robot device type
- On the Setup tab, click
to add a device type.
- In the Add device type dialog, on the Select a template page, select the Robot Sample Type template.
- Assign a name to the device type.
- Click Create.
- Select the sample device type, click Manage device type, and then click Data.
KPI data takes up to 5 minutes to generate.
Step 2: Define the state
- On the Data tab, click
.
- Select the
PrepareTimeInState
function from the catalog. - On the scope page, select All devices of this type.
- Click Next.
- On the input page, select
speed
as the source data item. - Define the state condition as
>= 3.5
. - On the output page, specify
too_fast
as the new KPI name. - Clear the 'Store in database' option.
- Click Create
- In the data item list, select
too_fast
. - Wait up to 5 minutes for Analytics Service to evaluate the expression using the sample data. Verify that the function produces some output.
Step 3: Calculate the amount of time that was spent in the state
- On the Data tab, click
.
- Select the
AggregateTimeInState
function from the catalog. - On the scope page, select All devices of this type.
- Click Next.
- On the input page, select
too_fast
as the source data item. - On the output page, specify
time_travelling_too_fast
as the new KPI name. - Set the time grain to hourly.
- Include the last 5 hours of historical data.
- Click Create
- In the data item list, select
time_travelling_too_fast
. - Wait up to 5 minutes for Analytics Service to evaluate the expression against the sample data. Verify that the function produces some output.
Step 4: Add a dashboard to the robot devices
- Go to a robot device on the user interface.
- Click Dashboards.
- Click Add dashboard.
- Assign the title 'tutorial' to the dashboard and click Configure. You'll overwrite the dashboard title in the JSON configuration.
- Click Import and import the following dashboard configuration from a JSON file:
-
Expand to see JSON
{ "timeGrain": "day", "cards": [ { "id": "344ed855-d211-4fcb-bec0-794f973de8e6", "title": "Time spent travelling too fast", "size": "MEDIUMWIDE", "type": "BAR", "content": { "type": "SIMPLE", "layout": "VERTICAL", "series": [ { "dataSourceId": "time_travelling_too_fast_36588a25-19fd-48a2-a973-9eb6ae3c9a87", "label": "time_travelling_too_fast", "color": "#6929c4" } ], "timeDataSourceId": "timestamp" }, "dataSource": { "attributes": [ { "id": "time_travelling_too_fast_36588a25-19fd-48a2-a973-9eb6ae3c9a87", "attribute": "time_travelling_too_fast", "aggregator": "mean" } ], "timeGrain": "day", "range": { "interval": "day", "count": -7, "type": "rolling" } }, "timeRange": "last7Days" } ], "title": "Robot speed", "layouts": { "lg": [ { "w": 16, "h": 2, "x": 0, "y": 0, "i": "344ed855-d211-4fcb-bec0-794f973de8e6", "moved": false, "static": false, "isResizable": true } ], "md": [ { "i": "344ed855-d211-4fcb-bec0-794f973de8e6", "x": 0, "y": 0, "w": 8, "h": 2, "isResizable": true } ], "sm": [ { "i": "344ed855-d211-4fcb-bec0-794f973de8e6", "x": 0, "y": 0, "w": 4, "h": 2, "isResizable": true } ] } }
-
Expand to see JSON
- Click Save.
Step 5: Monitor the time spent in the state
- On the Monitor tab, click Devices.
- Find your device type.
- Open the Robot speed tab.
- Review the time spent traveling too fast for one of the devices over the last 7 days.
Example: