# Real Time Visualization

### Set Up

1. Set Read-Only token

Set the Read-only OAUTH token that you can find in the private API tab of the settings section of your ubudu Manager account

1. Select the Application

In the "App" tab, select the application defined in your ubudu Manager's account for which you want to visualise real time reported positions .

1. Select the venue

In the "Venue" tab, select the appropriate venue.

When these steps are successfully fulfilled, the venue map is projected on Google Maps displaying the zones retrieved from the BO. On each zone, a movable green bubble counter is updated each time a new asset presence event occurs.

## Structure

The "Real time visualization" is composed of 4 main sections:

• (1) "Alert Rule Editor" : Zone Counter & dwell time zones Alert Rules Engine

• (3) "Zones real time stats" : Statistics on real time events

• (4) "Devices reporting data" : List of the assets that are detected in the venue

#### Alert Rule Editor

Through the following steps you will be able to configure the "Alert rule editor" according to your specific needs in terms of alerts generations.

This rule editor is a powerful and lightweight Json-rules-engine based. It is composed of an array of rules and enables to trigger and log alerts when conditions on counter zone or/and time spent in a zone are verified.

By definition, a rule is determined by 2 components :

• the conditions for which the event is triggered. It is a set of requirements that must be met to trigger the rule's event
• the event that determines the format of the alert (Type of notification, Label of the notification, content of the notification, style of the notification..)

Now that you are familiar with these concepts , Let's Get Started ...

###### How to display an alert when a (zone counter) OR (dwell time in zone) threshold in a specific zone is exceeded ?
1. Determine the conditions of an alert trigger

Rule conditions are a combination of facts, operators, and values that determine whether the rule is asuccessor afailure.

Each rule's conditions must have either an allor an anyoperator at its root, containing an array of conditions. The alloperator specifies that all conditions contained within must be valid for the rule to be considered a success. The anyoperator only requires one condition to be valid for the rule to succeed.

The condition is specified by 3 parameters :

• "fact" to determine the dimension of the condition. It can be either an event based on a zone counter(zone__count) or a dwell time (time_in_zone).
• "operator" to specify operation logic

• String and Numeric operators:
• equal :fact must equal value
• notEqual :fact must not equal value
• these operators use strict equality (===) and inequality (!==)
• Numeric operators:
• lessThan :fact must be less than value
• lessThanInclusive :fact must be less than or equal to value
• greaterThan :fact must be greater than value
• greaterThanInclusive :fact must be greater than or equal to value
• "value" to which the fact is compared

Sometimes it is necessary to compare 2 conditions in order to build 1 main condition.

Example 1 : trigger an event based on counter zone :

{
"rules": [
{
"conditions": {
"any": [
{
"all": [
{
"fact": "zone_count",
"operator": "greaterThanInclusive",
"value": 3
},
{
"fact": "zone_name",
"operator": "equal",
"value": "sales"
}
]
}
]
}
}
]
}


In this example , the event will be triggered if there are more than 3 asset in the zone named "sales" .

Example 2 : The example below shows how the structure should be implemented for dwell time in zone :

{
"rules": [
{
"conditions": {
"any": [
{
"all": [
{
"fact": "time_in_zone",
"operator": "greaterThanInclusive",
"value": 15
},
{
"fact": "zone_name",
"operator": "equal",
"value": "tech"
}
]
}
]
}
}
]
}


In this example , the event will be triggered if the time spent in the zone names "tech" is more than 15 seconds.

1. Determine the type of the event

Having explained how to configure the conditions for a rule, you may wonder how to define and what kind of event to fire when the conditions are met.

By definition, an event is determined by 2 components :

• "type" to identify whether the alert is a message displayed on the tool or a notification sent to a Third-Party application.
• Options: message | post__to__callback_url
• "params" to specify the alert

• "title" to specifiy the header of the event

• "text" to add a custom text

• "coalescence" to limit the number of event triggered in a time interval (second)

• "coalescence_group" is a key that can be composed dynamically with the same variable for which the condition has been defined.

Let's put this in practice !

Example 1 : in the example below, the message "Too many assets in Sales Room" will be displayed every 10 seconds each time the conditions are met (i.e 3 assets in the zone "sales") .

{
"rules": [
{
"conditions": {
"any": [
{
"all": [
{
"fact": "zone_count",
"operator": "greaterThanInclusive",
"value": 3
},
{
"fact": "zone_name",
"operator": "equal",
"value": "sales"
}
]
}
]
},
"event": {
"type": "message",
"params": {
"text": "Too many assets in Sales Room",
"coalescence": 10,
"coalescence_group": "{{zone_id}}"
}
}
}
]
}


In order to prevent collision between rules and to have an event per specific rule, it is recommended to add a prefix at the "coalescence_group" variable. See the example below :

{
"rules": [
{
"conditions": {
"any": [
{
"all": [
{
"fact": "zone_count",
"operator": "greaterThanInclusive",
"value": 3
},
{
"fact": "zone_name",
"operator": "equal",
"value": "sales"
}
]
}
]
},
"event": {
"type": "message",
"params": {
"text": "Too many assets in Sales Room",
"coalescence": 10,
"coalescence_group": "rule1_{{zone_id}}"
}
}
}
]
}


You can also post alerts in a third-party pplication by changing the "event" structure in the alert rule editor .

In the example below, we chose to post the alert in PushBullet, a service that enables to connect devices between them and trigger notifications.

"event": {
"type":"post_to_callback_url",
"params": {
"text": "Entrée Zone X",
"push_bullet_access_token": "o.bmg00tmOffvtJwlxHbgsfOuh",
"devices_ids":[
"ujExcblEzsthgrpn4od"
],
"coalescence":10,
"coalescence_group": "{{zone_id}}
}
}


Besides the alert that is displayed on the top right corner, it is possible to review all displayed rules. They are recorded and available in the section "Alerts".

#### Zone Real Time Stats

In addition to the green bubbles on the map that indicate the counter zone, it is possible to read in real time and in a table format the number of assets present in each zone. An other column represent the average dwell time for each zone.

#### Devices reporting data

You may be wondering what are the detected assets in the venue. In the following example, the table lists all the assets for which a position data was reported. Each row of the table gives you all information about a specific asset :

• Name of the asset
• Symbol corresponding to the type of the asset (Smartphone | Tag)
• UUID of the asset
• The name of the asset (smartphone brand | token)
• The zone where it is located