JSON structure for a KPI
The Key Performance Indicators (KPIs) instance can be managed by using KPI APIs.
The KPI APIs work on JSON objects, which are formed by several attributes.
A KPI instance can be created by assigning particular values to these attributes.
The generic structure of a KPI JSON object is shown in the code-block widget:
{
"id": <KPI_id>,
"name": "<name>",
"editable": <true/false>,
"enabled": <true/false>,
"description": "<description>",
"category": "<category>",
"tags": "<tags>",
"range": {
"min": <min>,
"max": <max>
},
"schedule": <schedule>,
"durablePoints": <true/false>,
"pointDuration": <point_duration>,
"templateId": <template_id>,
"computationTypeCode": "<TRIGGERED/SCHEDULED>",
"dynamicAttributes": [
{
"code": "<dynamic_attribute_code>",
"value": "<dynamic_attribute_value>"
},
{
"code": "<dynamic_attribute_code>",
"value": "<dynamic_attribute_value>"
},
{...other element...}
],
"affectedLinks": [
{
"tail": <link_tail>,
"idno": <link_idno>,
"order": <link_order>
},
{
"tail": <link_tail>,
"idno": <link_idno>,
"order": <link_order>
},
{...other element...}
],
"affectedStreets": [
{
"tail": <strt_tail>,
"idno": <strt_idno>,
"order": <strt_order>
},
{
"tail": <strt_tail>,
"idno": <strt_idno>,
"order": <strt_order>
},
{...other element...}
],
"affectedLines": [
{
"idno": <line_idno>
},
{
"idno": <line_idno>
},
{...other element...}
],
"affectedStops": [
{
"idno": <stop_idno>,
},
{
"idno": <stop_idno>,
},
{...other element...}
]
}
In the structure of the JSON object, take special care about two distinct elements:
- <KPI_id>: the ID of the KPI instance, generated by Optima.
- <template_id>: the ID of the template used, provided by the user.
A KPI JSON object is made up of a subset of the attributes of a KPI template.
In the table you can find the list of all the attributes of a KPI template:
KPI Attribute | Required | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
template_id |
YES |
Integer type. Unique identifier of the template. |
||||||||||||||||||||
name |
YES |
String type. Name of the template. |
||||||||||||||||||||
query |
YES |
String type. Preset query common to all the KPIs associated to the template. |
||||||||||||||||||||
editable |
YES |
Boolean type.
|
||||||||||||||||||||
enabled |
YES |
Boolean type.
|
||||||||||||||||||||
improvingDirection |
YES |
String type. To understand if the current KPI value is better than the previous value, it is important to state if it is increasing (the higher value is better) or decreasing (the lower value is better). Possible values:
|
||||||||||||||||||||
tags |
NO |
String type. It contains a list of comma-separated words, all being associated to a KPI instance. |
||||||||||||||||||||
unit |
NO |
String type. It contains the measurement unit (if it is defined) of the KPI. |
||||||||||||||||||||
resultType |
NO |
String type. It contains the result type of the KPI instance. |
||||||||||||||||||||
range |
YES |
JSON object. Attributes used to define the limits of the KPI value.
The properties "min" and "max" are integers. If both values are specified, <max> must be greater than <min>. |
||||||||||||||||||||
entity |
YES |
String type. A string to specify the type of entity associated with the KPI calculation. Possible values:
|
||||||||||||||||||||
qualityThreshold |
NO |
JSON object. An array of two real values separated by a comma.
<min_value> and <max_value> must fall within the range and are used by the GUI to show the quality of the KPI. The two threshold values are used to define three regions and each region is associated with a dedicated color in order to identify three quality levels of the KPI. |
||||||||||||||||||||
durablePoint |
YES |
Boolean type. KPIs are calculated at discrete time and KPI values can be represented as distinct points on a chart (false).
|
||||||||||||||||||||
pointDuration |
YES |
Real value. It contains a value (in seconds) that is used only if durablePoints = true. It specifies how long a point should persist over time (the length of the segment), representing how long the value of the KPI can be considered constant. The correct value for pointDuration should coincide with: 1/simulation frequency. If pointDuration is higher than 1/simulation frequency, you can see segments overlap. In the opposite case, it is possible to see a "jump" in the graphical representation. |
||||||||||||||||||||
selectionModes |
YES |
JSON object.
Each template can have one or more selection modes associated to the KPI calculation. The available selection modes are:
Each of these selection modes can have multiple values (in the JSON object, see the "values" array), and you must choose only one value for each selection mode. For example, the MAP selection mode can have values such as POLYGON or LINESTRING, while the ATTRIBUTE selection mode can be true or false (as well as ALL). For ALL, the possible values are:
For ATTRIBUTE, the possible values are:
Tip: Selection modes can be combined if ALL=false. |
||||||||||||||||||||
type |
NO |
String type. A string representing the result type of the KPI. |
||||||||||||||||||||
category |
NO |
Sting type. It contains a string to specify the category of the template. A category is associated with a specific icon displayed on the GUI. An unknown category is associated with a default icon.
|
||||||||||||||||||||
computationTypeCode |
YES |
String type. It describes how the KPI is calculated according to a specific template. Two are the possible values:
|
||||||||||||||||||||
dynamicAttributes |
NO |
A list of attributes that are used to fill the query (JSON format). |
||||||||||||||||||||
defaultSchedule |
NO |
Integer type. A default value to schedule the KPI computation. This attribute, expressed in seconds, MUST BE set if: computationTypeCode=SCHEDULED Take care of the constraint: defaultSchedule>= minSchedule |
||||||||||||||||||||
minSchedule |
NO |
Integer type. A base value to schedule the KPI computation. This attribute, expressed in seconds, MUST BE set if: computationTypeCode=SCHEDULED Take care of the constraint: minSchedule<=defaultSchedule |
||||||||||||||||||||
AffectedLinks or AffectedStreets |
NO |
JSON object.
The attributes of the object are: tail:Integer referencing the tail node. idno: Integer referencing the link (or street) idno. order: Integer representing the order of the link (or street). Example:
|
||||||||||||||||||||
AffectedLineRoute or AffectedStops |
NO |
JSON object.
The attributes of the object are: idno: Integer referencing the lines (or stop) idno. order: Integer representing the order of the line (or stop). Example:
|
Topics in this section