neck_active_habit.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package model
  2. import (
  3. "fmt"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. const (
  7. InitChangeFilter = -10000
  8. DefaultChangeFilter = -99
  9. DefaultRuminaFilter = -99
  10. DefaultChewFilter = -99
  11. DefaultFilterCorrect = 100
  12. DefaultWeeklyActive = 1500
  13. )
  14. type NeckActiveHabit struct {
  15. Id int64 `json:"id"`
  16. PastureId int64 `json:"pastureId"`
  17. NeckRingNumber string `json:"neckRingNumber"`
  18. CowId int64 `json:"cowId"`
  19. Lact int32 `json:"lact"`
  20. CalvingAge int32 `json:"calvingAge"`
  21. ActiveTime string `json:"activeTime"`
  22. Frameid int32 `json:"frameid"`
  23. HeatDate string `json:"heatDate"`
  24. Rumina int32 `json:"rumina"`
  25. Intake int32 `json:"intake"`
  26. Inactive int32 `json:"inactive"`
  27. Gasp int32 `json:"gasp"`
  28. Other int32 `json:"other"`
  29. High int32 `json:"high"`
  30. Active int32 `json:"active"`
  31. FilterHigh int32 `json:"filterHigh"`
  32. FilterRumina int32 `json:"filterRumina"`
  33. FilterChew int32 `json:"filterChew"`
  34. WeekHigh int32 `json:"weekHigh"`
  35. AvgHighHabit int32 `json:"avgHighHabit"`
  36. AvgRuminaHabit int32 `json:"avgRuminaHabit"`
  37. AvgIntakeHabit int32 `json:"avgIntakeHabit"`
  38. AvgChewHabit int32 `json:"avgChewHabit"`
  39. AvgInactiveHabit int32 `json:"avgInactiveHabit"`
  40. AvgOtherHabit int32 `json:"avgOtherHabit"`
  41. ChangeHigh int32 `json:"changeHigh"`
  42. ChangeRumina int32 `json:"changeRumina"`
  43. ChangeChew int32 `json:"changeChew"`
  44. ChangeAdjust int32 `json:"changeAdjust"`
  45. ChangeFilter int32 `json:"changeFilter"`
  46. RuminaFilter int32 `json:"ruminaFilter"`
  47. ChewFilter int32 `json:"chewFilter"`
  48. FilterCorrect int32 `json:"filterCorrect"`
  49. SumRumina int32 `json:"sumRumina"`
  50. SumIntake int32 `json:"sumIntake"`
  51. SumInactive int32 `json:"sumInactive"`
  52. SumAct int32 `json:"sumAct"`
  53. SumMinHigh int32 `json:"sumMinHigh"`
  54. SumMaxHigh int32 `json:"sumMaxHigh"`
  55. SumMinChew int32 `json:"SumMinChew"`
  56. SumRuminaBeforeThreeDay int32 `json:"sumRuminaBeforeThreeDay"`
  57. SumIntakeBeforeThreeDay int32 `json:"sumIntakeBeforeThreeDay"`
  58. Score int32 `json:"score"`
  59. IsMaxTime pasturePb.IsShow_Kind `json:"isMaxTime"`
  60. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  61. RecordCount int32 `json:"recordCount"`
  62. FirmwareVersion int32 `json:"firmwareVersion"`
  63. CreatedAt int64 `json:"createdAt"`
  64. UpdatedAt int64 `json:"updatedAt"`
  65. }
  66. func (n *NeckActiveHabit) TableName() string {
  67. return "neck_active_habit"
  68. }
  69. func NewNeckActiveHabit(data *NeckRingOriginalMerge) *NeckActiveHabit {
  70. return &NeckActiveHabit{
  71. PastureId: data.PastureId,
  72. Frameid: data.XframeId,
  73. HeatDate: data.ActiveDate,
  74. NeckRingNumber: data.NeckRingNumber,
  75. Active: data.Active,
  76. Gasp: data.Gasp,
  77. High: data.High,
  78. Inactive: data.Inactive,
  79. Intake: data.Intake,
  80. Other: data.Other,
  81. Rumina: data.Rumina,
  82. WeekHigh: DefaultWeeklyActive,
  83. IsShow: pasturePb.IsShow_No,
  84. IsMaxTime: pasturePb.IsShow_No,
  85. ChangeFilter: InitChangeFilter,
  86. FilterCorrect: InitChangeFilter,
  87. RuminaFilter: InitChangeFilter,
  88. ChewFilter: InitChangeFilter,
  89. ActiveTime: fmt.Sprintf("%s %02d:00:00", data.ActiveDate, data.XframeId*2+1),
  90. RecordCount: data.RecordCount,
  91. FirmwareVersion: data.FirmwareVersion,
  92. }
  93. }
  94. func (n *NeckActiveHabit) SumAvg() {
  95. n.Rumina = n.Rumina / n.RecordCount * n.RecordCount
  96. n.Inactive = n.Inactive / n.RecordCount * n.RecordCount
  97. n.Active = n.Active / n.RecordCount * n.RecordCount
  98. n.Intake = n.Intake / n.RecordCount * n.RecordCount
  99. n.Other = n.Other / n.RecordCount * n.RecordCount
  100. n.Gasp = n.Gasp / n.RecordCount * n.RecordCount
  101. n.High = n.High / n.RecordCount * n.RecordCount
  102. }
  103. type MaxHabitIdModel struct {
  104. Id int64 `json:"id"`
  105. }