model.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package util
  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. var (
  39. AvgHours = int32(6)
  40. JoinKey = "/"
  41. )
  42. type NeckRingOriginalMerge struct {
  43. Rumina int32
  44. Inactive int32
  45. Active int32
  46. Intake int32
  47. Other int32
  48. High int32
  49. Gasp int32
  50. ActiveDate string
  51. NeckRingNumber string
  52. XframeId int32
  53. ActiveDateType pasturePb.ActiveTimeType_Kind
  54. RecordCount int32
  55. }
  56. func (n *NeckRingOriginalMerge) IsMageData(data *NeckRingOriginal, xframeId int32) {
  57. if n.ActiveDateType == pasturePb.ActiveTimeType_Two_Hours {
  58. n.RecordCount = AvgHours
  59. } else {
  60. n.RecordCount += 1
  61. }
  62. n.Rumina += data.Rumina
  63. n.Inactive += data.Inactive
  64. n.Active += data.Active
  65. n.Intake += data.Intake
  66. n.Other += data.Other
  67. n.Gasp += data.Gasp
  68. n.High += data.High
  69. n.ActiveDate = data.ActiveDate
  70. n.NeckRingNumber = data.NeckRingNumber
  71. n.XframeId = xframeId
  72. }
  73. func (n *NeckRingOriginalMerge) SumAvg() {
  74. n.Rumina = n.Rumina / n.RecordCount * n.RecordCount
  75. n.Inactive = n.Inactive / n.RecordCount * n.RecordCount
  76. n.Active = n.Active / n.RecordCount * n.RecordCount
  77. n.Intake = n.Intake / n.RecordCount * n.RecordCount
  78. n.Other = n.Other / n.RecordCount * n.RecordCount
  79. n.Gasp = n.Gasp / n.RecordCount * n.RecordCount
  80. n.High = n.High / n.RecordCount * n.RecordCount
  81. }
  82. type NeckRingOriginalMap map[string]*NeckRingOriginalMerge
  83. func (n NeckRingOriginalMap) ForMatData() []*NeckActiveHabit {
  84. res := make([]*NeckActiveHabit, 0)
  85. for key, v := range n {
  86. keyStrList := strings.Split(key, JoinKey)
  87. if len(keyStrList) != 3 {
  88. continue
  89. }
  90. res = append(res, NewNeckActiveHabit(v))
  91. }
  92. return res
  93. }
  94. func NewNeckActiveHabit(data *NeckRingOriginalMerge) *NeckActiveHabit {
  95. return &NeckActiveHabit{
  96. Frameid: data.XframeId,
  97. HeatDate: data.ActiveDate,
  98. NeckRingNumber: data.NeckRingNumber,
  99. Active: data.Active,
  100. Gasp: data.Gasp,
  101. High: data.High,
  102. Inactive: data.Inactive,
  103. Intake: data.Intake,
  104. Other: data.Other,
  105. Rumina: data.Rumina,
  106. ActiveTime: fmt.Sprintf("%s %02d:00:00", data.ActiveDate, data.XframeId),
  107. }
  108. }
  109. type NeckActiveHabit struct {
  110. Id int64 `json:"id"`
  111. CowId int64 `json:"cowId"`
  112. NeckRingNumber string `json:"neckRingNumber"`
  113. ActiveTime string `json:"activeTime"`
  114. Frameid int32 `json:"frameid"`
  115. HeatDate string `json:"heatDate"`
  116. Rumina int32 `json:"rumina"`
  117. Intake int32 `json:"intake"`
  118. Inactive int32 `json:"inactive"`
  119. Gasp int32 `json:"gasp"`
  120. Other int32 `json:"other"`
  121. High int32 `json:"high"`
  122. Active int32 `json:"active"`
  123. FilterHigh int32 `json:"filterHigh"`
  124. FilterRumina int32 `json:"filterRumina"`
  125. FilterChew int32 `json:"filterChew"`
  126. WeekHigh int32 `json:"weekHigh"`
  127. AvgHighHabit int32 `json:"avgHighHabit"`
  128. AvgRuminaHabit int32 `json:"avgRuminaHabit"`
  129. AvgIntakeHabit int32 `json:"avgIntakeHabit"`
  130. AvgChewHabit int32 `json:"avgChewHabit"`
  131. AvgInactiveHabit int32 `json:"avgInactiveHabit"`
  132. AvgOtherHabit int32 `json:"avgOtherHabit"`
  133. ChangeHigh int32 `json:"changeHigh"`
  134. ChangeRumina int32 `json:"changeRumina"`
  135. ChangeChew int32 `json:"changeChew"`
  136. ChangeAdjust int32 `json:"changeAdjust"`
  137. ChangeFilter int32 `json:"changeFilter"`
  138. RuminaFilter int32 `json:"ruminaFilter"`
  139. ChewFilter int32 `json:"chewFilter"`
  140. FilterCorrect int32 `json:"filterCorrect"`
  141. SumRumina int32 `json:"sumRumina"`
  142. SumIntake int32 `json:"sumIntake"`
  143. SumInactive int32 `json:"sumInactive"`
  144. SumAct int32 `json:"sumAct"`
  145. SumMinHigh int32 `json:"sumMinHigh"`
  146. SumMaxHigh int32 `json:"sumMaxHigh"`
  147. SumMinChew int32 `json:"SumMinChew"`
  148. SumRuminaBeforeThreeDay int32 `json:"sumRuminaBeforeThreeDay"`
  149. SumIntakeBeforeThreeDay int32 `json:"sumIntakeBeforeThreeDay"`
  150. Score int32 `json:"score"`
  151. IsMaxTime pasturePb.IsShow_Kind `json:"isMaxTime"`
  152. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  153. ReceiveNumber int32 `json:"receiveNumber"`
  154. RecordCount int32 `json:"recordCount"`
  155. CreatedAt int64 `json:"createdAt"`
  156. UpdatedAt int64 `json:"updatedAt"`
  157. }