panlei
2019-11-30 54c923158d991c0db54307cef60a96ed0b7ac410
algorithm/intrusion/intrusion.go
@@ -2,14 +2,14 @@
import (
   "basic.com/pubsub/protomsg.git"
   "basic.com/valib/logger.git"
   logger "github.com/alecthomas/log4go"
   "github.com/knetic/govaluate"
   "ruleprocess/structure"
   "strconv"
)
//入侵算法
func Entrance(rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult {
func Entrance(rule *protomsg.Rule, am *structure.AreaMap,lable *structure.Others,args *structure.SdkDatas,message *protomsg.SdkMessage) structure.LittleRuleResult {
   if rule.PolygonId == am.AreaId { // 首先这条规则得是这个算法的规则,其次规则所对应的区域id要跟区域数据的id对的上
      return filterRule(rule, am)
   } else {
@@ -21,7 +21,7 @@
func filterRule(rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult {
   // 处理的都是yolo数据
   if rule.SdkArgAlias == "score" || rule.SdkArgAlias == "proportion" || rule.SdkArgAlias == "size" { // 判断的是相似值,占比,尺寸等过滤条件,如果再有,还可以再加
      logger.Debug("---------走了入侵算法",rule.Id,rule.SdkArgAlias,rule.Operator,rule.SdkArgValue,am.AreaId)
      //logger.Debug("---------走了入侵算法",rule.Id,rule.SdkArgAlias,rule.Operator,rule.SdkArgValue,am.AreaId)
      var args []*structure.Arg
      if rule.RuleWithPre == "&&" {
         args = am.FilterData
@@ -33,15 +33,16 @@
      //logger.Debug("看看args:::::", args)
      for _, arg := range args {
         var formula string
         if rule.SdkArgAlias == "score" {
            formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式
            logger.Info("当前相似度小公式:", formula)
         } else if rule.SdkArgAlias == "proportion" {
            formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式
            logger.Info("当前占比小公式:", formula)
         } else {
            formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式
            logger.Info("当前尺寸小公式:", formula)
         switch rule.SdkArgAlias {
            case "score":
               formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue
               //logger.Info("相似度小公式:", formula)
            case "proportion":
               formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue
               //logger.Info("占比公式:", formula)
            case "size":
               formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue
               //logger.Info("尺寸小公式:", formula)
         }
         expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式
         result, _ := expression.Evaluate(nil)                      // 得到数学公式的结果