From 9bbcbac49cf99c914bcc488157985a9ded6dc803 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期日, 23 八月 2020 15:34:58 +0800
Subject: [PATCH] add stayTime

---
 EsClient.go |   21 +++++++++++++++++----
 EsApi.go    |   13 ++++++++-----
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/EsApi.go b/EsApi.go
index caea6e1..0201857 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -190,7 +190,7 @@
             ]
         }
     },
-    "size": 10,
+    "size": 2147483647,
     "_source": {
         "includes": [
             "cameraId",
@@ -205,8 +205,8 @@
         ]
     }
 }`
-	//fmt.Println(personUrl)
-	//fmt.Println(personBody)
+	fmt.Println(personUrl)
+	fmt.Println(personBody)
 	buf, err := EsReq("POST", personUrl, []byte(personBody))
 	if err != nil {
 		return nil, err
@@ -270,12 +270,13 @@
                             }
                         }
                     }
-                ]
+                ],
+                "size": 100000000
             },
             "aggs":{
                 "top_attention_hits":{
                     "top_hits":{
-                        "size": 100,
+                        "size": 1000000,
                         "sort": [
                             {
                                 "picDate": {
@@ -292,6 +293,8 @@
         }
     }
 }`
+	//fmt.Println(buckersUrl)
+	//fmt.Println(buckersBody)
 	buf, err := EsReq("POST", buckersUrl, []byte(buckersBody))
 	if err != nil {
 		return nil, err
diff --git a/EsClient.go b/EsClient.go
index 4e1f551..30f182a 100644
--- a/EsClient.go
+++ b/EsClient.go
@@ -529,9 +529,11 @@
 
 			sTime := tmpTime
 			eTime := tmpTime
+			stayTime := 0.0
 			if startTime != "" {
 				sinTime, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, loc)
-				if math.Abs(sinTime.Sub(mTime).Seconds()) <= thresholdTime {
+				stayTime = math.Abs(sinTime.Sub(mTime).Seconds())
+				if  stayTime <= thresholdTime {
 					startTime = tmpTime
 					hitsSources[len(hitsSources)-1]["endTime"] = tmpTime
 					continue
@@ -559,6 +561,7 @@
 			tmpHitSource["startBackGroundPicUrl"] = source["picMaxUrl"].([]interface{})
 			tmpHitSource["startFacePicUrl"] = targetInfo["picSmUrl"].(string)
 			tmpHitSource["endTime"] = eTime
+			tmpHitSource["stayTime"] = stayTime
 			tmpHitSource["endTBackGroundPicUrl"] = source["picMaxUrl"].([]interface{})
 			tmpHitSource["endTFacePicUrl"] = targetInfo["picSmUrl"].(string)
 			hitsSources = append(hitsSources, tmpHitSource)
@@ -579,20 +582,30 @@
 
 //瑙f瀽鎶撴媿搴撲汉鍛樼粨鏋�
 func PerSonAnalysis(preData []map[string]interface{}) (sources []map[string]interface{}, err error) {
-	source := make(map[string]interface{}, 0)
+	loc, err := time.LoadLocation("Asia/Shanghai")
+	if err != nil {
+		return nil, errors.New("鏃跺尯璁剧疆閿欒")
+	}
 	for _, key := range preData {
+		source := make(map[string]interface{}, 0)
 		info := key
 		targetInfo := info["targetInfo"].([]interface{})[0].(map[string]interface{})
+		startTime := info["picDate"].(string)
+		endTime := info["updateTime"].(string)
 		source["personId"] = targetInfo["belongsTargetId"].(string)
 		source["cameraId"] = info["cameraId"].(string)
 		source["cameraName"] = info["cameraName"].(string)
 		source["cameraAddr"] = info["cameraAddr"].(string)
 		source["targetScore"] = int(targetInfo["targetScore"].(float64))
 		source["personRect"] = targetInfo["targetLocation"].(map[string]interface{})
-		source["startTime"] = info["picDate"].(string)
+		source["startTime"] = startTime
 		pixMaxUrl := info["picMaxUrl"].([]interface{})
 		source["startBackGroundPicUrl"] = pixMaxUrl[0]
-		source["endTime"] = info["updateTime"].(string)
+		source["endTime"] = endTime
+		startT, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, loc)
+		endT, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, loc)
+		stayTime := endT.Sub(startT).Seconds()
+		source["stayTime"] = stayTime
 		source["endBackGroundPicUrl"] = pixMaxUrl[len(pixMaxUrl)-1]
 		sources = append(sources, source)
 	}

--
Gitblit v1.8.0