Skip to content

Commit

Permalink
Merge pull request #20 from skyhackvip/optimize/1
Browse files Browse the repository at this point in the history
define const
  • Loading branch information
skyhackvip authored Feb 22, 2024
2 parents 336ffbe + 838ecdf commit 27ec096
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tags
dist/
22 changes: 12 additions & 10 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ type AppConf struct {
DslLoadPath string `yaml:"DslLoadPath"`
}

//策略
type Strategy struct {
Name string `yaml:"name"`
Priority int `yaml:"priority"` //越大越优先
Score int `yaml:"score"` //策略分
}

func LoadConfig(path string) (*Conf, error) {
conf := new(Conf)
file, err := ioutil.ReadFile(path)
Expand All @@ -57,8 +50,17 @@ func LoadConfig(path string) (*Conf, error) {
return conf, nil
}

//策略
type Strategy struct {
Name string `yaml:"name"`
Priority int `yaml:"priority"` //越大越优先
Score int `yaml:"score"` //策略分
}

//keywords for execute
const (
CONSOLE = "console"
FILE = "file"
DB = "db"
CONSOLE = "console"
FILE = "file"
DB = "db"
PARALLEL = "parallel"
)
4 changes: 2 additions & 2 deletions configs/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ const (
RULESET = "ruleset"
ABTEST = "abtest"
CONDITIONAL = "conditional"
DECISIONTREE = "decisiontree"
DECISIONMATRIX = "decisionmatrix"
DECISIONTREE = "tree"
DECISIONMATRIX = "matrix"
SCORECARD = "scorecard"
)

Expand Down
36 changes: 20 additions & 16 deletions core/inode.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
//
package core

import (
"github.com/skyhackvip/risk_engine/configs"
)

//各类型节点实现该接口
type INode interface {
GetName() string
Expand Down Expand Up @@ -51,29 +55,29 @@ const (
)

var nodeStrMap = map[NodeType]string{
TypeStart: "start",
TypeEnd: "end",
TypeRuleset: "ruleset",
TypeAbtest: "abtest",
TypeConditional: "conditional",
TypeTree: "tree",
TypeMatrix: "matrix",
TypeScorecard: "scorecard",
TypeStart: configs.START,
TypeEnd: configs.END,
TypeRuleset: configs.RULESET,
TypeAbtest: configs.ABTEST,
TypeConditional: configs.CONDITIONAL,
TypeTree: configs.DECISIONTREE,
TypeMatrix: configs.DECISIONMATRIX,
TypeScorecard: configs.SCORECARD,
}

func (nodeType NodeType) String() string {
return nodeStrMap[nodeType]
}

var nodeTypeMap map[string]NodeType = map[string]NodeType{
"start": TypeStart,
"end": TypeEnd,
"ruleset": TypeRuleset,
"abtest": TypeAbtest,
"conditional": TypeConditional,
"tree": TypeTree,
"matrix": TypeMatrix,
"scorecard": TypeScorecard,
configs.START: TypeStart,
configs.END: TypeEnd,
configs.RULESET: TypeRuleset,
configs.ABTEST: TypeAbtest,
configs.CONDITIONAL: TypeConditional,
configs.DECISIONTREE: TypeTree,
configs.DECISIONMATRIX: TypeMatrix,
configs.SCORECARD: TypeScorecard,
}

func GetNodeType(name string) NodeType {
Expand Down
2 changes: 1 addition & 1 deletion core/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (matrixNode MatrixNode) Parse(ctx *PipelineContext) (*NodeResult, error) {
var xResult string
var yResult string

if matrixNode.ExecPlan == "parallel" { //并发分组执行
if matrixNode.ExecPlan == configs.PARALLEL { //并发分组执行
ruleMap := make(map[string][]Rule)
for _, rule := range matrixNode.Rules {
if rule.Kind == configs.MATRIXX {
Expand Down
2 changes: 1 addition & 1 deletion core/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (rulesetNode RulesetNode) Parse(ctx *PipelineContext) (*NodeResult, error)
//ruleset 批量调用特征
depends := ctx.GetFeatures(info.Depends)

if rulesetNode.ExecPlan == "parallel" { //并发执行规则
if rulesetNode.ExecPlan == configs.PARALLEL { //并发执行规则
var wg sync.WaitGroup
var mu sync.Mutex
for _, rule := range rulesetNode.Rules {
Expand Down

0 comments on commit 27ec096

Please sign in to comment.