WPL.Enforce.RuleEvaluator (WPL Validator v1.9.0)

Copy Markdown View Source

Evaluates WPL personalization rules against a ClientContext.

Ported from wpl-validator-ts/src/enforce/rule-evaluator.ts. Fail-closed: unknown condition field → UNKNOWN_CONDITION_FIELD diagnostic (rule evaluates to not-met). Action without string type → UNKNOWN_ACTION_TYPE diagnostic.

ClientContext is a plain map with atom or string keys. Recognized fields: weight_kg, height_cm, age, sex, experience, injuries, equipment, fatigue, goals, cycle_day, cycle.

Summary

Functions

Return only the actions from rules whose condition was met.

Types

client_context()

@type client_context() :: map()

diagnostic()

@type diagnostic() :: %{
  code: String.t(),
  rule_id: String.t(),
  message: String.t(),
  meta: map()
}

evaluated_rule()

@type evaluated_rule() :: %{
  rule_id: String.t(),
  condition_met: boolean(),
  actions: [map()],
  condition: map() | nil
}

rule()

@type rule() :: map()

Functions

evaluate_rules(rules, ctx)

@spec evaluate_rules([rule()], client_context()) :: %{
  evaluated: [evaluated_rule()],
  diagnostics: [diagnostic()]
}

firing_actions(evaluated)

@spec firing_actions([evaluated_rule()]) :: [map()]

Return only the actions from rules whose condition was met.