zhangqian
2024-12-12 e012f2c5e7c6bc79277ff3317efae7d952a18d22
增加频次过滤
2个文件已修改
16 ■■■■■ 已修改文件
db/task_results.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/gather_model.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/task_results.go
@@ -18,6 +18,7 @@
    Location    string `json:"location" gorm:"type:varchar(255)"`                                        //发生地点
    Building    string `json:"building" gorm:"type:varchar(255);"`                                       //楼栋
    Floor       string `json:"floor"       gorm:"type:varchar(255);"`                                    //楼层
    PicDate     string `json:"picDate"       gorm:"type:varchar(255);"`                                  //抓拍时间
}
func (m *ModelTaskResults) TableName() string {
models/gather_model.go
@@ -227,6 +227,19 @@
                                                            },
                                                        },
                                                    },
                                                    "frequency_filter": map[string]interface{}{ // 添加频率过滤
                                                        "bucket_selector": map[string]interface{}{
                                                            "buckets_path": map[string]interface{}{
                                                                "eventCount": "_count", // 聚合事件次数
                                                            },
                                                            "script": map[string]interface{}{
                                                                "source": "params.eventCount >= params.threshold", // 筛选频率达到阈值的事件
                                                                "params": map[string]interface{}{
                                                                    "threshold": gatherModel.Threshold,
                                                                },
                                                            },
                                                        },
                                                    },
                                                },
                                            },
                                        },
@@ -294,7 +307,7 @@
                                        if gatherEvents, ok := floorBucket.(map[string]interface{})["gather_events"].(map[string]interface{})["buckets"].([]interface{}); ok {
                                            for _, eventBucket := range gatherEvents {
                                                key := int64(eventBucket.(map[string]interface{})["key"].(float64)) / 1000 // 将毫秒转换为秒
                                                timestamp := time.Unix(key, 0).Format("2006-01-02T15:04:05")
                                                timestamp := time.Unix(key, 0).Format("2006-01-02 15:04:05")
                                                // 解析人员
                                                if peopleBuckets, ok := eventBucket.(map[string]interface{})["people"].(map[string]interface{})["buckets"].([]interface{}); ok {