Insights API

An insight can be defined by either:

  • Starting from scratch by configuring it with a combination of parameters, operators, and constants that determine if a matching Event is forecasted to occur
  • Starting from any of our rich collection of Templates, based on real industry use-cases
  • Subscribing to an Insight Category (that encompasses various similar events reported by our sources)
  • Insights are current supported only for the metric system

You can create an insight by either our Rules language (Recommended), or using conditions - AST Trees,

Rules Language (Recommended)

The language is a simplified expression language designed to create dynamic conditions for querying insights in the API. This document provides an overview of the operators and syntax available in language.

Operators
The following table lists the operators available in language:

OperatorDescriptionExample
ANDLogical AND(temperature > 30 AND cloudCover IS NULL)
ORLogical OR(windSpeed > 100 OR humidity < 10)
>Greater Thantemperature > 30
<Less ThancloudCeiling < 3000
>=Greater Than or Equal TosnowAccumulation >= 10
<=Less Than or Equal TowindDirection <= 180
==Equal TowindSpeed == 20
IS NULLCheck if parameter is nullcloudCover IS NULL
!Negation (NOT operator)!(temperature > 30)

Syntax
The syntax of the language is based on simple expressions composed of parameters, comparison operators, and logical operators. Here's a breakdown of the syntax elements:

Parameters: Parameters represent the values you want to compare. For example, "temperature", "windSpeed", or "cloudCover" can be parameters in your conditions.

Comparison Operators: Comparison operators allow you to compare parameters with constants or other parameters. Examples of comparison operators include >, <, >=, <=, and ==. These operators are used to create conditional statements within your expressions.

Logical Operators: Logical operators enable you to combine multiple conditions. the language supports the logical AND operator (AND), which evaluates to true only if all conditions are true, and the logical OR operator (OR), which evaluates to true if any of the conditions are true.

Negation Operator: The negation operator, represented by !, allows you to negate a condition. It negates the result of the condition, effectively flipping its logical value.

IS NULL Operator: The "IS NULL" operator checks if a parameter is null. It is used to specifically validate if a parameter holds a null value.

Examples

To help you understand how to use the language, here are a few examples of valid expressions and their interpretations:

Example 1:

Expression: !(hailBinary == 0)

Interpretation: Select insights where the hailBinary is not equal to 0.

Example 2:

Expression: (temperature > 30 AND cloudCover IS NULL)

Interpretation: Select insights where the temperature is greater than 30 and the cloudCover parameter is null.

Example 3:

Expression: (windSpeed > 100 OR humidity < 10)

Interpretation: Select insights where the windSpeed is greater than 100 or the humidity is less than 10.

Example 4:

Expression: temperature > 30

Interpretation: Select insights where the temperature is greater than 30.

Example 5:

Expression: !(snowAccumulation >= 10)

Interpretation: Select insights where the snowAccumulation is not greater than or equal to 10.

Example 8:

Expression: ( (temperature > 30 AND cloudCover IS NULL) OR (windSpeed > 20 AND !( (rainIntensity > 10 AND snowAccumulation IS NULL) OR humidity < 50 )) )

Interpretation: Select insights where either:

The temperature is greater than 30 and the cloudCover is null, or

The windSpeed is greater than 20 and neither of the following conditions are met:

The rainIntensity is greater than 10 and the snowAccumulation is null, or

The humidity is less than 50.

Conditions Language (AST Trees)

The simplest form of a condition consists of an OPERATOR, a PARAMETER, and a CONST. When the engine runs, the operator is used to compare the parameter against the constant. If the result is truthy, the condition passes.

Each operator node has three properties:

  • type: a string that sets the type of the node - always OPERATOR
  • content: an object that contains the definition of the operator - for example operator: AND
  • children: an array with the collection of chained conditions
{
    "type": "OPERATOR",
    "content": {
        "operator": "AND"
    },
    "children": [{
            "type": "OPERATOR",
            "content": {
                "operator": "EQUAL"
            },
            "children": [{
                    "type": "PARAMETER",
                    "content": {
                        "parameter": "precipitationType"
                    }
                },
                {
                    "type": "CONST",
                    "content": {
                        "const": 1
                    }
                }
            ]
        },
        {
            "type": "OPERATOR",
            "content": {
                "operator": "GREATER"
            },
            "children": [{
                    "type": "PARAMETER",
                    "content": {
                        "parameter": "precipitationIntensity"
                    }
                },
                {
                    "type": "CONST",
                    "content": {
                        "const": 0.5
                    }
                }
            ]
        }

    ]
}

Logical Operators:
These operators must have at least two child nodes, of type OPERATOR. Notice that AND and OR can be nested within one another to produce complex boolean expressions. These operators must have at least two children.

OperatorDescription
ANDspecifies that all child conditions contained within must be truthy for the condition to be considered a success
ORrequires one child condition to be truthy for the condition to succeed

Comparison Operators:
These operators must have one child node of type PARAMETER and another of type CONST in this order, such that their value types match. For example precipitationType can only have string values and therefor the constant it is compared against must be a string.

OperatorDescription
GREATER PARAMETER must be greater than CONST to be considered truthy
GREATER_EQUALPARAMETER must be greater than or equal to CONST to be considered truthy
LESSPARAMETER must be less than CONST to be considered truthy
LESS_EQUALPARAMETER must be less than or equal to CONST to be considered truthy
EQUALPARAMETER must equal CONST to be considered truthy

Time Operator:
These operators must have two child nodes, either PARAMETER or CONST types, such that they describe a time period within a single day (00:00 until 23:59) in a monitored Location's timezone. Using sunriseTime and sunsetTime parameter that match the Location's specific times.

OperatorDescription
TIME_IN_DAYmust occur in the time in day between the first and second child to be considered truthy, whereas a child is defined by a PARAMETER (like sunsetTime or sunriseTime) or CONST like (18:00)

Parameters

For non-logical operators, PARAMETER children represent the conditions of observed/forecasted values at the monitored location. Read more about facts in the next section.

In case a field name suffix is not defined, Polygons will use the default type (see Data Layers). In case an Insight has a Min/Max/Average suffix and is checked for a Point location, the suffix will be omitted.

Each parameter node has two properties:

  • type: a string that sets the type of the node - always PARAMETER
  • content: an object that contains the definition of the data field name for the parameter to check against a constant (or operator such as TIME_IN_DAY) - such as precipitationType, precipitationIntensity or sunsetTime

Constants

For non-logical operators, CONST children represent constant values to check the other child value against (can be parameters, constants, or other operators).

Each const node has two properties:

  • type: a string that sets the type of the node - always CONST
  • content: an object that contains the value to check against the parameter (or operator such as TIME_IN_DAY) - for example, rain, 15, or 18:00 and must match the same type (like string, float etc).