AshDyan.Analysis behaviour (AshDyan v0.3.0)

Copy Markdown View Source

Behaviour for a single analysis capability (frequency, aggregate, time_bucket, percentile, histogram, ...).

AshDyan's analysis types were previously a closed sum type scattered across parallel case/when clauses in AshDyan.Request, AshDyan.Engine, AshDyan.Engine.Formatter, and AshDyan.Charts. Implementing this behaviour and registering the module under config :ash_dyan, :analysis_types lets a downstream app add a new analysis type (e.g. :funnel, :cohort) without forking AshDyan.

Example

defmodule MyApp.AshDyan.Funnel do
  @behaviour AshDyan.Analysis
  # ... implement the four callbacks ...
end

# config/config.exs
config :ash_dyan, :analysis_types, %{funnel: MyApp.AshDyan.Funnel}

The request's :type is the registry key.

Summary

Callbacks

format(t, list)

@callback format(AshDyan.Request.t(), [Ash.Resource.Record.t()]) ::
  {:ok, AshDyan.Result.t()} | {:error, term()}

recommend_chart(t)

@callback recommend_chart(AshDyan.Result.t()) :: AshDyan.Charts.chart_type()

select_fields(t)

@callback select_fields(AshDyan.Request.t()) :: [atom()]

supports_presentation?(atom)

@callback supports_presentation?(atom()) :: boolean()

validate(t)

@callback validate(AshDyan.Request.t()) :: :ok | {:error, AshDyan.Error.t()}

Functions

supports_presentation?(option)