| | |
| | | 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 |
| | | } |
| | |
| | | // 查找指定时间范围内出行过的档案编号 |
| | | now := time.Now() |
| | | startDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).AddDate(0, 0, -m.Duration) |
| | | endDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) |
| | | |
| | | err := db.GetDB().Raw(` |
| | | SELECT |
| | | document_number, |
| | | frequent_address, |
| | | community_id, |
| | | org_id |
| | | FROM |
| | | snapshot_count_summary |
| | | WHERE |
| | |
| | | logger.Warnf(err.Error()) |
| | | } |
| | | |
| | | logger.Debugf("task %s base filter result %d", m.Task.Name, len(baseFilter)) |
| | | esCli := db.GetEsClient() |
| | | // 调用es分析此人的出行规律是否符合条件, 返回符合条件的次数和最后一次符合条件的时间 |
| | | sTime := startDate.Format(time.DateTime) |
| | | eTime := endDate.Format(time.DateTime) |
| | | |
| | | 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 { |
| | | // 写数据库 |
| | | result := &db.ModelTaskResults{ |
| | | Title: m.Task.Name, |
| | | Event: fmt.Sprintf("%s %d次", m.Task.Name, hitCount), |
| | | Event: fmt.Sprintf("%s - %s 时间段内, %s %d次", sTime, eTime, m.Task.Name, hitCount), |
| | | ModelID: m.Task.ModelID, |
| | | ModelTaskID: m.Task.ID, |
| | | CommunityId: p.CommunityId, |
| | | OrgID: p.OrgId, |
| | | ObjectIds: p.DocumentNumber, |
| | | Location: p.FrequentAddress, |
| | | PicDate: time.Unix(p.LastAppearanceTime, 0).Format(time.DateTime), |
| | | PicDate: pd, |
| | | FirstPersonID: p.DocumentNumber, |
| | | } |
| | | |
| | |
| | | |
| | | func (m *RegularityModel) Shutdown() error { |
| | | // 清理资源 |
| | | fmt.Println("Shutting down LocationModel Model") |
| | | fmt.Println("Shutting down accessRegularityS Model") |
| | | return nil |
| | | } |
| | | |
| | |
| | | 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 |
| | |
| | | |
| | | for _, record := range records { |
| | | // 解析时间 |
| | | t, err := time.Parse(layout, record.PicDate) |
| | | t, err := time.ParseInLocation(layout, record.PicDate, time.Local) |
| | | if err != nil { |
| | | fmt.Println("解析时间失败:", err) |
| | | continue |
| | |
| | | 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 |
| | | } |