From 2c233372d3352bc6967d265caf85260d6fce4fb7 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期四, 04 七月 2019 15:04:10 +0800
Subject: [PATCH] 调整一下切的长度

---
 ruleserver/ruleToformula.go |   94 ++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 72 insertions(+), 22 deletions(-)

diff --git a/ruleserver/ruleToformula.go b/ruleserver/ruleToformula.go
index c7e3667..9c3f5b5 100644
--- a/ruleserver/ruleToformula.go
+++ b/ruleserver/ruleToformula.go
@@ -138,6 +138,7 @@
 	RuleGroupId string // 瑙勫垯缁刬d
 	AlarmLevel  int32  // 鎶ヨ绛夌骇
 	RuleText    string // 鏂囧瓧鐗堣鍒欑粍
+	Location    []Rect
 }
 type LittleRuleResult struct {
 	SdkName string // 璁板綍涓嬫缁撴灉鏄摢涓猻dk鐨勭粨鏋�
@@ -217,7 +218,7 @@
 					if len(temp) > 0 {
 						if ruleList[i].SetType == "linkTask" {
 							// groupId涓惈鏈塴ink鍒欎负鑱斿姩浠诲姟
-							//LinkTask(args, ruleList[i], taskId)
+							LinkTask(args, ruleList[i], taskId)
 						} else {
 							// 鐙珛浠诲姟鐨勫鐞�
 							RunRule(args, ruleList[i], taskId)
@@ -248,25 +249,7 @@
 			}
 		}
 	}
-	// 杩囧畬鏉′欢鏁版嵁鍚庢妸绗﹀悎鏉′欢鐨勪汉鑴告暟鎹杩涚粨鏋滄爣绛鹃噷
-	faces := []Arg{}
-	for _, sdkData := range args.Sdkdata {
-		for _, areaMap := range sdkData.AreaMapList {
-			for j := 0; j < len(groupRule.Rules); j++ {
-				faces = append(faces, putFaceToResult(groupRule.Rules[j], &areaMap)...)
-			}
-		}
-	}
-	// 閰嶄簡浜鸿劯鐨勭畻娉曟墠鎶婁汉鑴哥殑鏁版嵁鐢╁嚭鏉ユ墦鏍囩
-	flag := 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" {
-			flag = true
-		}
-	}
-	if flag {
-		args.RuleResult["face"] = faces
-	}
+
 	// 鍐嶈繃鍏朵粬鏁版嵁 杩欐鐩存帴寰楀埌缁撴灉锛堢湡鎴栧亣锛� 杩囩洰鏍囨暟閲�
 	for j := 0; j < len(groupRule.Rules); j++ {
 		for _, sdkData := range args.Sdkdata {
@@ -306,6 +289,19 @@
 	for _, va := range resultSplice {
 		completeFormula = completeFormula + va.Result
 	}
+	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 :]
+		}
+		if strings.HasPrefix(completeFormula, ">") || strings.HasPrefix(completeFormula, "<") {
+			completeFormula = completeFormula[1 :]
+		}
+		log.Println("-------------------鐪嬬湅鎷旀瘺鍚庣殑琛ㄨ揪寮忥細",completeFormula)
+		expression, _ := govaluate.NewEvaluableExpression(completeFormula)
+		result, _ := expression.Evaluate(nil) // 寰楀埌鏁板鍏紡鐨勭粨鏋�
+		return result.(bool)
+	}
 	if completeFormula != "" {
 		log.Println("缁撴灉鍏紡-----------锛�", completeFormula)
 		expression, _ := govaluate.NewEvaluableExpression(completeFormula)
@@ -321,8 +317,28 @@
 					timeEle.N = timeEle.InitN // 閲嶇疆瀹氭椂鍣�
 				}
 			}
+			log.Println("--------------------璧拌繖閲屼簡鍚�---------------")
 			return false
 		} else {
+			// 鏈�鍚庢垚鍔熸姤璀︽墠鎶婄鍚堟潯浠剁殑浜鸿劯鏁版嵁濉炶繘缁撴灉鏍囩閲�
+			faces := []Arg{}
+			for _, sdkData := range args.Sdkdata {
+				for _, areaMap := range sdkData.AreaMapList {
+					for j := 0; j < len(groupRule.Rules); j++ {
+						faces = append(faces, putFaceToResult(groupRule.Rules[j], &areaMap)...)
+					}
+				}
+			}
+			// 閰嶄簡浜鸿劯鐨勭畻娉曟墠鎶婁汉鑴哥殑鏁版嵁鐢╁嚭鏉ユ墦鏍囩
+			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" {
+					flag11 = true
+				}
+			}
+			if flag11 {
+				args.RuleResult["face"] = faces
+			}
 			// 鍘荤湅姹犲瓙閲屾槸鍚︽湁涓庢湰甯ф暟鎹湁鍏崇殑瀹氭椂鍣紝濡傛灉鏈夛紝鐪嬫鏃舵槸鍚﹁蛋鍒�0锛屾病鏈夋瀹氭椂鍣ㄦ垨鏈夊畾鏃跺櫒璧板埌0鐨勮瘽杩斿洖鎴愬姛鎶ヨ
 			var flag bool = true
 			for k, timeEle := range TimeEleList {
@@ -345,7 +361,26 @@
 					}
 				}
 				if sdkName != "" {
-					args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkName, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText})
+					// 鎶婁粬浠殑浣嶇疆鏁版嵁涔熶紶涓嬪幓
+					locations := []Rect{}
+					for _, sdkData := range args.Sdkdata {
+						for _, areaMap := range sdkData.AreaMapList {
+							for j := 0; j < len(groupRule.Rules); j++ {
+								locations = append(locations, putYolosToResult(groupRule.Rules[j], &areaMap)...)
+							}
+						}
+					}
+					//// 閰嶄簡浜鸿劯鐨勭畻娉曟墠鎶婁汉鑴哥殑鏁版嵁鐢╁嚭鏉ユ墦鏍囩
+					//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" {
+					//		flag11 = true
+					//	}
+					//}
+					//if flag11 {
+					//	args.RuleResult["face"] = faces
+					//}
+					args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkName, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText,locations})
 					log.Println("-------------------yolo缁撴灉鏍囩", args.RuleResult["yolo"].([]Result))
 				}
 				if args.RuleResult["face"] != nil {
@@ -372,6 +407,19 @@
 	}
 	//log.Println("-----------------------------------------------鍚浣犳槸绌虹殑锛�",faces)
 	return faces
+}
+
+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 len(am.filterData) > 0 {
+			for _, data := range am.filterData {
+				locations = append(locations, data.Location)
+			}
+		}
+	}
+	//log.Println("-----------------------------------------------鍚浣犳槸绌虹殑锛�",faces)
+	return locations
 }
 
 // 璁$畻鍖哄煙鍐呯殑鐩爣鏁伴噺浠ュ強灏嗙浉浼煎害銆佸崰姣斻�佸昂瀵哥瓑鎵撳寘
@@ -484,11 +532,13 @@
 		for _, va := range timeEle.RuleResults {
 			if va.CameraId == args.CameraId {
 				va.Result = strconv.FormatBool(isOk)
+				log.Println("杩欎釜鎽勫儚鏈�--", args.CameraId, "--琚祴浜堜簡result", va.Result)
 			}
 		}
 		// 鍒ゆ柇缁撴灉鏁扮粍鏄惁瀹屾弧(鍗宠璧嬪�煎畬姣�)鍙緱鍑烘姤璀︾粨鏋�
 		var isPerfect = true
 		for _, va := range timeEle.RuleResults {
+			log.Println("---------------------鐬呯瀰褰撳墠鏁扮粍________________锛�", *va)
 			if va.Result == "" && va.RuleWithPre != "||" {
 				isPerfect = false
 			}
@@ -516,7 +566,7 @@
 						}
 					}
 					if sdkName != "" {
-						args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkName, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText})
+						args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkName, groupRule.GroupId, groupRule.AlarmLevel, groupRule.GroupText,[]Rect{}})
 						log.Println("-------------------yolo缁撴灉鏍囩", args.RuleResult["yolo"].([]Result))
 					}
 					if args.RuleResult["face"] != nil {

--
Gitblit v1.8.0