| | |
| | | return fmt.Errorf("task id:%s, %s timeRange Time range setting error. %+v", task.ID, task.Name, task.Rules) |
| | | } |
| | | |
| | | logger.Debugf("LocationModel init finish ...task id:%s, name:%s, rule:%+v", task.ID, task.Name, m) |
| | | logger.Debugf("AccessRegularity init finish ...task id:%s, name:%s, rule:%+v", task.ID, task.Name, m) |
| | | |
| | | return nil |
| | | } |
| | |
| | | logger.Warnf(err.Error()) |
| | | } |
| | | |
| | | logger.Debugf("task %s base filter result %d", m.Task.Name, len(baseFilter)) |
| | | esCli := db.GetEsClient() |
| | | for _, p := range baseFilter { |
| | | // 调用es分析此人的出行规律是否符合条件, 返回符合条件的次数和最后一次符合条件的时间 |
| | | sTime := startDate.Format(time.DateTime) |
| | | eTime := time.Now().Format(time.DateTime) |
| | | captures, err := service.QueryEsRecord(esCli, sTime, eTime, nil, []interface{}{p.CommunityId}, []string{p.DocumentNumber}) |
| | | //logger.Debugf("task %s person %s captures %d", m.Task.Name, p.DocumentNumber, len(captures)) |
| | | |
| | | if len(captures) == 0 || err != nil { |
| | | continue |
| | | } |
| | | //logger.Debugf("task %s person %s captures %+v", m.Task.Name, p.DocumentNumber, captures[0]) |
| | | |
| | | // 根据抓拍时间和出入方向,计算符合规则内的出入次数 |
| | | hitCount := countValidDays(captures, m.StartHour, m.EndHour, m.LastDirection) |
| | | hitCount, pd := countValidDays(captures, m.StartHour, m.EndHour, m.LastDirection) |
| | | |
| | | if hitCount > m.Appearances { |
| | | // 写数据库 |
| | |
| | | OrgID: p.OrgId, |
| | | ObjectIds: p.DocumentNumber, |
| | | Location: p.FrequentAddress, |
| | | PicDate: time.Unix(p.LastAppearanceTime, 0).Format(time.DateTime), |
| | | PicDate: pd, |
| | | FirstPersonID: p.DocumentNumber, |
| | | } |
| | | |
| | |
| | | return "" |
| | | } |
| | | |
| | | func countValidDays(records []*service.ESRecordInfo, startHour, endHour int, direction string) int { |
| | | func countValidDays(records []*service.ESRecordInfo, startHour, endHour int, direction string) (int, string) { |
| | | layout := "2006-01-02 15:04:05" // 时间格式 |
| | | lastDirectionMap := make(map[string]string) // 记录最后一条 Direction |
| | | lastTimeMap := make(map[string]time.Time) // 记录最后一条时间 |
| | | lastPicDate := "" |
| | | |
| | | // 判断是否跨天 |
| | | var isCrossDay bool |
| | |
| | | if lastTime, exists := lastTimeMap[key]; !exists || t.After(lastTime) { |
| | | lastTimeMap[key] = t |
| | | lastDirectionMap[key] = record.CameraLocation.Direction |
| | | lastPicDate = record.PicDate |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | return count |
| | | return count, lastPicDate |
| | | } |
| | |
| | | if err != nil { |
| | | return err |
| | | } |
| | | logger.Debugf("records %s last result %s", m.Task.Name, records) |
| | | logger.Debugf("records %s last result %+v", m.Task.Name, records) |
| | | domains, err := domainToLocation(records) |
| | | if err != nil { |
| | | return err |
| | |
| | | "filter": filters, |
| | | }, |
| | | }, |
| | | "size": 0, |
| | | "sort": []interface{}{map[string]interface{}{"picDate": map[string]interface{}{"order": "asc"}}}, |
| | | "_source": map[string]interface{}{"includes": []interface{}{}, "excludes": []interface{}{"*.feature"}}, |
| | | } |
| | |
| | | PicMaxUrl: source["picMaxUrl"].(string), |
| | | } |
| | | |
| | | cameraLocation := source["cameraId"].(map[string]interface{}) |
| | | cameraLocation := source["cameraLocation"].(map[string]interface{}) |
| | | record.CameraLocation = CameraLocation{ |
| | | Building: cameraLocation["building"].(string), |
| | | Unit: cameraLocation["unit"].(string), |