From 3e2c40a20764f62969f807688457d15a09a413e7 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期四, 04 七月 2019 19:39:37 +0800
Subject: [PATCH] 在人脸提取中解析底库数据信息

---
 insertdata/insertDataToEs.go |  202 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 132 insertions(+), 70 deletions(-)

diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index 2f0b44f..277b14a 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -10,7 +10,6 @@
 	"strings"
 	"time"
 
-	"basic.com/dbapi.git"
 	"basic.com/pubsub/protomsg.git"
 	"github.com/golang/protobuf/proto"
 	"github.com/satori/go.uuid"
@@ -21,34 +20,34 @@
 var weedfsUrl = "http://192.168.1.182:6333/submit"
 // 浜鸿劯鐨勬暟鎹粨鏋�
 type PerVideoPicture struct {
-	Id              string `json:"id"`
-	CameraId        string `json:"cameraId"`
-	CameraAddr      string `json:"cameraAddr"`
-	PicDate         string `json:"picDate"`
-	PicMaxUrl       string `json:"picMaxUrl"`
-	TaskId          string `json:"taskId"`
-	TaskName        string `json:"taskName"`
-	SdkName         string `json:"sdkName"`
-	Content         string `json:"content"`
-	LikeDate        string `json:"likeDate"`
-	Sex             int32  `json:"sex"`
-	Age             int32  `json:"age"`
-	AgeDescription  string `json:"ageDescription"`
-	Race            int32  `json:"race"`
-	SmileLevel      int32  `json:"smileLevel"`
-	BeautyLevel     int32  `json:"beautyLevel"`
-	FaceFeature     string `json:"faceFeature"`
-	PicSmUrl        string `json:"picSmUrl"`
-	VideoUrl        string `json:"videoUrl"`
-	AnalyServerId   string `json:"analyServerId"`
-	AnalyServerName string `json:"analyServerName"`
-	AnalyServerIp   string `json:"analyServerIp"`
-	ClusterId       string `json:"clusterId"`
-	IsAlarm         string `json:"isAlarm"`
-	IsAckAlarm      string `json:"isAckAlarm"`
-	IsCollect       string `json:"isCollect"`
-	IsDelete        int    `json:"isDelete"`
-	BaseInfo        Base   `json:"baseInfo"`
+	Id              string   `json:"id"`
+	CameraId        string   `json:"cameraId"`
+	CameraAddr      string   `json:"cameraAddr"`
+	PicDate         string   `json:"picDate"`
+	PicMaxUrl       string   `json:"picMaxUrl"`
+	TaskId          string   `json:"taskId"`
+	TaskName        string   `json:"taskName"`
+	SdkName         string   `json:"sdkName"`
+	Content         string   `json:"content"`
+	LikeDate        string   `json:"likeDate"`
+	Sex             string   `json:"sex"`
+	Age             int32    `json:"age"`
+	AgeDescription  string   `json:"ageDescription"`
+	Race            string   `json:"race"`
+	SmileLevel      int32    `json:"smileLevel"`
+	BeautyLevel     int32    `json:"beautyLevel"`
+	FaceFeature     string   `json:"faceFeature"`
+	PicSmUrl        []string `json:"picSmUrl"`
+	VideoUrl        string   `json:"videoUrl"`
+	AnalyServerId   string   `json:"analyServerId"`
+	AnalyServerName string   `json:"analyServerName"`
+	AnalyServerIp   string   `json:"analyServerIp"`
+	ClusterId       string   `json:"clusterId"`
+	IsAlarm         int      `json:"isAlarm"`
+	IsAckAlarm      int      `json:"isAckAlarm"`
+	IsCollect       int      `json:"isCollect"`
+	IsDelete        int      `json:"isDelete"`
+	BaseInfo        []Base   `json:"baseInfo"`
 }
 
 type Base struct {
@@ -83,15 +82,15 @@
 	PicSmUrl        []string    `json:"picSmUrl"`
 	PicDate         string      `json:"picDate"`
 	VideoUrl        string      `json:"videoUrl"`
-	IsAlarm         string      `json:"isAlarm"`
-	IsAckAlarm      string      `json:"isAckAlarm"`
-	IsCollect       string      `json:"isCollect"`
+	IsAlarm         int         `json:"isAlarm"`
+	IsAckAlarm      int         `json:"isAckAlarm"`
+	IsCollect       int         `json:"isCollect"`
 	IsDelete        int         `json:"isDelete"`
 }
 
 type AlarmRule struct {
 	GroupId    string `json:"groupId"`
-	AlarmLevel int32  `json:"alarmLevel"`
+	AlarmLevel string `json:"alarmLevel"`
 	RuleText   string `json:"ruleText"`
 }
 
@@ -99,9 +98,9 @@
 func InsertToEs(msg ruleserver.ResultMsg) {
 
 	// 鐩存帴浠庤鍒欑殑鏍囩鏁版嵁閲屾嬁绗﹀悎瑙勫垯鐨勪汉鑴哥粨鏋�
-	if msg.RuleResult["faces"] != nil && len(msg.RuleResult["faces"].([]ruleserver.Arg)) > 0 {
+	if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.Arg)) > 0 {
 		log.Println("寰�ES鎻掍汉鑴告暟鎹�")
-		for _, face := range msg.RuleResult["faces"].([]ruleserver.Arg) {
+		for _, face := range msg.RuleResult["face"].([]ruleserver.Arg) {
 			// 涓婁紶澶у浘
 			// 瑙e帇缂╁苟涓婁紶鍥剧墖
 			bdata, err := util.UnCompress(msg.Data)
@@ -115,8 +114,8 @@
 			fmt.Println(bigPhotoUrl)
 			if len(face.Liker) == 0 {
 				// 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
-				flag, localConfig := dbapi.SysSetApi{}.GetServerInfo()
-				if !flag {
+				localConfig, err := cache.GetServerInfo()
+				if err != nil {
 					log.Println("鏌ヨ鏈満淇℃伅澶辫触锛�")
 				}
 				serverIp, err := GetLocalIP()
@@ -125,43 +124,57 @@
 				if err != nil {
 					panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
 				}
+				// 鏌ヨcameraName
+				camera, err := cache.GetCameraById(msg.Cid)
+				if err != nil {
+					log.Println("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
+				}
 				i := protomsg.Image{}
 				err = proto.Unmarshal(bdata, &i)
-				i1 := protomsg.Image{}
-				i1 = util.Subimg(i.Data, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
-				resp, err := util.PostFormBufferData(weedfsUrl, i1, uuid.NewV4().String())
+				log.Println("-------------------------------------------鐪嬩笅瀹藉拰楂�", i.Width, i.Height)
+				bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
+				resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
 				if err != nil {
 					log.Println("涓婁紶灏忓浘鍑洪敊")
 				}
+				sex := ""
+				if face.ThftRes.Gender == 1 {
+					sex = "鐢�"
+				} else {
+					sex = "濂�"
+				}
+				race := getRaceString(face.ThftRes.Race)
+				ageDescription := getDescription(face.ThftRes.Age)
+
 				pervideo := PerVideoPicture{
 					uuid.NewV4().String(),
 					msg.Cid,
-					msg.Caddr,
+					camera.Addr,
 					time.Now().Format("2006-01-02 15:04:05"),
-					bigPhotoUrl["fileUrl"].(string),
+					strings.Split(bigPhotoUrl["fileUrl"].(string), "/")[1],
 					msg.Tasklab.Taskid,
 					msg.Tasklab.Taskname,
-					face.SdkName,
+					"浜鸿劯",
 					"",
-					"", // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
-					face.ThftRes.Gender,
+					time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
+					sex,
 					face.ThftRes.Age,
-					"",
-					face.ThftRes.Race,
+					ageDescription,
+					race,
 					face.ThftRes.Smile,
 					face.ThftRes.Beauty,
 					"涓嶆槸姣忎釜浜鸿劯绠楁硶閮芥湁",
-					resp["fileUrl"].(string),
+					[]string{strings.Split(resp["fileUrl"].(string), "/")[1]},
 					"鏆傛棤闆嗙兢",
 					localConfig.ServerId,
 					localConfig.ServerName,
 					serverIp,
 					"",
-					"",
-					"",
-					"",
+					1,
 					0,
-					Base{},
+					0,
+					0,
+					[]Base{},
 				}
 				requstbody, err := json.Marshal(pervideo)
 
@@ -171,11 +184,9 @@
 
 				}
 				err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
-				if err != nil {
-					log.Println("es can not execute right.")
-				}
-			}else {
-				log.Println("璺熷簳搴撶殑鐩镐技鏁版嵁---------锛�",face.Liker)
+				log.Println(err)
+			} else {
+				log.Println("璺熷簳搴撶殑鐩镐技鏁版嵁---------锛�", face.Liker)
 			}
 		}
 	}
@@ -185,12 +196,13 @@
 		alarmRules := []AlarmRule{}
 		for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) {
 			sdkNames = sdkNames + yoloResult.SdkName
-			alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, yoloResult.AlarmLevel, yoloResult.RuleText})
+			alarm := ChangeToString(yoloResult.AlarmLevel)
+			alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText})
 		}
-		isAlarm := ""
+		isAlarm := 0
 		resp := make(map[string]interface{})
 		if len(alarmRules) > 0 {
-			isAlarm = "1"
+			isAlarm = 1
 			// 瑙e帇缂╁苟涓婁紶鍥剧墖
 			bdata, err := util.UnCompress(msg.Data)
 			if err != nil {
@@ -199,21 +211,21 @@
 			i := protomsg.Image{}
 			err = proto.Unmarshal(bdata, &i)
 			//resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
-			resp, err =util.DrawPolygonOnImage(i)
+			resp, err = util.DrawPolygonOnImage(msg.Cid, i,msg.RuleResult["yolo"].([]ruleserver.Result))
 			if err != nil {
-				log.Println("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊",err)
-			}else{
+				log.Println("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+			} else {
 				log.Println("宸叉姤璀﹀苟涓婁紶鏀瑰抚鍥剧墖鍒版湇鍔″櫒")
 			}
 		} else {
-			isAlarm = "0"
+			isAlarm = 0
 			// 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
 			return
 		}
 		// log.Println("鍥剧墖涓婁紶杩斿洖鍊硷細", resp)
 		// 鏌ヨ鏈満淇℃伅
 		localConfig, err := cache.GetServerInfo()
-		if err !=nil {
+		if err != nil {
 			log.Println("鏌ヨ鏈満淇℃伅澶辫触锛�")
 		}
 		// 鏌ヨcameraName
@@ -226,7 +238,7 @@
 			uuid.NewV4().String(),
 			msg.Cid,
 			camera.Name,
-			msg.Caddr,
+			camera.Addr,
 			msg.Tasklab.Taskid,
 			msg.Tasklab.Taskname,
 			sdkNames,
@@ -240,8 +252,8 @@
 			time.Now().Format("2006-01-02 15:04:05"),
 			"",
 			isAlarm,
-			"",
-			"",
+			0,
+			0,
 			0,
 		}
 		requstbody, err := json.Marshal(peraction)
@@ -253,9 +265,9 @@
 		}
 		err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody)
 		if err != nil {
-			log.Println("寰�ES鎻掑叆鏁版嵁澶辫触",err)
+			log.Println("寰�ES鎻掑叆鏁版嵁澶辫触", err)
 		} else {
-			log.Println("__________________________________________寰�ES鎻掑叆鏁版嵁鎴愬姛")
+			log.Println("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
 		}
 	}
 }
@@ -287,3 +299,53 @@
 	err = errors.New("ipv4 not found")
 	return
 }
+
+// 鎶婃姤璀︾瓑绾ц浆鍖栨垚姹夊瓧
+func ChangeToString(i int32) string {
+	alarm := ""
+	if i == 1 {
+		alarm = "涓�绾�"
+	}
+	if i == 2 {
+		alarm = "浜岀骇"
+	}
+	if i == 3 {
+		alarm = "涓夌骇"
+	}
+	if i == 4 {
+		alarm = "鍥涚骇"
+	}
+	if i == 5 {
+		alarm = "浜旂骇"
+	}
+	return alarm
+}
+
+//鑾峰彇骞撮緞鎻忚堪
+func getDescription(age int32) string {
+	ageInfo := "闈掑勾"
+	if age > 0 && age < 7 {
+		ageInfo = "绔ュ勾"
+	} else if age >= 7 && age < 18 {
+		ageInfo = "灏戝勾"
+	} else if age >= 18 && age < 40 {
+		ageInfo = "闈掑勾"
+	} else if age >= 40 && age < 65 {
+		ageInfo = "涓勾"
+	} else if age >= 65 {
+		ageInfo = "鑰佸勾"
+	}
+	return ageInfo
+}
+
+func getRaceString(i int32) string {
+	race := ""
+	if i == 1 {
+		race = "鐧戒汉"
+	} else if i == 2 {
+		race = "榛勪汉"
+	} else {
+		race = "榛戜汉"
+	}
+	return race
+}

--
Gitblit v1.8.0