package model import ( "fmt" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) const ( InitChangeFilter = -10000 DefaultChangeFilter = -99 DefaultRuminaFilter = -99 DefaultChewFilter = -99 DefaultFilterCorrect = 100 DefaultWeeklyActive = 1500 ) type NeckActiveHabit struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` NeckRingNumber string `json:"neckRingNumber"` CowId int64 `json:"cowId"` Lact int32 `json:"lact"` CalvingAge int32 `json:"calvingAge"` ActiveTime string `json:"activeTime"` Frameid int32 `json:"frameid"` HeatDate string `json:"heatDate"` Rumina int32 `json:"rumina"` Intake int32 `json:"intake"` Inactive int32 `json:"inactive"` Gasp int32 `json:"gasp"` Other int32 `json:"other"` High int32 `json:"high"` Active int32 `json:"active"` FilterHigh int32 `json:"filterHigh"` FilterRumina int32 `json:"filterRumina"` FilterChew int32 `json:"filterChew"` WeekHigh int32 `json:"weekHigh"` WeekHighHabit int32 `json:"weekHighHabit"` WeekRuminaHabit int32 `json:"weekRuminaHabit"` WeekIntakeHabit int32 `json:"weekIntakeHabit"` WeekChewHabit int32 `json:"weekChewHabit"` WeekInactiveHabit int32 `json:"weekInactiveHabit"` WeekOtherHabit int32 `json:"weekOtherHabit"` ChangeHigh int32 `json:"changeHigh"` ChangeRumina int32 `json:"changeRumina"` ChangeChew int32 `json:"changeChew"` ChangeAdjust int32 `json:"changeAdjust"` ChangeFilter int32 `json:"changeFilter"` RuminaFilter int32 `json:"ruminaFilter"` ChewFilter int32 `json:"chewFilter"` FilterCorrect int32 `json:"filterCorrect"` SumRumina int32 `json:"sumRumina"` SumIntake int32 `json:"sumIntake"` SumInactive int32 `json:"sumInactive"` SumActive int32 `json:"sumActive"` SumMinHigh int32 `json:"sumMinHigh"` SumMaxHigh int32 `json:"sumMaxHigh"` SumMinChew int32 `json:"SumMinChew"` BeforeThreeSumRumina int32 `json:"beforeThreeSumRumina"` BeforeThreeSumIntake int32 `json:"beforeThreeSumIntake"` Score int32 `json:"score"` IsMaxTime pasturePb.IsShow_Kind `json:"isMaxTime"` IsShow pasturePb.IsShow_Kind `json:"isShow"` RecordCount int32 `json:"recordCount"` FirmwareVersion int32 `json:"firmwareVersion"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (n *NeckActiveHabit) TableName() string { return "neck_active_habit" } func NewNeckActiveHabit(data *NeckRingOriginalMerge) *NeckActiveHabit { return &NeckActiveHabit{ PastureId: data.PastureId, Frameid: data.XframeId, HeatDate: data.ActiveDate, NeckRingNumber: data.NeckRingNumber, Active: data.Active, Gasp: data.Gasp, High: data.High, Inactive: data.Inactive, Intake: data.Intake, Other: data.Other, Rumina: data.Rumina, IsShow: data.IsShow, WeekHigh: DefaultWeeklyActive, IsMaxTime: pasturePb.IsShow_No, ChangeFilter: InitChangeFilter, FilterCorrect: InitChangeFilter, RuminaFilter: InitChangeFilter, ChewFilter: InitChangeFilter, ActiveTime: fmt.Sprintf("%s %02d:00:00", data.ActiveDate, data.XframeId*2+1), RecordCount: data.RecordCount, FirmwareVersion: data.FirmwareVersion, } } type NeckActiveHabitSlice []*NeckActiveHabit func (n NeckActiveHabitSlice) ToPB(curveName string) *pasturePb.CowBehaviorCurveData { res := &pasturePb.CowBehaviorCurveData{ OriginalDataList: make([]int32, 0), ChangeDataList: make([]int32, 0), SumDataList: make([]int32, 0), DataTimeList: make([]string, 0), EstrusList: make([]string, 0), EventList: make(map[string]string), } for _, v := range n { res.DataTimeList = append(res.DataTimeList, fmt.Sprintf("%s %02d", v.HeatDate, v.Frameid*2+1)) switch curveName { case "active": // 活动量 res.OriginalDataList = append(res.OriginalDataList, v.High) res.ChangeDataList = append(res.ChangeDataList, v.ChangeFilter) case "rumina": // 反刍 res.OriginalDataList = append(res.OriginalDataList, v.Rumina) res.ChangeDataList = append(res.ChangeDataList, v.ChangeRumina) res.SumDataList = append(res.SumDataList, v.SumRumina) case "intake": // 采食 res.OriginalDataList = append(res.OriginalDataList, v.Intake) res.SumDataList = append(res.SumDataList, v.SumIntake) case "inactive": // 休息 res.OriginalDataList = append(res.OriginalDataList, v.Inactive) res.SumDataList = append(res.SumDataList, v.SumInactive) case "chew": // 咀嚼 res.OriginalDataList = append(res.OriginalDataList, 0) res.ChangeDataList = append(res.ChangeDataList, v.ChangeChew) res.SumDataList = append(res.SumDataList, 0) case "immobility": // 静止 res.OriginalDataList = append(res.OriginalDataList, 0) res.SumDataList = append(res.SumDataList, 0) } } return res } func (n *NeckActiveHabit) SumAvg() { n.Rumina = n.Rumina / n.RecordCount * n.RecordCount n.Inactive = n.Inactive / n.RecordCount * n.RecordCount n.Active = n.Active / n.RecordCount * n.RecordCount n.Intake = n.Intake / n.RecordCount * n.RecordCount n.Other = n.Other / n.RecordCount * n.RecordCount n.Gasp = n.Gasp / n.RecordCount * n.RecordCount n.High = n.High / n.RecordCount * n.RecordCount } type MaxHabitIdModel struct { Id int64 `json:"id"` }