Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A metric is an expression which describes a computation that will be performed over the project's data. Metrics are written in a custom query language, which is fairly simple and doesn't require users to know SQL. A metric written in this language is then translated to SQL by a backend service and executed as multidimensional query on data warehouse.

...

This is the simplest type of metric. It returns the sum (function_sum) of all basket amounts (property baskets.amount).

All available functions and operators are described below.

Code Block
titleTurnover metric object syntax
{
    "name": "turnover_metric",
    "type": "metric",
    "content": {
        "type": "function_sum",
        "content": [
            {
                "type": "property",
                "value": "baskets.amount"
            }
        ]
    }
}

...

KeyTypeOptionalityDescriptionConstraints
typestring
Status
colourRed
titleREQUIRED
dwh query property, dwh query function, or a number

[dwh query functionproperty, number, variable]

contentarray
Status
colourRed
titleREQUIRED

array of dwh property definitions (see the content.content table)


optionsobject
Status
colourGreen
titleoptional
function options, allows to specify filters

...

KeyTypeOptionalityDescriptionConstraints
idstring
Status
colourGreen
titleoptional
choose a custom string identifier for the query property(a-z0-9_-)
typestring
Status
colourRed
titleREQUIRED
dwh query property, dwh query function, or a number

[dwh query functionproperty, number, variable]

value

string

long

decimal

Status
colourRed
titleREQUIRED

string identifier of a dataset property, which the function will be applied to (for type=function)

string with variable name (for type=variable)

long or decimal value (for type=number)

{datasetName}.{datasetProperty}

content.options

KeyTypeOptionalityDescriptionConstraints
aggregateByarray
Status
colourGreen
titleoptional

specifies datasets which the metric will be aggregated to

if specified, always null

[null]

acceptAggregateByarray
Status
colourYellow
titleVARIES

specifies datasets which the metric is allowed to be aggregated to

array of dataset names, or name prefixes (with the * wildcard)

(warning) only one of acceptAggregateBy and dontAggregateBy keys can be specified

{datasetName}

{datas*}


dontAggregateByarray
Status
colourYellow
titleVARIES

specifies datasets which the metric is not allowed to be aggregated to

array of dataset names, or name prefixes (with the * wildcard)

(warning) only one of acceptAggregateBy and dontAggregateBy keys can be specified

{datasetName}

{datas*}


withoutFiltersarray
Status
colourYellow
titleVARIES

specifies dataset properties not to be explicitly joined into the final query

array of dataset properties

(warning) only one of withoutFilters and acceptFilters keys can be specified

{datasetName}.{datasetProperty}

{datasetName}.*

*.*

acceptFiltersarray
Status
colourYellow
titleVARIES

specifies dataset properties to be explicitly joined into the final query

array of dataset properties

(warning) only one of withoutFilters and acceptFilters keys can be specified

{datasetName}.{datasetProperty}

{datasetName}.*

*.*

filterByobject
Status
colourGreen
titleoptional
object specifying the filter of the metric


placesinteger
Status
colourGreen
titleoptional

the number of places to round the metric result to

(warning) only for a metric with function_round


...

Some metrics are not computable when aggregated to certain datasets. Say we have a 3-level hierarchical administrative units - districts, wards and postcodes. But the business data is available only up to the 2nd level - wards.

Drawio
contentId644251843
simple0
zoom1
simpleinComment0
inCommentcustContentId0644251843
pageId120336991custContentId644251843
diagramDisplayNameacceptAggregateBy.xml
lbox1
contentVer2
revision2
baseUrlhttps://clevermaps.atlassian.net/wiki
diagramNameacceptAggregateBy.xml
pCenter0
aspectundefined
width401
links
tbstyle
height131

...

KeyTypeOptionalityDescriptionConstraints
propertystring
Status
colourRed
titleREQUIRED

identifier of a dataset property, which the filter will be applied to

{datasetName}.{datasetProperty}
value

string

long

decimal

boolean

Status
colourYellow
titleVARIES

value, by which the property will be filtered

this key is polymorphic - it doesn't have only one type

it can also be a single value, or an array:

  • for the in operator, specify an array of values
  • for all the other operators, use single value

(warning) only one of value and query keys can be specified


queryobject
Status
colourYellow
titleVARIES

query, by which the property will be filtered (see the content.content table)

(warning) only one of value and query keys can be specified


operatorobject
Status
colourRed
titleREQUIRED

the operator that will be used by the filter

see the available filterBy operators


filterBy examples

Code Block
titlefilterBy syntax excerpt with string value and eq operator
collapsetrue
    "filterBy": [
        {
            "property": "shops.type",
            "value": "partner",
            "operator": "eq"
        }
    ]

...

Window functions provide the ability to perform calculations across sets of rows that are related to the current query row.

IdentifierDescriptionExample

function_ntile

integer ranging from 1 to the argument value, dividing the partition as equally as possible

input: buckets = 3, values = [15, 73, 54, 33, 24, 80], argument = 73, sort = "asc"

input values are grouped into these buckets = ([15, 24], [33, 54], [73, 80])

result: 3 (argument 73 is in the 3th bucket)

function_rankrank of the current row with gaps

input: values = [15, 73, 54, 33, 24, 15], argument = 54, sort = "asc"

input values sorted = (15, 15, 33, 54, 73, 80)

result: 4 (argument 54 is the 4th element in sorted list of input values)

function_percentilevalue below which a given percentage of observations in a group of observations fall

input: values = [10, 75.2, 35.2, 21, 42.7, 61.1, 105.9], argument = 75.2, sort = "desc"

input values sorted = (105.9, 75.2, 61.1, 42.7, 35.2, 21, 10)

result: 83,3 (number 75.2 is higher than 83,3% of other input values)

function_row_numbera unique number for each row starting with 1. For rows that have duplicate values, numbers are arbitrary assigned.

input: values = [15, 73, 54, 33, 24, 15], argument = 54, sort = "asc"

input values sorted = (15, 15, 33, 54, 73, 80)

result: 4 (argument 54 is the 4th element in sorted list of input values)

...

  • function_plus, function_minus and function_multiply accept 2 or more arguments
  • function_divide and function_modulo accept exactly 2 arguments
IdentifierExample

function_plus

7 + 2 = 9

function_minus

7 - 2 = 5

function_multiply

7 * 2 = 14

function_divide7 / 2 = 3.5
function_modulo7 mod 2 = 1

...

IdentifierDescriptionExample
function_round

a rounding function (round to specific number of places)

function_round(56.157094235, 1) = 56.2

Conditional functions

IdentifierDescriptionExample

function_ifnull

defines the default value to use if the result of aggregate function is null

number = 0.0, value = null

function_ifnull(null) = 0.0


...

IdentifierDescriptionExample
eqis equal

input values: ["apple","orange","banana"], eq = "orange"

result: ["orange"]

nenegated

input values: ["apple","orange","banana"], ne = "orange"

result: ["apple","banana"]

inin range

input values: [1,2,3,4,5,6,7,8], in = [3,6]

result: [3,4,5,6]

ltlower than

input values: [1,2,3,4,5,6,7,8], lt = 5

result: [1,2,3,4]

ltelower than or equal

input values: [1,2,3,4,5,6,7,8], lte = 5

result: [1,2,3,4,5]

gtgreater than

input values: [1,2,3,4,5,6,7,8], gt = 5

result: [6,7,8]

gtegreater than or equal

input values: [1,2,3,4,5,6,7,8], gt = 5

result: [5,6,7,8]

isNullis null

input values: [1,2,3,4,null,6,7,8], isNull = 2

result: false

isNotNullis not null

input values: [1,2,3,4,null,6,7,8], isNotNull = 2

result: true

inAttributeis in attributesee the usage in a complete metric example above
notInAttributeis not in attributecomplementary to the inAttribute example 

...