| | |
| | | |
| | | } |
| | | |
| | | //根据摄像机列表和时间查询人员浏览轨迹 |
| | | 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 = `{ |
| | |
| | | return sources, nil |
| | | } |
| | | |
| | | //根据抓拍人员id更新(picurl)图片地址---预开发 |
| | | //根据抓拍人员id更新(picurl)图片地址 |
| | | 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 |
| | |
| | | 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" |
| | |
| | | } |
| | | ` |
| | | //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!") |
| | |
| | | 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) |
| | |
| | | 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 |
| | | } |
| | |
| | | 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) |
| | |
| | | return s, nil |
| | | } |
| | | |
| | | //解析抓拍库人员结构 |
| | | 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) |