neck_ring_original.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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, pastureId int64) *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: pastureId,
  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. Voltage int32
  86. IsShow pasturePb.IsShow_Kind
  87. }
  88. func (n *NeckRingOriginalMerge) IsMageData(data *NeckRingOriginal, xframeId int32) {
  89. if n.RecordCount == 6 {
  90. return
  91. }
  92. avgParam := int32(1)
  93. if n.ActiveDateType == pasturePb.ActiveTimeType_Two_Hours {
  94. n.RecordCount = AvgHours
  95. avgParam = DefaultRecordCount
  96. } else {
  97. n.RecordCount += 1
  98. }
  99. high := data.High * avgParam
  100. if high > 8800 {
  101. high = 8800
  102. }
  103. n.Rumina += data.Rumina * avgParam
  104. n.Inactive += data.Inactive * avgParam
  105. n.Active += data.Active * avgParam
  106. n.Intake += data.Intake * avgParam
  107. n.Other += data.Other * avgParam
  108. n.Gasp += data.Gasp * avgParam
  109. n.High += high
  110. n.Voltage += data.Voltage
  111. n.ActiveDate = data.ActiveDate
  112. n.NeckRingNumber = data.NeckRingNumber
  113. n.XframeId = xframeId
  114. n.PastureId = data.PastureId
  115. n.FirmwareVersion = data.FirmwareVersion
  116. n.IsShow = pasturePb.IsShow_No
  117. }
  118. func (n *NeckRingOriginalMerge) SumAvg() {
  119. n.Rumina = int32(float32(n.Rumina) / float32(n.RecordCount) * float32(n.RecordCount))
  120. n.Inactive = int32(float32(n.Inactive) / float32(n.RecordCount) * float32(n.RecordCount))
  121. n.Active = int32(float32(n.Active) / float32(n.RecordCount) * float32(n.RecordCount))
  122. n.Intake = int32(float32(n.Intake) / float32(n.RecordCount) * float32(n.RecordCount))
  123. n.Other = int32(float32(n.Other) / float32(n.RecordCount) * float32(n.RecordCount))
  124. n.Gasp = int32(float32(n.Gasp) / float32(n.RecordCount) * float32(n.RecordCount))
  125. n.High = int32(float32(n.High) / float32(n.RecordCount) * float32(n.RecordCount))
  126. n.Voltage = int32(float32(n.Voltage) / float32(n.RecordCount))
  127. }
  128. type NeckRingOriginalMap map[string]*NeckRingOriginalMerge
  129. func (n NeckRingOriginalMap) ForMatData() []*NeckActiveHabit {
  130. res := make([]*NeckActiveHabit, 0)
  131. for key, v := range n {
  132. keyStrList := strings.Split(key, JoinKey)
  133. if len(keyStrList) != 3 {
  134. continue
  135. }
  136. res = append(res, NewNeckActiveHabit(v))
  137. }
  138. return res
  139. }