-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.go
More file actions
99 lines (88 loc) · 2.5 KB
/
models.go
File metadata and controls
99 lines (88 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package coffeemachine
import (
"github.com/anshal21/coffee-machine/expressions"
"github.com/anshal21/coffee-machine/lib/models"
)
const (
OutputTypeExpression = "EXPR"
OutputTypeConstant = "CONST"
)
// Rule is an in-memory represent of a rule
// defined in the rule-set
// It consists of rule-id, associated predicate
// ans a list of post-evals
type Rule struct {
ID string
Predicate expressions.Expression
PostEvals []*RulePostEval
}
// RulePostEval is an expression or constant
// that is calculated if the associated rule
// evaluates to true
// The calculated value is returned in the
// response
type RulePostEval struct {
ID string
Type string
Const string
Evaluable expressions.Expression
Echo bool
}
// Node represents a node in the rule-graph
// it consists of a rule and any edges / relations
// with other rules
type Node struct {
Rule *Rule
Relations []*Edge
}
// Edge is a struct to represent a relation
// between two rules in the dependency graph
type Edge struct {
Destination *Node
ForwardOutput bool
}
// RuleGraph is a dependency graph representation
// of the rule-set
type RuleGraph struct {
ID string
Root *Node
Constants []interface{}
}
// RuleEngineRequest is a struct that holds
// the input parameters required for the
// evaluation and the response criteria
type RuleEngineRequest struct {
// map[string]interface{} contains the values for the variables
// in the predicates defined in the rule-engine
Variables map[string]interface{}
// EvaluatedCount, If true, response contains the count of rules that were
// evaluated
EvaluatedCount bool
// EvaluatedTrueCount, If true, response contais the count of rules that
// evaluated to true
EvaluatedTrueCount bool
// EvaluatedRules, If true, output contains the rule-ids of the evaluated rules
EvaluatedRules bool
}
// EvaluationOutput contains evaluation output for a expression
// It is used to hold the values of the PostEvals calculations
type EvaluationOutput struct {
ID string
Value models.Value
Type models.DataType
}
// RuleOutput is a struct to hold the result of a rule evaluation
// It contains the RuleID and evaluation response for all
// the associated post-evals
type RuleOutput struct {
ID string
PostEvals []*EvaluationOutput
}
// RuleEngineResponse is a struct that holds the response for a
// rule-engine Run
type RuleEngineResponse struct {
RulesEvaluated int
RulesEvaluatedTrue int
Outputs []*RuleOutput
EvaluatedRules []string
}