| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 | 
							- package util
 
- import (
 
- 	"fmt"
 
- 	"strings"
 
- 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
- )
 
- type NeckRingOriginal struct {
 
- 	Id              int64                         `json:"id"`
 
- 	PastureId       int64                         `json:"pastureId"`
 
- 	Uuid            string                        `json:"uuid"`
 
- 	NeckRingNumber  string                        `json:"neckRingNumber"`  // 脖环号 (对应老表字段EID1)
 
- 	ActiveDate      string                        `json:"activeDate"`      // 采集时间-天(YYYY-MM-DD对应老表字段heatdate)
 
- 	Hours           int32                         `json:"hours"`           // 采集时间-小时(hours)
 
- 	Frameid         int32                         `json:"frameid"`         // 采集时长(对应老表frameid)
 
- 	Rumina          int32                         `json:"rumina"`          // 反刍时长(rumaina)
 
- 	Intake          int32                         `json:"intake"`          // 采食时长(intake)
 
- 	Inactive        int32                         `json:"inactive"`        // 静止时间(inactive)
 
- 	Gasp            int32                         `json:"gasp"`            // 喘息时长(Other)
 
- 	High            int32                         `json:"high"`            // 活动量(activitys)
 
- 	Active          int32                         `json:"active"`          // 运动时长(High)
 
- 	Other           int32                         `json:"other"`           // 其他时长
 
- 	FirmwareVersion int32                         `json:"firmwareVersion"` // 固件版本(对应老表Version)
 
- 	HardwareVersion int32                         `json:"hardwareVersion"` // 硬件版本
 
- 	Remain          int32                         `json:"remain"`          // 脖环剩余数据量,57之后为上一次上报结果
 
- 	Voltage         int32                         `json:"voltage"`         // 电池电压
 
- 	RestartReason   int32                         `json:"restartReason"`   // 脖环重启原因 (对应老表HIB)
 
- 	Upper           int32                         `json:"upper"`           // 脖环正向比例发射功率
 
- 	ActiveDateType  pasturePb.ActiveTimeType_Kind `json:"ActiveDateTimeType"`
 
- 	IsShow          pasturePb.IsShow_Kind         `json:"isShow"`
 
- 	Imei            string                        `json:"imei"`          // 4G模组IMEI(imei)
 
- 	ReceiveNumber   string                        `json:"receiveNumber"` // 接收器编号
 
- 	CreatedAt       int64                         `json:"createdAt"`
 
- 	UpdatedAt       int64                         `json:"updatedAt"`
 
- }
 
- func (n *NeckRingOriginal) TableName() string {
 
- 	return "neck_ring_original"
 
- }
 
- var (
 
- 	AvgHours = int32(6)
 
- 	JoinKey  = "/"
 
- )
 
- type NeckRingOriginalMerge struct {
 
- 	Rumina         int32
 
- 	Inactive       int32
 
- 	Active         int32
 
- 	Intake         int32
 
- 	Other          int32
 
- 	High           int32
 
- 	Gasp           int32
 
- 	ActiveDate     string
 
- 	NeckRingNumber string
 
- 	XframeId       int32
 
- 	ActiveDateType pasturePb.ActiveTimeType_Kind
 
- 	RecordCount    int32
 
- }
 
- func (n *NeckRingOriginalMerge) IsMageData(data *NeckRingOriginal, xframeId int32) {
 
- 	if n.ActiveDateType == pasturePb.ActiveTimeType_Two_Hours {
 
- 		n.RecordCount = AvgHours
 
- 	} else {
 
- 		n.RecordCount += 1
 
- 	}
 
- 	n.Rumina += data.Rumina
 
- 	n.Inactive += data.Inactive
 
- 	n.Active += data.Active
 
- 	n.Intake += data.Intake
 
- 	n.Other += data.Other
 
- 	n.Gasp += data.Gasp
 
- 	n.High += data.High
 
- 	n.ActiveDate = data.ActiveDate
 
- 	n.NeckRingNumber = data.NeckRingNumber
 
- 	n.XframeId = xframeId
 
- }
 
- func (n *NeckRingOriginalMerge) 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 NeckRingOriginalMap map[string]*NeckRingOriginalMerge
 
- func (n NeckRingOriginalMap) ForMatData() []*NeckActiveHabit {
 
- 	res := make([]*NeckActiveHabit, 0)
 
- 	for key, v := range n {
 
- 		keyStrList := strings.Split(key, JoinKey)
 
- 		if len(keyStrList) != 3 {
 
- 			continue
 
- 		}
 
- 		res = append(res, NewNeckActiveHabit(v))
 
- 	}
 
- 	return res
 
- }
 
- func NewNeckActiveHabit(data *NeckRingOriginalMerge) *NeckActiveHabit {
 
- 	return &NeckActiveHabit{
 
- 		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,
 
- 		ActiveTime:     fmt.Sprintf("%s %02d:00:00", data.ActiveDate, data.XframeId),
 
- 	}
 
- }
 
- type NeckActiveHabit struct {
 
- 	Id                      int64                 `json:"id"`
 
- 	CowId                   int64                 `json:"cowId"`
 
- 	NeckRingNumber          string                `json:"neckRingNumber"`
 
- 	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"`
 
- 	AvgHighHabit            int32                 `json:"avgHighHabit"`
 
- 	AvgRuminaHabit          int32                 `json:"avgRuminaHabit"`
 
- 	AvgIntakeHabit          int32                 `json:"avgIntakeHabit"`
 
- 	AvgChewHabit            int32                 `json:"avgChewHabit"`
 
- 	AvgInactiveHabit        int32                 `json:"avgInactiveHabit"`
 
- 	AvgOtherHabit           int32                 `json:"avgOtherHabit"`
 
- 	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"`
 
- 	SumAct                  int32                 `json:"sumAct"`
 
- 	SumMinHigh              int32                 `json:"sumMinHigh"`
 
- 	SumMaxHigh              int32                 `json:"sumMaxHigh"`
 
- 	SumMinChew              int32                 `json:"SumMinChew"`
 
- 	SumRuminaBeforeThreeDay int32                 `json:"sumRuminaBeforeThreeDay"`
 
- 	SumIntakeBeforeThreeDay int32                 `json:"sumIntakeBeforeThreeDay"`
 
- 	Score                   int32                 `json:"score"`
 
- 	IsMaxTime               pasturePb.IsShow_Kind `json:"isMaxTime"`
 
- 	IsShow                  pasturePb.IsShow_Kind `json:"isShow"`
 
- 	ReceiveNumber           int32                 `json:"receiveNumber"`
 
- 	RecordCount             int32                 `json:"recordCount"`
 
- 	CreatedAt               int64                 `json:"createdAt"`
 
- 	UpdatedAt               int64                 `json:"updatedAt"`
 
- }
 
 
  |