panlei
2019-06-25 514f2fb736939adbe3cebba4f33f881c26a7d512
ruleserver/ruleToformula.go
@@ -60,6 +60,12 @@
   score      float64 // 区域内的目标的相似度
   proportion float64 // 区域内的目标的占比
   size       float64 // 区域内的目标的尺寸
   liker      []LikePerson
}
type LikePerson struct {
   Id    string  // 与之相似的底库人员的id
   Score float64 // 与底库人员的相似值
}
// 每个区域内的图片数据集合
@@ -83,7 +89,8 @@
// sdk输出的图片上单个目标的数据
type PhotoMap struct {
   Rects Rect    // 矩形区域参数
   Score float64 // 相似度得分
   Score float64 // 相似度得分(有多大程度像一个目标。人脸,人体或车等等)
   Liker []LikePerson // 如果是人脸的话尤其是比对,应存下他跟底库的人员的相似情况 yolo的话给nil就行
}
// 从通道中获取的sdk输出的图像数据(目前主要是yolo算法的数据)
@@ -110,7 +117,7 @@
type Result struct {
   TaskId      string // 任务id
   RuleGroupId string // 规则组id
   AlarmLevel  int32 // 报警等级
   AlarmLevel  int32  // 报警等级
   RuleText    string // 文字版规则组
}
@@ -188,11 +195,17 @@
// 将字符串格式的坐标序列化为Point格式
func Json2points(areaPoints string) []Point {
   var pts []Point
   err := json.Unmarshal([]byte(areaPoints), &pts)
   if err != nil {
      fmt.Println("json.Unmarshal错误", err)
      panic("序列化坐标异常,程序退出")
   if areaPoints == "" {
      pts = append(pts, Point{0, 0})
      pts = append(pts, Point{0, 540})
      pts = append(pts, Point{960, 540})
      pts = append(pts, Point{960, 0})
   } else {
      err := json.Unmarshal([]byte(areaPoints), &pts)
      if err != nil {
         fmt.Println("json.Unmarshal错误", err)
         panic("序列化坐标异常,程序退出")
      }
   }
   return pts
}
@@ -295,19 +308,26 @@
func singleTask(aml *AreaMapList, arg *ArgsFromSdk, groupRule *protomsg.GroupRule, taskId string) bool {
   var completeFormula string = ""
   for _, areaMap := range aml.areaMapList {
      //fmt.Println("当前规则组为---------:",groupRule)
      for j := 0; j < len(groupRule.Rules); j++ {
         // 先过完条件数据
         filterRule(groupRule.Rules[j], &areaMap)
      }
      for j := 0; j < len(groupRule.Rules); j++ {
         // 再过其他数据 这步直接得到结果(真或假)
         // 再过其他数据 这步直接得到结果(真或假) 过目标数量
         flag := transferParameters(groupRule.Rules[j], &areaMap)
         if flag != "" {
            fmt.Println("得出的结果", flag)
            completeFormula = completeFormula + groupRule.Rules[j].RuleWithPre + "" + flag
         }
      }
      if completeFormula == "" {
         flag := splice1(&areaMap)
         if flag != "" {
            fmt.Println("强行拼凑一个人数是否大于0的结果", flag)
            completeFormula = flag
         }
      }
      for j := 0; j < len(groupRule.Rules); j++ {
         // 这步过的是时间规则(时间段等)
         flag := timeRuleResult(groupRule.Rules[j], &areaMap)
@@ -316,10 +336,12 @@
            completeFormula = completeFormula + groupRule.Rules[j].RuleWithPre + "" + flag
         }
      }
      for j := 0; j < len(groupRule.Rules); j++ {
         // 最后过持续时间等时间维度的条件
         duration(groupRule.Rules[j], &areaMap)
      }
   }
   fmt.Println("拼出的数学公式为:==== ", completeFormula)
   if completeFormula != "" {
@@ -347,7 +369,7 @@
         if flag {
            fmt.Println("定时器报警了")
            // 过完规则后打个标签,告诉调用者本帧数据针对哪个任务哪组规则报警了
            arg.RuleResult = append(arg.RuleResult, Result{taskId, groupRule.GroupId,groupRule.AlarmLevel,groupRule.GroupText})
            arg.RuleResult = append(arg.RuleResult, Result{taskId, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText})
            return true
         } else {
            return false
@@ -411,7 +433,6 @@
            }
         }
         am.targetNum = len(am.filterData) // 把符合条件的目标数量更新到targetNum字段
         //fmt.Println("筛选完后的内容:", am)
      }
   }
}
@@ -438,6 +459,15 @@
         }
      }
   }
}
// 冗余拼接
func splice1(am *AreaMap) string {
   args := am.targetNum
   formula := strconv.Itoa(args) + " " + ">" + "0"
   expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式
   result, _ := expression.Evaluate(nil)                      // 得到数学公式的结果
   return strconv.FormatBool(result.(bool))
}
// 给数据库的规则表达式代参 args: 一条子规则,区域数据
@@ -469,10 +499,13 @@
      } else if rule.SdkId == "FaceDetect" { // 人脸检测
         if rule.Operator == "==" || rule.Operator == ">=" || rule.Operator == "<=" || rule.Operator == "<" || rule.Operator == ">" || rule.Operator == "!=" {
            // 如果是不规矩的连接符统统返回false 规则也只能判断人脸的相似度,所以不存在别的连接符
            return "false"
         } else {
            return "false"
         }
      } else if rule.SdkId == "FaceCompare"{
      }
   }