| | |
| | | "github.com/knetic/govaluate" |
| | | "plugin" |
| | | "ruleprocess/cache" |
| | | "ruleprocess/ruleserver" |
| | | "ruleprocess/structure" |
| | | "sort" |
| | | "strings" |
| | | "time" |
| | | ) |
| | | |
| | | func Entrance (args *structure.SdkDatas,groupRule protomsg.GroupRule) ([]*structure.LittleRuleResult,string,string){ |
| | | func Entrance (args *structure.SdkDatas,groupRule protomsg.GroupRule,lable *structure.Others,message *protomsg.SdkMessage) (bool,string,string){ |
| | | resultSplice := []*structure.LittleRuleResult{} |
| | | sdkNames := "" |
| | | polygonId := "" |
| | |
| | | if ipcId == sdkData.IpcId { |
| | | //logger.Info("当前走的规则是--:", sdkName, "---","") |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | ruleResult := CallSo(sdk.Id, groupRule.Rules[j], areaMap) |
| | | ruleResult := CallSo(sdk.Id, groupRule.Rules[j], areaMap,lable,args,message) |
| | | if ruleResult.Result != "" { |
| | | logger.Info("条件规则结果:", ruleResult.Result) |
| | | // 如果结果为真,把这条规则中的区域置为有效 |
| | |
| | | } |
| | | } |
| | | } |
| | | // 人脸 |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972" && groupRule.Rules[j].SdkArgAlias != "time_rule"{ |
| | | for _, sdkData := range args.Sdkdata { |
| | |
| | | if ipcId == sdkData.IpcId { |
| | | //logger.Info("当前走的规则是--:", sdkName, "---","") |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | ruleResult := CallSo(sdk.Id, groupRule.Rules[j], areaMap) |
| | | ruleResult := CallSo(sdk.Id, groupRule.Rules[j], areaMap,lable,args,message) |
| | | if ruleResult.Result != "" { |
| | | logger.Info("人脸比对规则结果:", ruleResult.Result) |
| | | // 如果结果为真,把这条规则中的区域置为有效 |
| | | if strings.Contains(ruleResult.Result, "true") { |
| | | areaMap.IsEffective = true |
| | | } |
| | | // 如果此结果为真且当前过的是yolo算法,应记下此规则所对应的sdkName,另外,还要去重 (后加:把此条触碰的区域id也记录下来) |
| | | if strings.Contains(ruleResult.Result, "true") && ipcId == "02D54B61-0F16-C604-8567-FC4BE493C523" && !strings.Contains(sdkNames, sdkName) { |
| | | sdkNames = sdkName + " " |
| | | } |
| | | if strings.Contains(ruleResult.Result, "true") && ipcId == "02D54B61-0F16-C604-8567-FC4BE493C523" && !strings.Contains(polygonId, groupRule.Rules[j].PolygonId) { |
| | | polygonId += groupRule.Rules[j].PolygonId + "," |
| | | } |
| | | resultSplice = append(resultSplice, &ruleResult) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 个体静止 |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | if groupRule.Rules[j].SdkId == "个体静止" && groupRule.Rules[j].SdkArgAlias != "time_rule"{ |
| | | for _, sdkData := range args.Sdkdata { |
| | | // 根据规则的sdkId查出其对应的ipcId,用ipcId去找该比对的数据 |
| | | sdk, err := cache.GetSdkById(groupRule.Rules[j].SdkId) |
| | | if err != nil { |
| | | logger.Error("没查到sdk的信息---", err) |
| | | } |
| | | ipcId := sdk.IpcId |
| | | sdkName := sdk.SdkName |
| | | //logger.Info("规则的ipcId与sdkData的IpcId:", ipcId, "===", sdkData.IpcId) |
| | | if ipcId == sdkData.IpcId { |
| | | //logger.Info("当前走的规则是--:", sdkName, "---","") |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | ruleResult := CallSo(sdk.Id, groupRule.Rules[j], areaMap,lable,args,message) |
| | | if ruleResult.Result != "" { |
| | | logger.Info("个体静止结果:", ruleResult.Result) |
| | | // 如果结果为真,把这条规则中的区域置为有效 |
| | | if strings.Contains(ruleResult.Result, "true") { |
| | | areaMap.IsEffective = true |
| | |
| | | sdkName := sdk.SdkName |
| | | if ipcId == sdkData.IpcId { |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | ruleResult := CallSo(sdk.Id, groupRule.Rules[j], areaMap) |
| | | ruleResult := CallSo(sdk.Id, groupRule.Rules[j], areaMap,lable,args,message) |
| | | if ruleResult.Result != "" { |
| | | if strings.Contains(ruleResult.Result, "true") { |
| | | areaMap.IsEffective = true |
| | |
| | | } |
| | | } |
| | | } |
| | | return resultSplice,sdkNames,polygonId |
| | | // 将数组按sort排序 |
| | | sort.Sort(ruleserver.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) // 得到数学公式的结果 |
| | | return result.(bool),sdkNames,polygonId |
| | | } else { |
| | | return false,sdkNames,polygonId |
| | | } |
| | | } |
| | | |
| | | func timeRuleResult(rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult { |
| | |
| | | return structure.LittleRuleResult{} |
| | | } |
| | | |
| | | func CallSo(sdkId string,rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult{ |
| | | func CallSo(sdkId string,rule *protomsg.Rule, am *structure.AreaMap,lable *structure.Others,args *structure.SdkDatas,message *protomsg.SdkMessage) structure.LittleRuleResult{ |
| | | // 根据sdkId查出其对应的sdk的soName,调用相应so的Entrance方法 |
| | | var soName = "" |
| | | if sdkId == "812b674b-2375-4589-919a-5c1c3278a97e" { |
| | |
| | | soName = "personUnsual.so" |
| | | } else if sdkId == "812b674b-2375-4589-919a-5c1c3278a972" { |
| | | soName = "faceCompare.so" |
| | | } else if sdkId == "个体静止" { |
| | | soName = "static.so" |
| | | } |
| | | //soInfo,errr := cache.GetSoInfoById(sdkId) |
| | | //if errr != nil { |
| | |
| | | if err1 != nil { |
| | | panic("没有找到入口函数") |
| | | } |
| | | ruleResult := f.(func(rule *protomsg.Rule, am *structure.AreaMap)structure.LittleRuleResult)(rule,am) |
| | | ruleResult := f.(func(rule *protomsg.Rule, am *structure.AreaMap,lable *structure.Others, args *structure.SdkDatas,message *protomsg.SdkMessage)structure.LittleRuleResult)(rule,am,lable,args,message) |
| | | return ruleResult |
| | | } |
| | | |