ruleserver/ruleToformula.go
@@ -2,6 +2,7 @@
import (
   "encoding/json"
   "github.com/gogo/protobuf/proto"
   "ruleprocess/cache"
   "ruleprocess/logger"
   "sort"
@@ -9,6 +10,7 @@
   "strings"
   "time"
    bigCache "basic.com/pubsub/cache.git"
   "basic.com/pubsub/protomsg.git"
   "github.com/knetic/govaluate"
)
@@ -62,6 +64,7 @@
   IsYolo     bool    // 是否是yolo数据
   Location   Rect    // 记下每个目标的位置参数,最后给结果装配人脸数据的时候用的到
   SdkName    string
   Feature      []byte
   ThftRes    protomsg.ThftResult
   Liker      []*protomsg.Baseinfo
}
@@ -97,7 +100,7 @@
   IsYolo  bool    // 是否是yolo数据
   SdkName string
   ThftRes protomsg.ThftResult
   Liker   []*protomsg.Baseinfo // 如果是人脸的话尤其是比对,应存下他跟底库的人员的相似情况 yolo的话给nil就行
   Feature []byte
}
// 每个算法对于当前帧画面自己提取的数据
@@ -227,6 +230,42 @@
      }
   }
}
func Compare(args *SdkDatas, groupRule *protomsg.GroupRule) {
   compareFlag := false
   // 看看是否有只配人脸比对算法但没有配对比库的规则,如果有,则比对对象为全部底库
   for j := 0; j < len(groupRule.Rules); j++ {
      if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972"{
         if groupRule.Rules[j].SdkArgAlias == "对比底库" {
            compareFlag = true
         }
      }
   }
   if compareFlag {
      logger.Info("配置了对比底库参数")
   }else {
      logger.Info("没有配置对比底库参数")
   }
   for j := 0; j < len(groupRule.Rules); j++ {
      if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972" && groupRule.Rules[j].SdkArgAlias == "对比底库"{
         for _, sdkData := range args.Sdkdata {
            if sdkData.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" { // 搜索到人脸检测的sdkdata 现在关于人脸的只有他一个sdk,全找他
               for _, areaMap := range sdkData.AreaMapList {
                  // 拿区域中每个人脸特征值去对比,填充其liker
                  if groupRule.Rules[j].PolygonId == areaMap.areaId {
                     for _,arg := range areaMap.args {
                        bytes := bigCache.Getdbpersonmsg(string(arg.Feature),true)
                        binfos := protomsg.Binfos{}
                        proto.Unmarshal(bytes,&binfos)
                        arg.Liker = binfos.Infos
                        logger.Info("-------------------成功给liker赋值:",arg.Liker)
                     }
                  }
               }
            }
         }
      }
   }
}
func RunRule(args *SdkDatas, groupRule *protomsg.GroupRule, taskId string) bool {
   defer func() {
      if err := recover(); err != nil {
@@ -234,6 +273,7 @@
      }
   }()
   logger.Info("+++++++++++规则开始运行+++++++++++++++++当前规则--:", *groupRule)
   Compare(args,groupRule)
   resultSplice := []*LittleRuleResult{}
   // 先过完条件规则
   for j := 0; j < len(groupRule.Rules); j++ {
@@ -330,7 +370,7 @@
         // 配了人脸的算法才把人脸的数据甩出来打标签
         flag11 := false
         for j := 0; j < len(groupRule.Rules); j++ {
            if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a971" {
            if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972" {
               flag11 = true
            }
         }
@@ -396,7 +436,7 @@
func putFaceToResult(rule *protomsg.Rule, am *AreaMap) []Arg {
   faces := []Arg{}
   if rule.SdkId == am.sdkId && rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a971" {
   if rule.SdkId == am.sdkId && rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a972" {
      if len(am.filterData) > 0 {
         for _, data := range am.filterData {
            faces = append(faces, data)
@@ -409,7 +449,7 @@
func putYolosToResult(rule *protomsg.Rule, am *AreaMap) []Rect {
   locations := []Rect{}
   if rule.SdkId == am.sdkId && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a97e" && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a971" {
   if rule.SdkId == am.sdkId && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a97e" && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a972" {
      if len(am.filterData) > 0 {
         for _, data := range am.filterData {
            locations = append(locations, data.Location)
@@ -442,7 +482,7 @@
      if threshold <= obj.Score && size <= float64(obj.Rects.Width*obj.Rects.Height) && intersectionper <= PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) {
         // 这步要备齐表达式里所需要的所有参数
         a.targetNum++
         arg1 := Arg{obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.SdkName, obj.ThftRes, obj.Liker}
         arg1 := Arg{obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.SdkName, obj.Feature,obj.ThftRes,[]*protomsg.Baseinfo{}}
         //logger.Println("放进去的arg:-------", arg1)
         a.args = append(a.args, arg1)
         a.filterData = append(a.filterData, arg1)
@@ -592,14 +632,14 @@
func filterRule(rule *protomsg.Rule, am *AreaMap) LittleRuleResult {
   if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a972" {
      // 处理的是人脸算法 如果这条规则配置的是人脸算法,过滤完条件之后直接得出结果,因为肯定没有数量条件,自己拼接
      logger.Info("规则的算法id和区域的算法id:",rule.SdkId,"===",am.sdkId)
      logger.Error("规则的算法id和区域的算法id:",rule.SdkId,"===",am.sdkId)
      if rule.SdkId == am.sdkId && rule.PolygonId == am.areaId { // 算法和区域都得对的上
         if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a972" && rule.SdkArgAlias != "time_rule"{
            // 只需要过滤阈值,过滤完后数组长度大于0即为报警,但要考虑如何对每一张都报警呢
            argValue, err := strconv.ParseFloat(rule.SdkArgValue, 64)
            if err != nil {
               logger.Info("规则配置的阈值非法")
               logger.Error("规则配置的阈值非法")
               return LittleRuleResult{am.sdkName, rule.RuleWithPre + "" + "false", rule.Sort}
            }
            flag := "false"