View Source Sooth.Context (Sooth v0.5.0)

Provides the Context module for Sooth.

This module is mainly used for internal implementation details of the Sooth.Predictor module and should not be used directly.

Summary

Types

t()

A Context of id/count/statistics

Functions

Fetch a statistic in a context.

Find a statistic in a context.

Create a new context.

Observe an event in a context.

Convert a context to a list of statistics.

Types

@type t() :: %Sooth.Context{
  count: non_neg_integer(),
  id: non_neg_integer(),
  statistic_objects: map(),
  statistic_set: :gb_sets.set()
}

A Context of id/count/statistics

Functions

Link to this function

fetch_statistic(context, event)

View Source
@spec fetch_statistic(t(), non_neg_integer()) :: {:ok, Sooth.Statistic.t()} | :error

Fetch a statistic in a context.

This is an implementation detail and should not be used directly.

Examples

iex> context = Sooth.Context.new(0)
iex> Sooth.Context.fetch_statistic(context, 3)
:error
iex> {context, _} = Sooth.Context.observe(context, 3)
iex> Sooth.Context.fetch_statistic(context, 3)
{:ok, %Sooth.Statistic{count: 1, event: 3}}
Link to this function

find_statistic(context, event)

View Source
@spec find_statistic(t(), non_neg_integer()) :: Sooth.Statistic.t() | nil

Find a statistic in a context.

This is an implementation detail and should not be used directly.

@spec new(non_neg_integer()) :: t()

Create a new context.

Examples

iex> Sooth.Context.new(0)
#Sooth.Context<id: 0, count: 0, statistic_set: [], statistic_objects: %{}>
@spec observe(t(), non_neg_integer()) :: {t(), Sooth.Statistic.t()}

Observe an event in a context.

Examples

iex> context = Sooth.Context.new(0)
iex> {context, _} = Sooth.Context.observe(context, 3)
iex> context
#Sooth.Context<id: 0, count: 1, statistic_set: [3], statistic_objects: %{3 => %Sooth.Statistic{count: 1, event: 3}}>
@spec to_list(t()) :: [Sooth.Statistic.t()]

Convert a context to a list of statistics.

Examples

iex> context = Sooth.Context.new(0)
iex> Sooth.Context.to_list(context)
[]
iex> {context, _} = Sooth.Context.observe(context, 3)
iex> Sooth.Context.to_list(context)
[%Sooth.Statistic{count: 1, event: 3}]