From 353829e0039ebebdf3502cd198248edf7e94d8d4 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期五, 28 八月 2020 19:17:43 +0800 Subject: [PATCH] add ids faceinfo --- EsClient.go | 46 +++++++++++++++++++++++++++++++++------------- 1 files changed, 33 insertions(+), 13 deletions(-) diff --git a/EsClient.go b/EsClient.go index 8e08e76..a24b0e2 100644 --- a/EsClient.go +++ b/EsClient.go @@ -476,8 +476,7 @@ return tmpinfos } -func FaceSourceAggregations(buf [] byte, thresholdTime float64, queryUseTime float64) (sources map[string]interface{}, err error) { - s := make(map[string]interface{}) +func FaceSourceAggregations(buf []byte, thresholdTime int,thresholdStayTime int) (sources []map[string]interface{}, err error) { loc, err := time.LoadLocation("Asia/Shanghai") if err != nil { return nil, errors.New("鏃跺尯璁剧疆閿欒") @@ -509,12 +508,12 @@ for _, in := range finalHits { point = point+1 tmpHitSource := make(map[string]interface{}) - tmpbuf, ok := in.(map[string]interface{}) + tmpBuf, ok := in.(map[string]interface{}) if !ok { fmt.Println("change to source error!") continue } - source, ok := tmpbuf["_source"].(map[string]interface{}) + source, ok := tmpBuf["_source"].(map[string]interface{}) if !ok { fmt.Println("change _source error!") continue @@ -535,7 +534,7 @@ passTime := math.Abs(mTime.Sub(sinTime).Seconds()) hitsSources[len(hitsSources)-1]["stayTime"] = stayTime //fmt.Println("passTime: ", passTime) - if passTime <= thresholdTime || point == indexLength{ + if int(passTime) <= thresholdTime || point == indexLength{ startTime = tmpTime hitsSources[len(hitsSources)-1]["endTime"] = tmpTime if point == indexLength{ @@ -543,6 +542,7 @@ realStartTime, _ := time.ParseInLocation("2006-01-02 15:04:05", hitStartTime, loc) stayTime = math.Abs(mTime.Sub(realStartTime).Seconds()) hitsSources[len(hitsSources)-1]["stayTime"] = stayTime + startTime = "" } continue } else { @@ -565,7 +565,11 @@ } //fmt.Println("========================================================") startTime = tmpTime - tmpHitSource["personId"] = baseInfo["targetId"].(string) + tmpHitSource["faceId"] = baseInfo["targetId"].(string) + if targetInfo["areaId"] == nil { + continue + } + tmpHitSource["areaId"] = targetInfo["areaId"].(string) tmpHitSource["startTime"] = sTime tmpHitSource["startFacePicUrl"] = targetInfo["picSmUrl"].(string) tmpHitSource["endTime"] = eTime @@ -574,14 +578,30 @@ } allSource = append(allSource, hitsSources...) } - count := len(allSource) - //fmt.Println(count) - s["count"] = count - s["allSource"] = allSource - s["queryUseTime"] = queryUseTime - return s, nil + return allSource, nil } - +func SourceDeduplication(buf [] byte) ([]string,error) { + var info interface{} + json.Unmarshal(buf, &info) + out, ok := info.(map[string]interface{}) + if !ok { + return nil, errors.New("http response interface can not change map[string]interface{}") + } + middle, ok := out["aggregations"].(map[string]interface{}) + if !ok { + return nil, errors.New("first hits change error!") + } + bucketsAggs := middle["buckets_aggs"].(map[string]interface{}) + buckets := bucketsAggs["buckets"].([]interface{}) + if len(buckets) == 0 { + return nil, nil + } + faceId := make([]string,0) + for _, in := range buckets { + faceId = append(faceId, in.(map[string]interface{})["key"].(map[string]interface{})["faceId"].(string)) + } + return faceId,nil +} func SourceAggregations(buf [] byte, thresholdTime float64, queryUseTime float64) (sources map[string]interface{}, err error) { s := make(map[string]interface{}) loc, err := time.LoadLocation("Asia/Shanghai") -- Gitblit v1.8.0