From b2f549332f6f890b252c3cc6abcbd35fdc6ae2e5 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期二, 09 七月 2019 11:09:08 +0800
Subject: [PATCH] 调整配置文件的引用位置

---
 ruleserver/ruleToformula.go |   83 +++++++++++++++++++++++++++++++++--------
 1 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/ruleserver/ruleToformula.go b/ruleserver/ruleToformula.go
index efda1eb..26e0430 100644
--- a/ruleserver/ruleToformula.go
+++ b/ruleserver/ruleToformula.go
@@ -2,6 +2,7 @@
 
 import (
 	"encoding/json"
+	"fmt"
 	"ruleprocess/cache"
 	"ruleprocess/logger"
 	"sort"
@@ -9,10 +10,13 @@
 	"strings"
 	"time"
 
+	bigCache "basic.com/pubsub/cache.git"
 	"basic.com/pubsub/protomsg.git"
 	"github.com/knetic/govaluate"
 )
-
+func init () {
+	bigCache.Init()
+}
 // 浠诲姟
 type Task struct {
 	camID     string //鎽勫儚鏈篒D
@@ -62,6 +66,7 @@
 	IsYolo     bool    // 鏄惁鏄痽olo鏁版嵁
 	Location   Rect    // 璁颁笅姣忎釜鐩爣鐨勪綅缃弬鏁帮紝鏈�鍚庣粰缁撴灉瑁呴厤浜鸿劯鏁版嵁鐨勬椂鍊欑敤鐨勫埌
 	SdkName    string
+	Feature    []byte
 	ThftRes    protomsg.ThftResult
 	Liker      []*protomsg.Baseinfo
 }
@@ -97,7 +102,7 @@
 	IsYolo  bool    // 鏄惁鏄痽olo鏁版嵁
 	SdkName string
 	ThftRes protomsg.ThftResult
-	Liker   []*protomsg.Baseinfo // 濡傛灉鏄汉鑴哥殑璇濆挨鍏舵槸姣斿锛屽簲瀛樹笅浠栬窡搴曞簱鐨勪汉鍛樼殑鐩镐技鎯呭喌 yolo鐨勮瘽缁檔il灏辫
+	Feature []byte
 }
 
 // 姣忎釜绠楁硶瀵逛簬褰撳墠甯х敾闈㈣嚜宸辨彁鍙栫殑鏁版嵁
@@ -227,6 +232,48 @@
 		}
 	}
 }
+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 == "compareBase" {
+				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 == "compareBase" {
+			for _, sdkData := range args.Sdkdata {
+				if sdkData.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" { // 鎼滅储鍒颁汉鑴告娴嬬殑sdkdata 鐜板湪鍏充簬浜鸿劯鐨勫彧鏈変粬涓�涓猻dk锛屽叏鎵句粬
+					for _, areaMap := range sdkData.AreaMapList {
+						// 鎷垮尯鍩熶腑姣忎釜浜鸿劯鐗瑰緛鍊煎幓瀵规瘮锛屽~鍏呭叾liker
+						if groupRule.Rules[j].PolygonId == areaMap.areaId {
+							for _, arg := range areaMap.args {
+								bytes := bigCache.Getdbpersonmsg("", arg.Feature, true)
+								var m map[string]float32
+								json.Unmarshal(bytes, &m)
+								for key, val := range m {
+									fmt.Println(key)
+									baseinfo := protomsg.Baseinfo{}
+									baseinfo.CompareScore = val
+									arg.Liker = append(arg.Liker, &baseinfo)
+								}
+								logger.Info("-------------------鎴愬姛缁檒iker璧嬪�硷細", arg.Liker)
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+}
 func RunRule(args *SdkDatas, groupRule *protomsg.GroupRule, taskId string) bool {
 	defer func() {
 		if err := recover(); err != nil {
@@ -234,6 +281,7 @@
 		}
 	}()
 	logger.Info("+++++++++++瑙勫垯寮�濮嬭繍琛�+++++++++++++++++褰撳墠瑙勫垯--锛�", *groupRule)
+	Compare(args, groupRule)
 	resultSplice := []*LittleRuleResult{}
 	// 鍏堣繃瀹屾潯浠惰鍒�
 	for j := 0; j < len(groupRule.Rules); j++ {
@@ -290,12 +338,12 @@
 	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 :]
+			completeFormula = completeFormula[2:]
 		}
 		if strings.HasPrefix(completeFormula, ">") || strings.HasPrefix(completeFormula, "<") {
-			completeFormula = completeFormula[1 :]
+			completeFormula = completeFormula[1:]
 		}
-		logger.Info("-------------------鐪嬬湅鎷旀瘺鍚庣殑琛ㄨ揪寮忥細",completeFormula)
+		logger.Info("-------------------鐪嬬湅鎷旀瘺鍚庣殑琛ㄨ揪寮忥細", completeFormula)
 		expression, _ := govaluate.NewEvaluableExpression(completeFormula)
 		result, _ := expression.Evaluate(nil) // 寰楀埌鏁板鍏紡鐨勭粨鏋�
 		return result.(bool)
@@ -315,7 +363,7 @@
 					timeEle.N = timeEle.InitN // 閲嶇疆瀹氭椂鍣�
 				}
 			}
-			logger.Info("--------------------璧拌繖閲屼簡鍚�---------------")
+			logger.Info("-------------------閲嶇疆瀹氭椂鍣ㄥ苟杩斿洖false---------------")
 			return false
 		} else {
 			// 鏈�鍚庢垚鍔熸姤璀︽墠鎶婄鍚堟潯浠剁殑浜鸿劯鏁版嵁濉炶繘缁撴灉鏍囩閲�
@@ -330,7 +378,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
 				}
 			}
@@ -378,7 +426,7 @@
 					//if flag11 {
 					//	args.RuleResult["face"] = faces
 					//}
-					args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkName, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText,locations})
+					args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkName, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText, locations})
 					logger.Info("-------------------yolo缁撴灉鏍囩", args.RuleResult["yolo"].([]Result))
 				}
 				if args.RuleResult["face"] != nil {
@@ -396,7 +444,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 +457,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 +490,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)
@@ -564,7 +612,7 @@
 						}
 					}
 					if sdkName != "" {
-						args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkName, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText,[]Rect{}})
+						args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkName, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText, []Rect{}})
 						logger.Info("-------------------yolo缁撴灉鏍囩", args.RuleResult["yolo"].([]Result))
 					}
 					if args.RuleResult["face"] != nil {
@@ -590,23 +638,24 @@
 
 // 杩囨护瑙勫垯鍏堢瓫閫夊嚭绗﹀悎鏉′欢鐨勭洰鏍囨暟閲�
 func filterRule(rule *protomsg.Rule, am *AreaMap) LittleRuleResult {
-	if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a971" {
+	if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a972" {
 		// 澶勭悊鐨勬槸浜鸿劯绠楁硶 濡傛灉杩欐潯瑙勫垯閰嶇疆鐨勬槸浜鸿劯绠楁硶锛岃繃婊ゅ畬鏉′欢涔嬪悗鐩存帴寰楀嚭缁撴灉锛屽洜涓鸿偗瀹氭病鏈夋暟閲忔潯浠讹紝鑷繁鎷兼帴
-
+		logger.Info("瑙勫垯鐨勭畻娉昳d鍜屽尯鍩熺殑绠楁硶id锛�", rule.SdkId, "===", am.sdkId)
 		if rule.SdkId == am.sdkId && rule.PolygonId == am.areaId { // 绠楁硶鍜屽尯鍩熼兘寰楀鐨勪笂
 
-			if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a971" && rule.SdkArgAlias != "time_rule"{
+			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"
 				for _, obj := range am.filterData {
 					for index := 0; index < len(obj.Liker); {
 						// 灏嗚揪涓嶅埌闃堝�肩殑鐩镐技鑰呬粠鐩镐技鑰呮暟缁勪腑鍒犻櫎
-						if float64(obj.Liker[index].CompareScore * 100) < argValue {
+						logger.Warn("=======================鐩镐技鍊硷細", float64(obj.Liker[index].CompareScore*100))
+						if float64(obj.Liker[index].CompareScore*100) < argValue {
 							// Go 璇█涓垏鐗囧垹闄ゅ厓绱犵殑鏈川鏄細浠ヨ鍒犻櫎鍏冪礌涓哄垎鐣岀偣锛屽皢鍓嶅悗涓や釜閮ㄥ垎鐨勫唴瀛橀噸鏂拌繛鎺ヨ捣鏉ャ�備笉鐢ㄦ��鐤戯紝鏁扮粍鍒犻櫎鍏冪礌灏辫繖涔堝潙鐖�
 							obj.Liker = append(obj.Liker[:index], obj.Liker[index+1:]...)
 						} else {

--
Gitblit v1.8.0