neck_ring_original.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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, pastureMap map[string]int64) *NeckRingOriginal {
  39. activeDateTimeType := pasturePb.ActiveTimeType_Twenty_Minutes
  40. pastureId := int64(0)
  41. if neckLog.Frameid%10 == 8 {
  42. activeDateTimeType = pasturePb.ActiveTimeType_Two_Hours
  43. }
  44. if pasture, ok := pastureMap[neckLog.Imei]; ok {
  45. pastureId = pasture
  46. }
  47. return &NeckRingOriginal{
  48. Uuid: neckLog.UUID,
  49. PastureId: pastureId,
  50. NeckRingNumber: fmt.Sprintf("%d", neckLog.Ecowid),
  51. Frameid: neckLog.Frameid,
  52. Rumina: neckLog.Rumina,
  53. Intake: neckLog.Intake,
  54. Inactive: neckLog.Inactive,
  55. Gasp: neckLog.Other,
  56. High: neckLog.Activitys,
  57. Active: neckLog.High,
  58. FirmwareVersion: neckLog.Sver,
  59. HardwareVersion: neckLog.Hver,
  60. Remain: neckLog.Remain,
  61. Voltage: neckLog.BAT,
  62. RestartReason: neckLog.STATUS,
  63. Upper: neckLog.UpPer,
  64. Imei: neckLog.Imei,
  65. ReceiveNumber: neckLog.Imei,
  66. ActiveDateType: activeDateTimeType,
  67. IsShow: pasturePb.IsShow_No,
  68. }
  69. }
  70. const (
  71. AvgHours = int32(6)
  72. JoinKey = "/"
  73. )
  74. type NeckRingOriginalMerge struct {
  75. Rumina int32
  76. Inactive int32
  77. Active int32
  78. Intake int32
  79. Other int32
  80. High int32
  81. Gasp int32
  82. ActiveDate string
  83. NeckRingNumber string
  84. XframeId int32
  85. ActiveDateType pasturePb.ActiveTimeType_Kind
  86. RecordCount int32
  87. PastureId int64
  88. }
  89. func (n *NeckRingOriginalMerge) IsMageData(data *NeckRingOriginal, xframeId int32) {
  90. avgParam := int32(1)
  91. if n.ActiveDateType == pasturePb.ActiveTimeType_Two_Hours {
  92. n.RecordCount = AvgHours
  93. avgParam = 6
  94. } else {
  95. n.RecordCount += 1
  96. }
  97. high := data.High * avgParam
  98. if high > 8800 {
  99. high = 8800
  100. }
  101. n.Rumina += data.Rumina * avgParam
  102. n.Inactive += data.Inactive * avgParam
  103. n.Active += data.Active * avgParam
  104. n.Intake += data.Intake * avgParam
  105. n.Other += data.Other * avgParam
  106. n.Gasp += data.Gasp * avgParam
  107. n.High += high
  108. n.ActiveDate = data.ActiveDate
  109. n.NeckRingNumber = data.NeckRingNumber
  110. n.XframeId = xframeId
  111. n.PastureId = data.PastureId
  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. }