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 --- EsApi.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 47 insertions(+), 11 deletions(-) diff --git a/EsApi.go b/EsApi.go index d35c480..4849041 100644 --- a/EsApi.go +++ b/EsApi.go @@ -5,6 +5,7 @@ "encoding/json" "errors" "fmt" + "sort" "strconv" "strings" "sync" @@ -159,9 +160,27 @@ } /**************************************customer analysis util start**************************************/ +/*******************sort []map util*******************/ +type MapsSort struct { + Key string + MapList []map[string]interface{} +} +func (m *MapsSort) Len() int { + return len(m.MapList) +} + +func (m *MapsSort) Less(i, j int) bool { + return m.MapList[i][m.Key].(string) > m.MapList[j][m.Key].(string) +} + +func (m *MapsSort) Swap(i, j int) { + m.MapList[i], m.MapList[j] = m.MapList[j], m.MapList[i] +} + +/*******************sort []map util*******************/ //鏍规嵁鏃堕棿鑼冨洿鑱氬悎鎵�鏈夊尯鍩熶汉淇℃伅锛岃繑鍥炲浐瀹氭潯鏁� -func GetFaceDataByTimeAnd(startTime string, total int, serverIp string, serverPort string, indexName string) (resData []map[string]interface{}, err error) { +func GetFaceDataByTimeAnd(startTime string, total int, thresholdTime int, thresholdStayTime int, serverIp string, serverPort string, indexName string) (resData []map[string]interface{}, err error) { var requestUrl = "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search" var requestBody = `{ "query": { @@ -219,6 +238,7 @@ "includes": [ "baseInfo.targetId", "targetInfo.picSmUrl", + "targetInfo.areaId", "picDate" ] } @@ -232,12 +252,26 @@ if err != nil { return nil, err } - source, err := Sourcelist(buf) + source, err := FaceSourceAggregations(buf, thresholdTime, thresholdStayTime) if err != nil { return nil, err } - fmt.Println(source) - return resData, nil + fmt.Println(len(source)) + faceSource := make([]map[string]interface{}, 0) + for index, info := range source { + if int(info["stayTime"].(float64)) > thresholdStayTime { + faceSource = append(faceSource, source[index]) + } + } + //fmt.Println(len(source)) + if len(faceSource) > total { + mapsSort := MapsSort{} + mapsSort.Key = "endTime" + mapsSort.MapList = faceSource + sort.Sort(&mapsSort) + return mapsSort.MapList[:total], nil + } + return faceSource, nil } func GetFaceIdDeduplication(startTime string, endTime string, serverIp string, serverPort string, indexName string) (ids []string, err error) { @@ -280,14 +314,17 @@ } } }` + //fmt.Println(requestUrl) + //fmt.Println(requestBody) buf, err := EsReq("POST", requestUrl, []byte(requestBody)) if err != nil { return nil, err } - fmt.Println(buf) - //ids, err := SourceDeduplication(buf) - - return ids,nil + ids, err1 := SourceDeduplication(buf) + if err1 != nil { + return nil, err1 + } + return ids, nil } /**************************************customer analysis util end**************************************/ @@ -580,9 +617,8 @@ return err } picMaxUrls := tRes[0].PicMaxUrl - sourceStr := ` - "lang":"painless", - "inline": "ctx._source.picMaxUrl.add('` + picUrl + `');ctx._source.updateTime='` + updateTime + `'" + sourceStr := ` + "source": "ctx._source.picMaxUrl.add('` + picUrl + `');ctx._source.updateTime='` + updateTime + `'" ` if len(picMaxUrls) >= 2 { sourceStr = `"source": "ctx._source.picMaxUrl[1]='` + picUrl + `';ctx._source.updateTime='` + updateTime + `'"` -- Gitblit v1.8.0