| | |
| | | RuleText string // 文字版规则组 |
| | | Location []Rect // 目标的坐标 |
| | | AlarmPolygon string // 触发的报警框 |
| | | Others map[string]interface{} // cacheData: []ResultMsg,(本组规则中含有持续时间的规则开启的定时器缓存的数据帧),linkCache: []ResultMsg ,timeLabel: 00,01,10,11,12 |
| | | Others |
| | | } |
| | | |
| | | type Others struct { |
| | | CacheData []ResultMsg //(本组规则中含有持续时间的规则开启的定时器缓存的数据帧) |
| | | LinkCache []ResultMsg |
| | | TimeLabel string |
| | | } |
| | | // 过规则库打上的标签 |
| | | type FaceResult struct { |
| | | Result |
| | |
| | | taskId := taskGroup.TaskId |
| | | //logger.Println("------------本组任务下的规则组的数量:",len(ruleList)) |
| | | temp := group.Rules // temp为一组完整规则 在此需要判断规则是否是联动规则 |
| | | label := make(map[string]interface{}) |
| | | label := Others{} |
| | | if len(temp) > 0 { |
| | | if group.SetType != "linkTask" { |
| | | // 独立任务的处理 |
| | |
| | | taskId := taskGroup.TaskId |
| | | //logger.Println("------------本组任务下的规则组的数量:",len(ruleList)) |
| | | temp := group.Rules // temp为一组完整规则 在此需要判断规则是否是联动规则 |
| | | label := make(map[string]interface{}) |
| | | label := Others{} |
| | | if len(temp) > 0 { |
| | | if group.SetType == "linkTask" { |
| | | // groupId中含有link则为联动任务 |
| | |
| | | } |
| | | } |
| | | |
| | | func RunRule(args *SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage,label map[string]interface{}) bool { |
| | | func RunRule(args *SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage,label Others) bool { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | | logger.Error("比对规则有误", err.(string)) |
| | |
| | | } |
| | | } |
| | | // 进行定时器的处理和判断 |
| | | timeFlag := TimerAlarm(label, groupRule.GroupId, result.(bool)) |
| | | timeFlag := TimerAlarm(&label, groupRule.GroupId, result.(bool)) |
| | | if timeFlag == "01" || timeFlag == "10" || timeFlag == "11" { // 没有定时器或者满足定时器条件 |
| | | // 打人脸标签和yolo标签 |
| | | // 最后成功报警才把符合条件的人脸数据塞进结果标签里 |
| | |
| | | } |
| | | } |
| | | } |
| | | nihao := make(map[string]interface{}) |
| | | for k,v := range label{ |
| | | nihao[k] = v |
| | | } |
| | | //logger.Debug("------locations的内容:", locations) |
| | | if sdkNames != "" { |
| | | args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkNames, groupRule.GroupId,groupRule.DefenceState,groupRule.AlarmLevel, groupRule.GroupText, locations, polygonId,nihao}) |
| | | args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkNames, groupRule.GroupId,groupRule.DefenceState,groupRule.AlarmLevel, groupRule.GroupText, locations, polygonId,label}) |
| | | //logger.Info("-------------------yolo结果标签长度", len(args.RuleResult["yolo"].([]Result))) |
| | | } |
| | | if faceFlag { |
| | | args.RuleResult["face"] = append(args.RuleResult["face"].([]FaceResult), FaceResult{Result{taskId, sdkNames, groupRule.GroupId,groupRule.DefenceState,groupRule.AlarmLevel, groupRule.GroupText, []Rect{}, polygonId,nihao},faces}) |
| | | args.RuleResult["face"] = append(args.RuleResult["face"].([]FaceResult), FaceResult{Result{taskId, sdkNames, groupRule.GroupId,groupRule.DefenceState,groupRule.AlarmLevel, groupRule.GroupText, []Rect{}, polygonId,label},faces}) |
| | | //logger.Info("-------------------face结果标签", len(args.RuleResult["face"].([]FaceResult))) |
| | | } |
| | | return true |
| | |
| | | } |
| | | |
| | | // 联动任务的处理 |
| | | func LinkTask(args *SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage,label map[string]interface{}) { |
| | | func LinkTask(args *SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage,label Others) { |
| | | // new一个定时器,如果以此groupId为标志的定时器不存在的话 |
| | | logger.Info("------------------------------------------当前是联动任务,规则是:", groupRule.GroupText) |
| | | var flag bool = true |
| | |
| | | va.Result = strconv.FormatBool(isOk) |
| | | tempMap := make(map[string]interface{}) |
| | | for k,result := range args.RuleResult { |
| | | if k == "yolo" { |
| | | for _,res := range result.([]Result) { |
| | | tempMap[k] = append(tempMap[k].([]Result),res) |
| | | } |
| | | } |
| | | if k == "face" { |
| | | for _,res := range result.([]FaceResult) { |
| | | tempMap[k] = append(tempMap[k].([]FaceResult),res) |
| | | } |
| | | } |
| | | tempMap[k] = result |
| | | } |
| | | for _,result := range args.RuleResult["yolo"].([]Result) { |
| | | for k,_ := range result.Others { |
| | | logger.Warn("放进联动缓存的键是",k) |
| | | } |
| | | logger.Warn("放进联动缓存的长度是",len(result.LinkCache)) |
| | | } |
| | | va.CacheData = ResultMsg{message,tempMap} |
| | | logger.Info("这个摄像机--", args.CameraId, "--被赋予了result", va.Result) |
| | |
| | | if result.(bool) { |
| | | logger.Info("___________________________________________________________________联动任务报警") |
| | | // 把数组里缓存的数据取出来一起报警 |
| | | label["linkCache"] = []ResultMsg{} |
| | | label.LinkCache = []ResultMsg{} |
| | | for _, ruleRes := range TimeEleList[groupRule.GroupId].RuleResults { |
| | | label["linkCache"] = append(label["linkCache"].([]ResultMsg),ruleRes.CacheData) |
| | | label.LinkCache = append(label.LinkCache,ruleRes.CacheData) |
| | | } |
| | | logger.Debug("联动任务缓存了几个数据",len(label["linkCache"].([]ResultMsg))) |
| | | logger.Debug("联动任务缓存了几个数据",len(label.LinkCache)) |
| | | //for _,result := range args.RuleResult["yolo"].([]Result) { |
| | | // if result.RuleGroupId == groupRule.GroupId { |
| | | // result.Others["linkCache"] = label |
| | |
| | | //} |
| | | for i := 0; i < len(args.RuleResult["yolo"].([]Result)); i++ { |
| | | if args.RuleResult["yolo"].([]Result)[i].RuleGroupId == groupRule.GroupId { // 把原来那个删掉再存一份新的 |
| | | args.RuleResult["yolo"].([]Result)[i].Others["linkCache"] = label["linkCache"] |
| | | //res := args.RuleResult["yolo"].([]Result)[i] |
| | | //res.Others["linkCache"] = label["linkCache"] |
| | | //args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result)[:i],args.RuleResult["yolo"].([]Result)[i+1:]...) |
| | | //args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result),res) |
| | | args.RuleResult["yolo"].([]Result)[i].Others.LinkCache = label.LinkCache |
| | | } |
| | | } |
| | | } |