| | |
| | | "ruleprocess/structure" |
| | | "sort" |
| | | "strconv" |
| | | "strings" |
| | | "sync" |
| | | ) |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | func CallMiddleware(args *structure.SdkDatas,rule protomsg.GroupRule) ([]*structure.LittleRuleResult, string, string){ |
| | | func CallMiddleware(args *structure.SdkDatas,rule protomsg.GroupRule) (bool, string, string){ |
| | | p,err := plugin.Open("./algorithm/middleware.so") |
| | | if err != nil { |
| | | panic(err) |
| | |
| | | if err1 != nil { |
| | | panic("没有找到中间件入口函数") |
| | | } |
| | | a,b,c := f.(func(args *structure.SdkDatas,rule protomsg.GroupRule)([]*structure.LittleRuleResult, string, string))(args,rule) |
| | | a,b,c := f.(func(args *structure.SdkDatas,rule protomsg.GroupRule)(bool, string, string))(args,rule) |
| | | return a,b,c |
| | | } |
| | | |
| | |
| | | logger.Info("+++++++++++规则开始运行+++++++++++++++++当前大规则--:", (*groupRule).GroupText) |
| | | //logger.Warn("传进去之后是什么德行:",args.RuleResult["yolo"]) |
| | | Compare(args, groupRule) |
| | | resultSplice := []*structure.LittleRuleResult{} |
| | | result := false |
| | | sdkNames := "" |
| | | polygonId := "" |
| | | resultSplice,sdkNames,polygonId = CallMiddleware(args,*groupRule) |
| | | // 将数组按sort排序 |
| | | sort.Sort(resultList(resultSplice)) |
| | | // 排序后取各自的结果和连接符拼出规则表达式得出结果 |
| | | completeFormula := "" |
| | | for _, va := range resultSplice { |
| | | completeFormula = completeFormula + va.Result |
| | | } |
| | | if strings.HasPrefix(completeFormula, "&&") || strings.HasPrefix(completeFormula, "||") || strings.HasPrefix(completeFormula, ">=") || strings.HasPrefix(completeFormula, "<=") || strings.HasPrefix(completeFormula, "==") || strings.HasPrefix(completeFormula, "!=") || strings.HasPrefix(completeFormula, ">") || strings.HasPrefix(completeFormula, "<") { |
| | | // 以这些开头的基本是联动任务 |
| | | if strings.HasPrefix(completeFormula, "&&") || strings.HasPrefix(completeFormula, "||") || strings.HasPrefix(completeFormula, ">=") || strings.HasPrefix(completeFormula, "<=") || strings.HasPrefix(completeFormula, "==") || strings.HasPrefix(completeFormula, "!=") { |
| | | completeFormula = completeFormula[2:] |
| | | } |
| | | if strings.HasPrefix(completeFormula, ">") || strings.HasPrefix(completeFormula, "<") { |
| | | completeFormula = completeFormula[1:] |
| | | } |
| | | logger.Info("-------------------看看拔毛后的表达式:", completeFormula) |
| | | //expression, _ := govaluate.NewEvaluableExpression(completeFormula) |
| | | //result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | | //return result.(bool) |
| | | } |
| | | if completeFormula != "" { |
| | | logger.Info("结果公式-----------:", completeFormula) |
| | | expression, err2 := govaluate.NewEvaluableExpression(completeFormula) |
| | | if strings.HasPrefix(completeFormula, "&&") || strings.HasPrefix(completeFormula, "||") || err2 != nil { |
| | | panic("规则有误,得到的数学公式不可解析") |
| | | } |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | | // 把一帧数据和一组规则发给算法部分,得出判断结果 |
| | | result,sdkNames,polygonId = CallMiddleware(args,*groupRule) |
| | | |
| | | if result.(bool) { |
| | | if result { |
| | | // 最后过持续时间等时间维度的条件 把时间规则位置调整到这个位置是为了缓存数据 |
| | | cacheId := "" |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | |
| | | } |
| | | } |
| | | // 进行定时器的处理和判断 |
| | | timeFlag := TimerAlarm(&label, groupRule.GroupId, result.(bool)) |
| | | timeFlag := TimerAlarm(&label, groupRule.GroupId, result) |
| | | if timeFlag == "01" || timeFlag == "10" || timeFlag == "11" || cacheId != ""{ // 没有定时器或者满足定时器条件 |
| | | // 打人脸标签和yolo标签 |
| | | // 最后成功报警才把符合条件的人脸数据塞进结果标签里 |
| | |
| | | |
| | | } else { |
| | | // 结果为假时也要走,有杀死定时器的操作 |
| | | TimerAlarm(&label, groupRule.GroupId, result.(bool)) |
| | | TimerAlarm(&label, groupRule.GroupId, result) |
| | | //fmt.Println(timeFlag) |
| | | return false,[]int{} |
| | | } |
| | | } else { |
| | | return false,[]int{} |
| | | } |
| | | } |