From 573a1e019fc00e171b7df7105fe69b414a490966 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期六, 09 十一月 2019 15:03:36 +0800
Subject: [PATCH] 把一部分判断放进中间件

---
 algorithm/static/static.go |   41 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/algorithm/static/static.go b/algorithm/static/static.go
index 88b4e33..6caff13 100644
--- a/algorithm/static/static.go
+++ b/algorithm/static/static.go
@@ -8,9 +8,23 @@
 	"ruleprocess/structure"
 	"strconv"
 )
+
 //涓綋闈欐绠楁硶
+var StaticMap = make(map[string]CameraArea)
+
+type CameraArea struct {
+	targets  []Obj
+	duration int
+	cache    structure.ResultMsg
+}
+type Obj struct {
+	id           string
+	location     []structure.Rect
+	staticStatus int
+}
+
 func Entrance(rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult {
-	for _,obj := range am.FilterData {
+	for _, obj := range am.FilterData {
 		var flag bool = true
 		for k, _ := range ruleserver.TimeEleList {
 			if k == rule.Id+""+strconv.Itoa(int(obj.Id)) {
@@ -20,7 +34,7 @@
 		}
 		if flag {
 			timeEle := ruleserver.TimeElement{N: 10, InitN: 10, AlarmFlag: false, BufferFlag: 5} // 鎵旇繘鍘讳竴涓畾鏃跺櫒鍏冪礌
-			ruleserver.TimeEleList[rule.Id+""+strconv.Itoa(int(obj.Id))] = &timeEle // 瀹氭椂鍣ㄥ厓绱犱互灏忚鍒檌d鍜岀洰鏍噄d涓洪敭
+			ruleserver.TimeEleList[rule.Id+""+strconv.Itoa(int(obj.Id))] = &timeEle              // 瀹氭椂鍣ㄥ厓绱犱互灏忚鍒檌d鍜岀洰鏍噄d涓洪敭
 		}
 	}
 	return structure.LittleRuleResult{}
@@ -62,4 +76,25 @@
 	} else {
 		return structure.LittleRuleResult{am.SdkName, rule.RuleWithPre + "" + "false", rule.Sort}
 	}
-}
\ No newline at end of file
+}
+
+// 鍒ゆ柇涓や釜鐭╁舰鐨勯噸鍚堝害锛屾妸闈㈢Н鏇村ぇ鐨勫仛鍒嗘瘝
+func PgsInterPercent(pgpts []structure.Point, box structure.Rect, widthScale float64, heightScale float64) (percent float64) {
+
+	areapts, areaBox := ruleserver.GetLocation(box, 10)
+	var count = 0
+	for _, pts := range areapts {
+		if ruleserver.PintIsInPolygon(pts, pgpts, widthScale, heightScale) {
+			count++
+		}
+	}
+	perInterBox := float64(count) / float64(len(areapts)) // 閲嶅悎闈㈢Н鍗犵煩褰㈢殑姣斾緥
+	areaInter := perInterBox * areaBox
+	areaPg := ruleserver.ComputePolygonArea(pgpts)
+	perInterPg := areaInter / areaPg // 閲嶅悎闈㈢Н鍗犲杈瑰舰鍖哄煙鐨勬瘮渚�
+	// 鍝釜鍗犵殑姣斾緥灏忔寜鍝釜璁$畻锛屾瘮濡備汉绔欒捣鏉ヤ簡锛屽ぇ妗嗗浣忎簡灏忔
+	if perInterBox < perInterPg {
+		return (perInterBox * 100)
+	}
+	return (perInterPg * 100)
+}

--
Gitblit v1.8.0