zhangzengfei
2025-02-07 17f45fcc0a062a15372883de8909953071c51b3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package models
 
import (
    "fmt"
    "time"
 
    "model-engine/db"
    "model-engine/pkg/logger"
    "model-engine/service"
)
 
type LocationModel struct {
    AreaIds       map[string]struct{}
    Building      string       // 楼栋
    AlarmType     db.AlarmType // 预警方式
    KeyPersonType string       // 人员类型
    PersonLabel   string
    PersonCount   int // 人数, 出现的同类型人员数量
    Appearances   int // 出现次数,
    Duration      int // 时间范围, 单位天
    Task          *db.ModelTask
}
 
func (m *LocationModel) Init(task *db.ModelTask) error {
    m.AreaIds = make(map[string]struct{})
    for _, a := range task.DomainUnitIds {
        m.AreaIds[a] = struct{}{}
    }
 
    m.Task = task
    m.Building = task.Building
    m.AlarmType = task.AlarmType
    m.KeyPersonType = task.PersonType
    m.PersonLabel = task.PersonLabel
 
    for _, v := range task.Rules {
        if v.Alias == "personCount" {
            if val, ok := v.Value.(float64); ok {
                m.PersonCount = int(val)
            }
        }
 
        if v.Alias == "appearances" {
            if val, ok := v.Value.(float64); ok {
                m.Appearances = int(val)
            }
        }
 
        if v.Alias == "duration" {
            if val, ok := v.Value.(float64); ok {
                m.Duration = int(val)
            }
        }
    }
 
    // 默认计算30天的数据
    if m.Duration == 0 {
        m.Duration = 30
    }
 
    logger.Debugf("LocationModel init finish ...task id:%s, name:%s, rule:%+v", task.ID, task.Name, m)
 
    return nil
}
 
func (m *LocationModel) Run() error {
    // 根据配置的时间段天数, 过滤规则配置的相同重点人员类型和相同标签人员频繁出现的楼层地址
 
    results := make([]*db.ModelTaskResults, 0)
 
    logger.Debugf("task %s last filter result %d", m.Task.Name, len(results))
    return service.SaveTaskResults(results)
}
 
func (m *LocationModel) KeepAlive() error {
    db.GetDB().Model(m.Task).Where("id = ?", m.Task.ID).Update("last_run_time", time.Now())
    return nil
}
 
func (m *LocationModel) Shutdown() error {
    // 清理资源
    fmt.Println("Shutting down LocationModel Model")
    return nil
}
 
func (m *LocationModel) eventFormat() string {
    return ""
}