neck_ring_original.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package model
  2. import (
  3. "fmt"
  4. "strings"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type NeckRingOriginal struct {
  8. Id int64 `json:"id"`
  9. PastureId int64 `json:"pastureId"`
  10. Uuid string `json:"uuid"`
  11. NeckRingNumber string `json:"neckRingNumber"` // 脖环号 (对应老表字段EID1)
  12. ActiveDate string `json:"activeDate"` // 采集时间-天(YYYY-MM-DD对应老表字段heatdate)
  13. Hours int32 `json:"hours"` // 采集时间-小时(hours)
  14. Frameid int32 `json:"frameid"` // 采集时长(对应老表frameid)
  15. Rumina int32 `json:"rumina"` // 反刍时长(rumaina)
  16. Intake int32 `json:"intake"` // 采食时长(intake)
  17. Inactive int32 `json:"inactive"` // 静止时间(inactive)
  18. Gasp int32 `json:"gasp"` // 喘息时长(Other)
  19. High int32 `json:"high"` // 活动量(activitys)
  20. Active int32 `json:"active"` // 运动时长(High)
  21. Other int32 `json:"other"` // 其他时长
  22. FirmwareVersion int32 `json:"firmwareVersion"` // 固件版本(对应老表Version)
  23. HardwareVersion int32 `json:"hardwareVersion"` // 硬件版本
  24. Remain int32 `json:"remain"` // 脖环剩余数据量,57之后为上一次上报结果
  25. Voltage int32 `json:"voltage"` // 电池电压
  26. RestartReason int32 `json:"restartReason"` // 脖环重启原因 (对应老表HIB)
  27. Upper int32 `json:"upper"` // 脖环正向比例发射功率
  28. ActiveDateType pasturePb.ActiveTimeType_Kind `json:"ActiveDateTimeType"`
  29. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  30. Imei string `json:"imei"` // 4G模组IMEI(imei)
  31. ReceiveNumber string `json:"receiveNumber"` // 接收器编号
  32. CreatedAt int64 `json:"createdAt"`
  33. UpdatedAt int64 `json:"updatedAt"`
  34. }
  35. func (n *NeckRingOriginal) TableName() string {
  36. return "neck_ring_original"
  37. }
  38. func NewNeckRingOriginal(neckLog *Behavior) *NeckRingOriginal {
  39. activeDateTimeType := pasturePb.ActiveTimeType_Twenty_Minutes
  40. if neckLog.Frameid%10 == 8 {
  41. activeDateTimeType = pasturePb.ActiveTimeType_Two_Hours
  42. }
  43. return &NeckRingOriginal{
  44. Uuid: neckLog.UUID,
  45. PastureId: 1,
  46. NeckRingNumber: fmt.Sprintf("%d", neckLog.Ecowid),
  47. Frameid: neckLog.Frameid,
  48. Rumina: neckLog.Rumina,
  49. Intake: neckLog.Intake,
  50. Inactive: neckLog.Inactive,
  51. Gasp: neckLog.Other,
  52. High: neckLog.Activitys,
  53. Active: neckLog.High,
  54. FirmwareVersion: neckLog.Sver,
  55. HardwareVersion: neckLog.Hver,
  56. Remain: neckLog.Remain,
  57. Voltage: neckLog.BAT,
  58. RestartReason: neckLog.STATUS,
  59. Upper: neckLog.UpPer,
  60. Imei: neckLog.Imei,
  61. ReceiveNumber: neckLog.Imei,
  62. ActiveDateType: activeDateTimeType,
  63. IsShow: pasturePb.IsShow_No,
  64. }
  65. }
  66. const (
  67. AvgHours = int32(6)
  68. JoinKey = "/"
  69. )
  70. type NeckRingOriginalMerge struct {
  71. Rumina int32
  72. Inactive int32
  73. Active int32
  74. Intake int32
  75. Other int32
  76. High int32
  77. Gasp int32
  78. ActiveDate string
  79. NeckRingNumber string
  80. XframeId int32
  81. ActiveDateType pasturePb.ActiveTimeType_Kind
  82. RecordCount int32
  83. PastureId int64
  84. FirmwareVersion int32
  85. IsShow pasturePb.IsShow_Kind
  86. }
  87. func (n *NeckRingOriginalMerge) IsMageData(data *NeckRingOriginal, xframeId int32) {
  88. avgParam := int32(1)
  89. if n.ActiveDateType == pasturePb.ActiveTimeType_Two_Hours {
  90. n.RecordCount = AvgHours
  91. avgParam = 6
  92. } else {
  93. n.RecordCount += 1
  94. }
  95. high := data.High * avgParam
  96. if high > 8800 {
  97. high = 8800
  98. }
  99. n.Rumina += data.Rumina * avgParam
  100. n.Inactive += data.Inactive * avgParam
  101. n.Active += data.Active * avgParam
  102. n.Intake += data.Intake * avgParam
  103. n.Other += data.Other * avgParam
  104. n.Gasp += data.Gasp * avgParam
  105. n.High += high
  106. n.ActiveDate = data.ActiveDate
  107. n.NeckRingNumber = data.NeckRingNumber
  108. n.XframeId = xframeId
  109. n.PastureId = data.PastureId
  110. n.FirmwareVersion = data.FirmwareVersion
  111. n.IsShow = pasturePb.IsShow_No
  112. }
  113. func (n *NeckRingOriginalMerge) SumAvg() {
  114. n.Rumina = int32(float32(n.Rumina) / float32(n.RecordCount) * float32(n.RecordCount))
  115. n.Inactive = int32(float32(n.Inactive) / float32(n.RecordCount) * float32(n.RecordCount))
  116. n.Active = int32(float32(n.Active) / float32(n.RecordCount) * float32(n.RecordCount))
  117. n.Intake = int32(float32(n.Intake) / float32(n.RecordCount) * float32(n.RecordCount))
  118. n.Other = int32(float32(n.Other) / float32(n.RecordCount) * float32(n.RecordCount))
  119. n.Gasp = int32(float32(n.Gasp) / float32(n.RecordCount) * float32(n.RecordCount))
  120. n.High = int32(float32(n.High) / float32(n.RecordCount) * float32(n.RecordCount))
  121. }
  122. type NeckRingOriginalMap map[string]*NeckRingOriginalMerge
  123. func (n NeckRingOriginalMap) ForMatData() []*NeckActiveHabit {
  124. res := make([]*NeckActiveHabit, 0)
  125. for key, v := range n {
  126. keyStrList := strings.Split(key, JoinKey)
  127. if len(keyStrList) != 3 {
  128. continue
  129. }
  130. res = append(res, NewNeckActiveHabit(v))
  131. }
  132. return res
  133. }