From c738ec5996011f51549d18dd2ff2417e509f1399 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期四, 20 八月 2020 22:25:52 +0800 Subject: [PATCH] add get person data --- EsClient.go | 39 +++++++++++++++---- EsApi.go | 75 ++++++++++++++++++++++++++++++++++--- 2 files changed, 100 insertions(+), 14 deletions(-) diff --git a/EsApi.go b/EsApi.go index eabf7cf..caea6e1 100644 --- a/EsApi.go +++ b/EsApi.go @@ -159,8 +159,71 @@ } +//鏍规嵁鎽勫儚鏈哄垪琛ㄥ拰鏃堕棿鏌ヨ浜哄憳娴忚杞ㄨ抗 +func GetPersonDataByCameraIdAndTime(cameraId []string, startTime string, endTime string, serverIp string, ServerPort string, indexName string) ([]map[string]interface{}, error) { + esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1) + personUrl := "http://" + serverIp + ":" + ServerPort + "/" + indexName + "/_search" + personBody := `{ + "query": { + "bool": { + "filter": [ + { + "range": { + "picDate": { + "gte": "` + startTime + `", + "lte": "` + endTime + `" + } + } + }, + { + "term": { + "targetInfo.targetType.raw": "Yolo" + } + }, + { + "terms": { + "cameraId": [ + "` + esCameraId + `" + ] + } + } + ] + } + }, + "size": 10, + "_source": { + "includes": [ + "cameraId", + "cameraName", + "cameraAddr", + "targetInfo.targetScore", + "picDate", + "updateTime", + "picMaxUrl", + "targetInfo.belongsTargetId", + "targetInfo.targetLocation" + ] + } +}` + //fmt.Println(personUrl) + //fmt.Println(personBody) + buf, err := EsReq("POST", personUrl, []byte(personBody)) + if err != nil { + return nil, err + } + + sources, err := Sourcelist(buf) + if err != nil { + return nil, err + } + resData,err := PerSonAnalysis(sources) + //println(sources) + return resData, nil + +} + //鏍规嵁鏃堕棿鑼冨洿锛屾憚鍍忔満鍒楄〃锛屽垎缁勮仛鍚堜汉鑴稿垪琛� -func GetfaceDataBucketsBycameraIdAndTime(cameraId []string, startTime string, endTime string, thresholdTime float64, serverIp string, ServerPort string, indexName string) (buckersDate map[string]interface{}, err error) { +func GetFaceDataBucketsByCameraIdAndTime(cameraId []string, startTime string, endTime string, thresholdTime float64, serverIp string, ServerPort string, indexName string) (buckersDate map[string]interface{}, err error) { esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1) var buckersUrl = "http://" + serverIp + ":" + ServerPort + "/" + indexName + "/_search" var buckersBody = `{ @@ -242,9 +305,9 @@ return sources, nil } -//鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坧icurl锛夊浘鐗囧湴鍧�---棰勫紑鍙� +//鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坧icurl锛夊浘鐗囧湴鍧� func UpdatePicUrlById(id string, picUrl string, indexName string, serverIp string, serverPort string) (err error) { - + updateTime := time.Now().Format("2006-01-02 15:04:05") tRes, err := AIOceaninfosbyid([]string{id}, indexName, serverIp, serverPort) if err != nil || len(tRes) == 0 { return err @@ -252,10 +315,10 @@ picMaxUrls := tRes[0].PicMaxUrl sourceStr := ` "lang":"painless", - "inline": "ctx._source.picMaxUrl.add(` + picUrl + `)" + "inline": "ctx._source.picMaxUrl.add('` + picUrl + `');ctx._source.updateTime='`+updateTime+`'" ` if len(picMaxUrls) >= 2 { - sourceStr = `"source": "ctx._source.picMaxUrl[1]='` + picUrl + `'"` + sourceStr = `"source": "ctx._source.picMaxUrl[1]='` + picUrl + `';ctx._source.updateTime='`+updateTime+`'"` } var info interface{} url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_update_by_query?refresh=true" @@ -279,7 +342,7 @@ } ` //logPrint("url: ", url, videoUrlInfo) - //fmt.Println(url, picUrlInfo) + fmt.Println(url, picUrlInfo) buf, err := EsReq("POST", url, []byte(picUrlInfo)) if err != nil { logPrint("http request videoUrlInfo info is err!") diff --git a/EsClient.go b/EsClient.go index 96be3c7..4e1f551 100644 --- a/EsClient.go +++ b/EsClient.go @@ -497,7 +497,7 @@ if len(buckets) == 0 { return nil, nil } - allSource := make([]map[string]interface{},0) + allSource := make([]map[string]interface{}, 0) for _, inf := range buckets { //tmpSources := make(map[string]interface{}, 0) hitsSources := make([]map[string]interface{}, 0) @@ -536,8 +536,8 @@ hitsSources[len(hitsSources)-1]["endTime"] = tmpTime continue } else { - if sinTime.Sub(mTime).Seconds() == 0{ - sinTime.Add(time.Second*1) + if sinTime.Sub(mTime).Seconds() == 0 { + sinTime.Add(time.Second * 1) sinTime.Format("2006-01-02 15:04:05") hitsSources[len(hitsSources)-1]["endTime"] = sinTime } @@ -563,11 +563,11 @@ tmpHitSource["endTFacePicUrl"] = targetInfo["picSmUrl"].(string) hitsSources = append(hitsSources, tmpHitSource) } - allSource = append(allSource,hitsSources...) - // tmpSources["groupKey"] = groupKey - // tmpSources["doc_count"] = docCount - // tmpSources["hits_sources"] = hitsSources - // sources = append(sources, tmpSources) + allSource = append(allSource, hitsSources...) + // tmpSources["groupKey"] = groupKey + // tmpSources["doc_count"] = docCount + // tmpSources["hits_sources"] = hitsSources + // sources = append(sources, tmpSources) } count := len(allSource) fmt.Println(count) @@ -577,6 +577,29 @@ return s, nil } +//瑙f瀽鎶撴媿搴撲汉鍛樼粨鏋� +func PerSonAnalysis(preData []map[string]interface{}) (sources []map[string]interface{}, err error) { + source := make(map[string]interface{}, 0) + for _, key := range preData { + info := key + targetInfo := info["targetInfo"].([]interface{})[0].(map[string]interface{}) + 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) + pixMaxUrl := info["picMaxUrl"].([]interface{}) + source["startBackGroundPicUrl"] = pixMaxUrl[0] + source["endTime"] = info["updateTime"].(string) + source["endBackGroundPicUrl"] = pixMaxUrl[len(pixMaxUrl)-1] + sources = append(sources, source) + } + + return sources, nil +} + func Sourcelist(buf []byte) (sources []map[string]interface{}, err error) { var info interface{} json.Unmarshal(buf, &info) -- Gitblit v1.8.0