Custom Queries
The Custom Queries section enables you to perform direct queries against the database in which the data model is stored.
The database used by Altair IoT Studio is ArangoDB, which allows you to perform queries using the capabilities of a graphical database.
Thing Diagram
When accessing the Custom Queries panel, the first thing to look at in some detail is
the Thing Diagram. This diagram defines the structure that
the AnythingDB database follows internally. This structure must be followed to
perform the queries correctly.
Run a Custom Query
To perform a custom query, you must directly insert the query text into the "query" field inside the box below the Execute button. Below are two sample queries using the parking system example.
-
Check occupied parking slots.
-
Get all Traffic Lights location.
In this example you will launch a query to obtain the location of all the traffic lights.
-
Get the average "Power Consumption" of all the Traffic lights.
In this example you will launch a query to obtain the average value of the property "Power Consumption" of all the things titled "Traffic Light" that belong to the category "TrafficManagement."
{ "query": "FOR c in categories FILTER c.name == @category_name FOR t IN things FILTER t.title == @thing_title FILTER c._id IN t.categories FILTER HAS(t.status, @property_name) COLLECT AGGREGATE average = AVG(t.status.@property_name) RETURN average", "count": true, "bindVars": { "category_name": "TrafficManagement", "thing_title":"Traffic Light", "property_name": "Power Consumption" } }
The response returned by the platform will include the result:de": 201, "count": 1, "error": false, "extra": { "stats": { "executionTime": 0.009605439845472574, "peakMemoryUsage": 32768 } }, "hasMore": false, "result": [ 14.75 ] }