| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | package modelimport (	"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"}func NewNeckRingOriginal(neckLog *Behavior, pastureId int64) *NeckRingOriginal {	activeDateTimeType := pasturePb.ActiveTimeType_Twenty_Minutes	if neckLog.Frameid%10 == 8 {		activeDateTimeType = pasturePb.ActiveTimeType_Two_Hours	}	return &NeckRingOriginal{		Uuid:            neckLog.UUID,		PastureId:       pastureId,		NeckRingNumber:  fmt.Sprintf("%d", neckLog.Ecowid),		Frameid:         neckLog.Frameid,		Rumina:          neckLog.Rumina,		Intake:          neckLog.Intake,		Inactive:        neckLog.Inactive,		Gasp:            neckLog.Other,		High:            neckLog.Activitys,		Active:          neckLog.High,		FirmwareVersion: neckLog.Sver,		HardwareVersion: neckLog.Hver,		Remain:          neckLog.Remain,		Voltage:         neckLog.BAT,		RestartReason:   neckLog.STATUS,		Upper:           neckLog.UpPer,		Imei:            neckLog.Imei,		ReceiveNumber:   neckLog.Imei,		ActiveDateType:  activeDateTimeType,		IsShow:          pasturePb.IsShow_No,	}}const (	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	PastureId       int64	FirmwareVersion int32	Voltage         int32	IsShow          pasturePb.IsShow_Kind}func (n *NeckRingOriginalMerge) IsMageData(data *NeckRingOriginal, xframeId int32) {	if n.RecordCount == 6 {		return	}	avgParam := int32(1)	if n.ActiveDateType == pasturePb.ActiveTimeType_Two_Hours {		n.RecordCount = AvgHours		avgParam = DefaultRecordCount	} else {		n.RecordCount += 1	}	high := data.High * avgParam	if high > 8800 {		high = 8800	}	n.Rumina += data.Rumina * avgParam	n.Inactive += data.Inactive * avgParam	n.Active += data.Active * avgParam	n.Intake += data.Intake * avgParam	n.Other += data.Other * avgParam	n.Gasp += data.Gasp * avgParam	n.High += high	n.Voltage += data.Voltage	n.ActiveDate = data.ActiveDate	n.NeckRingNumber = data.NeckRingNumber	n.XframeId = xframeId	n.PastureId = data.PastureId	n.FirmwareVersion = data.FirmwareVersion	n.IsShow = pasturePb.IsShow_No}func (n *NeckRingOriginalMerge) SumAvg() {	n.Rumina = int32(float32(n.Rumina) / float32(n.RecordCount) * float32(n.RecordCount))	n.Inactive = int32(float32(n.Inactive) / float32(n.RecordCount) * float32(n.RecordCount))	n.Active = int32(float32(n.Active) / float32(n.RecordCount) * float32(n.RecordCount))	n.Intake = int32(float32(n.Intake) / float32(n.RecordCount) * float32(n.RecordCount))	n.Other = int32(float32(n.Other) / float32(n.RecordCount) * float32(n.RecordCount))	n.Gasp = int32(float32(n.Gasp) / float32(n.RecordCount) * float32(n.RecordCount))	n.High = int32(float32(n.High) / float32(n.RecordCount) * float32(n.RecordCount))	n.Voltage = int32(float32(n.Voltage) / float32(n.RecordCount))}type NeckRingOriginalMap map[string]*NeckRingOriginalMergefunc (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}
 |