From 859810ec55a27fe55b98ec7ea597f712802f47a8 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期三, 26 八月 2020 14:14:57 +0800
Subject: [PATCH] fix stay time

---
 EsClient.go |   21 +++++++++++++++------
 EsApi.go    |    4 ++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/EsApi.go b/EsApi.go
index 82eeb03..d39066a 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -296,7 +296,7 @@
                         }
                     }
                 ],
-                "size": 100
+                "size": 10000000
             },
             "aggs":{
                 "top_attention_hits":{
@@ -402,7 +402,7 @@
                         }
                     }
                 ],
-                "size": 100
+                "size": 10000000
             },
             "aggs":{
                 "top_attention_hits":{
diff --git a/EsClient.go b/EsClient.go
index 8fbbcdf..51baa86 100644
--- a/EsClient.go
+++ b/EsClient.go
@@ -533,20 +533,23 @@
 			sTime := tmpTime
 			eTime := tmpTime
 			stayTime := 0.0
-			if startTime != "" && point < indexLength{
+			if startTime != "" && point <= indexLength{
 				sinTime, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, loc)
 				passTime := math.Abs(mTime.Sub(sinTime).Seconds())
 				//fmt.Println("passTime:   ", passTime)
 				if passTime <= thresholdTime {
 					startTime = tmpTime
 					hitsSources[len(hitsSources)-1]["endTime"] = tmpTime
+					if point == indexLength{
+						hitStartTime := hitsSources[len(hitsSources)-1]["startTime"].(string)
+						realStartTime, _ := time.ParseInLocation("2006-01-02 15:04:05", hitStartTime, loc)
+						stayTime = math.Abs(mTime.Sub(realStartTime).Seconds())
+						hitsSources[len(hitsSources)-1]["stayTime"] = stayTime
+					}
 					continue
 				} else {
 					hitStartTime := hitsSources[len(hitsSources)-1]["startTime"].(string)
 					realStartTime, _ := time.ParseInLocation("2006-01-02 15:04:05", hitStartTime, loc)
-					//fmt.Println("hitStartTime:    ",hitStartTime)
-					//fmt.Println("realStartTime:    ",realStartTime)
-					//fmt.Println("mTime:    ",mTime)
 					stayTime = math.Abs(mTime.Sub(realStartTime).Seconds())
 					//fmt.Println("stayTime:    ",stayTime)
 					hitsSources[len(hitsSources)-1]["endTime"] = tmpTime
@@ -654,13 +657,19 @@
 			sTime := tmpTime
 			eTime := tmpTime
 			stayTime := 0.0
-			if startTime != "" && point < indexLength{
+			if startTime != "" && point <= indexLength{
 				sinTime, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, loc)
 				passTime := math.Abs(mTime.Sub(sinTime).Seconds())
 				//fmt.Println("passTime:   ", passTime)
-				if passTime <= thresholdTime {
+				if passTime <= thresholdTime || point == indexLength{
 					startTime = tmpTime
 					hitsSources[len(hitsSources)-1]["endTime"] = tmpTime
+					if point == indexLength{
+						hitStartTime := hitsSources[len(hitsSources)-1]["startTime"].(string)
+						realStartTime, _ := time.ParseInLocation("2006-01-02 15:04:05", hitStartTime, loc)
+						stayTime = math.Abs(mTime.Sub(realStartTime).Seconds())
+						hitsSources[len(hitsSources)-1]["stayTime"] = stayTime
+					}
 					continue
 				} else {
 					hitStartTime := hitsSources[len(hitsSources)-1]["startTime"].(string)

--
Gitblit v1.8.0