neck_ring_original.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package model
  2. import (
  3. "math"
  4. "strconv"
  5. "strings"
  6. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  7. )
  8. type NeckRingOriginal struct {
  9. Id int64 `json:"id"`
  10. PastureId int64 `json:"pastureId"`
  11. Uuid string `json:"uuid"`
  12. NeckRingNumber string `json:"neckRingNumber"` // 脖环号 (对应老表字段EID1)
  13. ActiveDate string `json:"activeDate"` // 采集时间-天(YYYY-MM-DD对应老表字段heatdate)
  14. Hours int32 `json:"hours"` // 采集时间-小时(hours)
  15. Frameid int32 `json:"frameid"` // 采集时长(对应老表frameid)
  16. Rumina int32 `json:"rumina"` // 反刍时长(rumaina)
  17. Intake int32 `json:"intake"` // 采食时长(intake)
  18. Inactive int32 `json:"inactive"` // 静止时间(inactive)
  19. Gasp int32 `json:"gasp"` // 喘息时长(Other)
  20. High int32 `json:"high"` // 活动量(activitys)
  21. Active int32 `json:"active"` // 运动时长(High)
  22. Other int32 `json:"other"` // 其他时长
  23. FirmwareVersion int32 `json:"firmwareVersion"` // 固件版本(对应老表Version)
  24. HardwareVersion int32 `json:"hardwareVersion"` // 硬件版本
  25. Remain int32 `json:"remain"` // 脖环剩余数据量,57之后为上一次上报结果
  26. Voltage int32 `json:"voltage"` // 电池电压
  27. RestartReason int32 `json:"restartReason"` // 脖环重启原因 (对应老表HIB)
  28. Upper int32 `json:"upper"` // 脖环正向比例发射功率
  29. ActiveDateType pasturePb.ActiveTimeType_Kind `json:"ActiveDateTimeType"`
  30. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  31. Imei string `json:"imei"` // 4G模组IMEI(imei)
  32. ReceiveNumber string `json:"receiveNumber"` // 接收器编号
  33. CreatedAt int64 `json:"createdAt"`
  34. UpdatedAt int64 `json:"updatedAt"`
  35. }
  36. func (n *NeckRingOriginal) TableName() string {
  37. return "neck_ring_original"
  38. }
  39. var (
  40. AvgHours = int32(6)
  41. JoinKey = "/"
  42. )
  43. func (n *NeckRingOriginal) IsAvgHours() {
  44. if n.ActiveDateType == pasturePb.ActiveTimeType_Two_Hours {
  45. n.Remain *= AvgHours
  46. n.Inactive *= AvgHours
  47. n.Active *= AvgHours
  48. n.Intake *= AvgHours
  49. n.Other *= AvgHours
  50. n.Gasp *= AvgHours
  51. n.High *= AvgHours
  52. n.High = int32(math.Min(1800, float64(n.Other)))
  53. }
  54. }
  55. type NeckRingOriginalMerge struct {
  56. Rumina int32
  57. Inactive int32
  58. Active int32
  59. Intake int32
  60. Other int32
  61. High int32
  62. Gasp int32
  63. ActiveDateType pasturePb.ActiveTimeType_Kind
  64. }
  65. func (n *NeckRingOriginalMerge) IsMageData(data *NeckRingOriginal) {
  66. n.Rumina += data.Rumina
  67. n.Inactive += data.Inactive
  68. n.Active += data.Active
  69. n.Intake += data.Intake
  70. n.Other += data.Other
  71. n.Gasp += data.Gasp
  72. n.High += data.High
  73. }
  74. func (n *NeckRingOriginalMerge) SumAvg() {
  75. n.Rumina = n.Rumina / AvgHours * AvgHours
  76. n.Inactive = n.Inactive / AvgHours * AvgHours
  77. n.Active = n.Active / AvgHours * AvgHours
  78. n.Intake = n.Intake / AvgHours * AvgHours
  79. n.Other = n.Other / AvgHours * AvgHours
  80. n.Gasp = n.Gasp / AvgHours * AvgHours
  81. n.High = n.High / AvgHours * AvgHours
  82. }
  83. type NeckRingOriginalMap map[string]*NeckRingOriginalMerge
  84. func (n NeckRingOriginalMap) ForMatData() []*NeckActiveHabit {
  85. res := make([]*NeckActiveHabit, 0)
  86. for key, v := range n {
  87. keyStrList := strings.Split(key, JoinKey)
  88. if len(keyStrList) != 3 {
  89. continue
  90. }
  91. neckRingNumber := keyStrList[0]
  92. heatDate := keyStrList[1]
  93. frameId := keyStrList[2]
  94. frameIdInt, _ := strconv.Atoi(frameId)
  95. res = append(res, NewNeckActiveHabit(int32(frameIdInt), heatDate, neckRingNumber, v))
  96. }
  97. return res
  98. }