From 6f1ae979d13028006ccdca01e310d2b5d2d53c5c Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期四, 15 八月 2019 16:27:44 +0800
Subject: [PATCH] 把数据定义模块儿提取出来

---
 ruleserver/readyDataForRule.go |   64 +++++++++++---------------------
 1 files changed, 22 insertions(+), 42 deletions(-)

diff --git a/ruleserver/readyDataForRule.go b/ruleserver/readyDataForRule.go
index ba290b0..3e4b712 100644
--- a/ruleserver/readyDataForRule.go
+++ b/ruleserver/readyDataForRule.go
@@ -16,6 +16,7 @@
 	"ruleprocess/cache"
 	"ruleprocess/logger"
 	"github.com/golang/protobuf/proto"
+	"ruleprocess/structure"
 	"strconv"
 	"time"
 )
@@ -56,20 +57,6 @@
 	}
 }
 
-type BaseInfo struct {
-	TableId      string  `json:"tableId"`
-	TableName    string  `json:"tableName"`
-	BwType       string  `json:"bwType"`
-	CompareScore float64 `json:"compareScore"`
-	PersonId     string  `json:"personId"`
-	PersonName   string  `json:"personName"`
-	PersonPicUrl string  `json:"personPicUrl"`
-	PhoneNum     string  `json:"phoneNum"`
-	Sex          string  `json:"sex"`
-	IdCard       string  `json:"idCard"`
-	MonitorLevel string  `json:"monitorLevel"`
-	Content      string  `json:"content"`
-}
 
 // 浠ユ憚鍍忔満id鏌ュ嚭璺熷叾鐩稿叧鐨勬墍鏈変换鍔′笅鐨勬墍鏈夎鍒欑粍
 func GetRuleGroup(cameraId string, taskId string) *protomsg.TaskGroupArgs {
@@ -110,9 +97,9 @@
 	return value2
 }
 // 鍙栧嚭鏌愪釜鏃堕棿瑙勫垯鐨勭鍑犲ぉ鐨勮鍒欐闆嗗悎
-func GetTimeById(id string, index int) []TimeRange {
+func GetTimeById(id string, index int) []structure.TimeRange {
 	_, cameraTimeRule := cache.GetTimeRuleById(id)
-	var timeRangeList []Day
+	var timeRangeList []structure.Day
 	err := json.Unmarshal([]byte(cameraTimeRule.TimeRule), &timeRangeList)
 	if err != nil {
 		logger.Error("鍙栨椂闂磋鍒欐椂鍙嶅簭鍒楀寲閿欒锛�")
@@ -137,24 +124,17 @@
 	return 0
 }
 
-type TimeRange struct {
-	Start string `json:"start"`
-	End   string `json:"end"`
-}
-type Day struct {
-	Day       int         `json:"day"`        // 鏍囩ず褰撳墠鏄熸湡鍑�
-	TimeRange []TimeRange `json:"time_range"` // 褰撳ぉ鐨勫嚑涓椂闂存
-}
+
 
 // 灏嗗瓧绗︿覆鏍煎紡鐨勫潗鏍囧簭鍒楀寲涓篜oint鏍煎紡
-func Json2points(areaPoints string) []Point {
-	var pts []Point
+func Json2points(areaPoints string) []structure.Point {
+	var pts []structure.Point
 	if areaPoints == "[]" || areaPoints == "" {
 		logger.Error("=====================姝ゅ尯鍩熶负鍏ㄩ儴鍖哄煙")
-		pts = append(pts, Point{0, 0})
-		pts = append(pts, Point{0, 540})
-		pts = append(pts, Point{960, 540})
-		pts = append(pts, Point{960, 0})
+		pts = append(pts, structure.Point{0, 0})
+		pts = append(pts, structure.Point{0, 540})
+		pts = append(pts, structure.Point{960, 540})
+		pts = append(pts, structure.Point{960, 0})
 	} else {
 		err := json.Unmarshal([]byte(areaPoints), &pts)
 		if err != nil {
@@ -166,7 +146,7 @@
 }
 
 // 缁欑洰鏍囧~鍏卨iker
-func (arg *Arg) FillLiker(tableId []string, compareThreshold float32) {
+func FillLiker(arg *structure.Arg,tableId []string, compareThreshold float32) {
 	//bytes := bigCache.GetComparePersonBaseInfo(tableId, arg.Feature, compareThreshold)
 	comArg := &protomsg.CompareArgs{
 		TableIds:tableId,
@@ -204,7 +184,7 @@
 				logger.Error("鏍规嵁id鏌ヨ搴曞簱淇℃伅鍑洪敊锛�", err, "--杩斿洖鍊奸暱搴︿负锛�", len(table))
 			}
 			logger.Debug("鐪嬬湅杩欎釜base鐨勫姣斿�兼槸澶氬皯锛�", Decimal(m[baseinfo.Id].CompareScore))
-			base := BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id].CompareScore), PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved}
+			base := structure.BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id].CompareScore), PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved}
 			//os.Exit(1)
 			arg.Liker = append(arg.Liker, &base)
 		}
@@ -213,7 +193,7 @@
 }
 
 // 浜鸿劯姣斿
-func Compare(args *SdkDatas, groupRule *protomsg.GroupRule) {
+func Compare(args *structure.SdkDatas, groupRule *protomsg.GroupRule) {
 	compareFlag := 0
 	var tableIds []string
 	var threshold float32 = 50 // 榛樿闃堝�间负50
@@ -255,18 +235,18 @@
 							for _, arg := range areaMap.Args {
 								arg.Liker = arg.Liker[0:0]
 								logger.Info("娓呯┖涔嬪悗鐪嬬湅涔嬪墠鎵撶殑浜鸿劯鏍囩鍙樹簡娌★細")
-								if args.RuleResult["face"] != nil && len(args.RuleResult["face"].([]FaceResult)) > 0 {
-									for _, faceResult := range args.RuleResult["face"].([]FaceResult) {
+								if args.RuleResult["face"] != nil && len(args.RuleResult["face"].([]structure.FaceResult)) > 0 {
+									for _, faceResult := range args.RuleResult["face"].([]structure.FaceResult) {
 										for _,arg := range faceResult.Args {
 											logger.Info("浜哄憳鍒嗗�兼槸锛�",arg.Score,"liker鐨勬暟閲忎负",arg.Liker)
 										}
 									}
 								}
 								if compareFlag == 1 {
-									arg.FillLiker(nil, threshold)
+									FillLiker(arg,nil, threshold)
 								}
 								if compareFlag == 2 {
-									arg.FillLiker(tableIds, threshold)
+									FillLiker(arg,tableIds, threshold)
 								}
 								//logger.Info("-------------------鎴愬姛缁檒iker璧嬪��,闀垮害涓猴細", len(arg.Liker))
 							}
@@ -283,7 +263,7 @@
 }
 
 // 璁$畻鍖哄煙鍐呯殑鐩爣鏁伴噺浠ュ強灏嗙浉浼煎害銆佸崰姣斻�佸昂瀵哥瓑鎵撳寘
-func (a *AreaMap) CountAreaObjs(arg *SdkData) {
+func CountAreaObjs(a *structure.AreaMap,arg *structure.SdkData) {
 
 	a.TargetNum = 0
 	threshold := 0.0       // 鐩镐技搴�
@@ -298,7 +278,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.Id,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.Feature, obj.ThftRes, []*BaseInfo{}}
+			arg1 := structure.Arg{obj.Id,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.Feature, obj.ThftRes, []*BaseInfo{}}
 			//logger.Println("鏀捐繘鍘荤殑arg锛�-------", arg1)
 			a.Args = append(a.Args, &arg1)
 			a.FilterData = append(a.FilterData, &arg1)
@@ -312,16 +292,16 @@
 }
 
 // 鎶妔dk浠庢暟鎹抚涓婃彁鍙栫殑鎸夌収鍖哄煙鍒嗙被褰掔疆
-func SdkDataFormat(cameraId string, arg *SdkData, cameraPolygons []protomsg.CameraPolygon) {
+func SdkDataFormat(cameraId string, arg *structure.SdkData, cameraPolygons []protomsg.CameraPolygon) {
 	logger.Info("==================================鏈瑂dkData涓В鍑烘潵鐨勭洰鏍囨暟鎹�=======================================")
 	for _, photo := range arg.Photo {
 		logger.Info("--------瑙f瀽鍑烘潵鐨勬暟鎹�---", cameraId, arg.IpcId, photo.Rects, photo.Score)
 	}
 	for _, polygon := range cameraPolygons {
 		//logger.Println("++++++鍦ㄨ繖鍎跨湅涓�涓嬪尯鍩熷晩:", polygon.Polygon)
-		areaMap := AreaMap{CameraId: cameraId, AreaId: polygon.Id, AreaJson: polygon.Polygon, TriggerLine: polygon.TriggerLine, DirectionLine: polygon.DirectionLine}
+		areaMap := structure.AreaMap{CameraId: cameraId, AreaId: polygon.Id, AreaJson: polygon.Polygon, TriggerLine: polygon.TriggerLine, DirectionLine: polygon.DirectionLine}
 		// 涓烘瘡涓憚鍍忔満鍖哄煙濉厖鏁版嵁
-		areaMap.CountAreaObjs(arg)
+		CountAreaObjs(&areaMap,arg)
 		arg.AreaMapList = append(arg.AreaMapList, &areaMap)
 	}
 }

--
Gitblit v1.8.0