| | |
| | | Unit: "", |
| | | Range: "", |
| | | Value: "", |
| | | ValType: "[{\"label\":\"进\", \"value\":\"in\"},{\"label\":\"出\", \"value\":\"out\"}]", |
| | | ValType: "string", |
| | | Operator: "==", |
| | | Options: "[{\"label\":\"进\", \"value\":\"in\"},{\"label\":\"出\", \"value\":\"out\"}]", |
| | | Sort: 3, |
| | | }, |
| | | }, |
| | |
| | | RuleArg struct { |
| | | Alias string `gorm:"column:alias" json:"alias"` // 参数的别名 |
| | | Name string `gorm:"column:name" json:"name"` // 参数名称 |
| | | Type string `gorm:"column:type" json:"type"` // 参数类型: input, option, range, image |
| | | Type string `gorm:"column:type" json:"type"` // 参数类型: input, select, range, image |
| | | Must bool `gorm:"column:must" json:"must"` // 是否必填 |
| | | Unit string `gorm:"column:unit" json:"unit"` // 单位 |
| | | Range string `gorm:"column:range" json:"range"` // 值的范围,eg:0,100表示从0到100 |
| | | Value string `gorm:"column:value" json:"value"` // 参数值 |
| | | ValType string `gorm:"column:val_type" json:"valType"` // 参数值类型 int, string, bool |
| | | Operator string `gorm:"column:operator" json:"operator"` // 运算符 |
| | | Options string `gorm:"column:options" json:"options"` // 选项的备选参数 |
| | | Sort int `gorm:"column:sort;default:0" json:"sort"` // 参数顺序 |
| | | } |
| | | |
| | | ModelRuleSet struct { |
| | | Alias string `json:"alias"` // 参数的别名 |
| | | Type string `json:"type"` // 参数类型: input, option, range, image |
| | | Type string `json:"type"` // 参数类型: input, select, range, image |
| | | Name string `json:"name"` // 参数名称 |
| | | Value interface{} `json:"value"` // 参数值 |
| | | ValType string `json:"valType"` // 值类型 |
| | |
| | | return "" |
| | | } |
| | | |
| | | func countValidDays(records []*service.ESRecordInfo, startHour, endHort int, direction string) int { |
| | | func countValidDays(records []*service.ESRecordInfo, startHour, endHour int, direction string) int { |
| | | layout := "2006-01-02 15:04:05" // 时间格式 |
| | | lastDirectionMap := make(map[string]string) // 记录最后一条 Direction |
| | | lastTimeMap := make(map[string]time.Time) // 记录最后一条时间 |
| | | |
| | | // 判断是否跨天 |
| | | var isCrossDay bool |
| | | if endHour < startHour { |
| | | isCrossDay = true |
| | | } |
| | | |
| | | for _, record := range records { |
| | | // 解析时间 |
| | |
| | | hour := t.Hour() |
| | | var key string |
| | | |
| | | // 判断时间范围,并归属到某一天 |
| | | if hour >= startHour { // 21:00-23:59 归属当天 |
| | | key = t.Format("2006-01-02") |
| | | } else if hour < endHort { // 00:00-02:59 归属前一天 |
| | | key = t.AddDate(0, 0, -1).Format("2006-01-02") |
| | | if !isCrossDay { |
| | | // 判断时间范围,并归属到某一天 |
| | | if hour >= startHour && hour < endHour { |
| | | key = t.Format("2006-01-02") |
| | | } else { |
| | | continue // 不在统计范围内 |
| | | } |
| | | } else { |
| | | continue // 不在统计范围内 |
| | | // 判断时间范围,并归属到某一天 |
| | | if hour >= startHour { // 21:00-23:59 归属当天 |
| | | key = t.Format("2006-01-02") |
| | | } else if hour < endHour { // 00:00-02:59 归属前一天 |
| | | key = t.AddDate(0, 0, -1).Format("2006-01-02") |
| | | } else { |
| | | continue // 不在统计范围内 |
| | | } |
| | | } |
| | | |
| | | // 记录该时间段内的最后一条数据 |
| | |
| | | } |
| | | |
| | | var modelRegistry = map[string]func() Model{ |
| | | "gather": func() Model { return &GatherModel{} }, |
| | | "disappear": func() Model { return &DisappearModel{} }, |
| | | "location": func() Model { return &LocationModel{} }, |
| | | "night": func() Model { return &nightModel{} }, |
| | | "gather": func() Model { return &GatherModel{} }, |
| | | "disappear": func() Model { return &DisappearModel{} }, |
| | | "location": func() Model { return &LocationModel{} }, |
| | | "night": func() Model { return &nightModel{} }, |
| | | "accessRegularity": func() Model { return &RegularityModel{} }, |
| | | // 添加其他模型 |
| | | } |
| | | |