Skip to main content

Diagnostics

Decisions4s aims to help not only evaluate and visualize the decisions but also to understand them.

Results of evaluation carry all the information needed, such as:

  • Table that was evaluated
  • Input that was provided
  • Results of individual rules
import decisions4s.*

val decisionTable: DecisionTable[Input, Output, HitPolicy.Distinct] = ???
val input: Input[Value] = ???

decisionTable.evaluateDistinct(input).makeDiagnosticsString

Which produces a debug string containing

  • Name of the decision
  • Hit policy
  • Result of the evaluation
  • Input used
  • All the evaluated rules, including:
    • Their predicates
    • Predicates' results (satisfied or not)
    • Rule output

Example

Evaluation diagnostics for "PullRequestDecision"
Hit policy: First
Result: Some(Output(true,false))
Input:
numOfApprovals: 2
isTargetBranchProtected: true
authorIsAdmin: false
Rule 0 [✗]:
numOfApprovals [✓]: > 0
isTargetBranchProtected [✗]: false
authorIsAdmin [✓]: -
== ✗
Rule 1 [✓]:
numOfApprovals [✓]: > 1
isTargetBranchProtected [✓]: true
authorIsAdmin [✓]: -
== Output(allowMerging = true, notifyUnusualAction = false)

Customization

You can easily produce your own diagnostics format:

val diagData: DiagnosticsData = decisionTable.evaluateFirst(input).diagnosticsData
val output: String =
s"""${diagData.table.name}
| produced ${diagData.output.rawValue}
| using ${diagData.table.rules.size} rules""".stripMargin

To get something like this:

PullRequestDecision
produced Some(Output(true,false))
using 4 rules