View Source ExTeal.Metric.Partition behaviour (ExTeal v0.27.7)

Partition metrics displays a pie chart of values.

Summary

Callbacks

Often, the column values that divide your partition metrics into groups will be simple keys, and not something that is human readable. Or, if you are displaying a partition metric grouped by a column that is a boolean, Teal will display labels as "false" and "true". For this reason, Teal provides the label_for/1 callback that can be overriden on a partition metric to provide a custom label for each value.

Types

@type result() :: %{label: any(), value: float() | integer()}

Callbacks

@callback calculate(ExTeal.Metric.Request.t()) :: [result()]
@callback label_for(String.t()) :: String.t()

Often, the column values that divide your partition metrics into groups will be simple keys, and not something that is human readable. Or, if you are displaying a partition metric grouped by a column that is a boolean, Teal will display labels as "false" and "true". For this reason, Teal provides the label_for/1 callback that can be overriden on a partition metric to provide a custom label for each value.

@impl true
def label_for(false), do: "User"
def label_for(true), do: "Admin"

It's also useful for handling null values:

@impl true
def label_for(null), do: "None"
def label_for(key), do: String.capitalize(key)

Functions

Link to this function

aggregate(metric, query, aggregate, grouper, column)

View Source
@spec aggregate(
  metric :: module(),
  query :: Ecto.Queryable.t(),
  aggregate :: atom(),
  group_by :: atom(),
  column :: atom()
) :: [result()]
Link to this function

default_order_by(query, grouper)

View Source

By default sort the partition results by the group field