pen_behavior.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package model
  2. import (
  3. "kpt-pasture/util"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type PenBehavior struct {
  7. Id int64 `json:"id"`
  8. PastureId int64 `json:"pastureId"`
  9. HeatDate string `json:"heatDate"`
  10. ActiveTime string `json:"activeTime"`
  11. PenId int32 `json:"penId"`
  12. PenName string `json:"penName"`
  13. CowCount int32 `json:"cowCount"`
  14. AvgHigh int32 `json:"avgHigh"`
  15. SumRumina int32 `json:"sumRumina"`
  16. SumIntake int32 `json:"sumIntake"`
  17. SumRest int32 `json:"sumRest"`
  18. SumGasp int32 `json:"sumGasp"`
  19. RuminaRate int32 `json:"ruminaRate"`
  20. IntakeRate int32 `json:"intakeRate"`
  21. RestRate int32 `json:"restRate"`
  22. GaspRate int32 `json:"gaspRate"`
  23. WeekRuminaRate int32 `json:"weekRuminaRate"`
  24. RuminaStd int32 `json:"ruminaStd"`
  25. WeekIntakeRate int32 `json:"weekIntakeRate"`
  26. IntakeStd int32 `json:"intakeStd"`
  27. WeekRestRate int32 `json:"weekRestRate"`
  28. RestStd int32 `json:"restStd"`
  29. WeekGaspRate int32 `json:"weekGaspRate"`
  30. GaspStd int32 `json:"gaspStd"`
  31. CreatedAt int64 `json:"createdAt"`
  32. UpdatedAt int64 `json:"updatedAt"`
  33. }
  34. func (p *PenBehavior) TableName() string {
  35. return "pen_behavior"
  36. }
  37. type PenBehaviorSlice []*PenBehavior
  38. func (p PenBehaviorSlice) ToPB() *pasturePb.BarnBehaviorCurveItem {
  39. res := &pasturePb.BarnBehaviorCurveItem{
  40. EventTime: &pasturePb.EventTime{
  41. FeedTime: make([]string, 0),
  42. MilkTime: make([]string, 0),
  43. },
  44. DateTime: make([]string, 0),
  45. Rumina: make([]int32, 0),
  46. Intake: make([]int32, 0),
  47. Rest: make([]int32, 0),
  48. WeekAvgRumina: make([]int32, 0),
  49. WeekAvgIntake: make([]int32, 0),
  50. WeekAvgReset: make([]int32, 0),
  51. }
  52. for _, v := range p {
  53. dateTime := ""
  54. if v.ActiveTime != "" {
  55. dt, _ := util.TimeParseLocal(LayoutTime, v.ActiveTime)
  56. dateTime = dt.Format(LayoutHour)
  57. }
  58. res.DateTime = append(res.DateTime, dateTime)
  59. res.Rumina = append(res.Rumina, v.RuminaStd)
  60. res.Intake = append(res.Intake, v.IntakeStd)
  61. res.Rest = append(res.Rest, v.RestStd)
  62. res.WeekAvgRumina = append(res.WeekAvgRumina, v.WeekRuminaRate)
  63. res.WeekAvgIntake = append(res.WeekAvgIntake, v.WeekIntakeRate)
  64. res.WeekAvgReset = append(res.WeekAvgReset, v.WeekRestRate)
  65. }
  66. return res
  67. }
  68. type PenBehaviorData struct {
  69. PastureId int64 `json:"pastureId"`
  70. PenId int32 `json:"penId"`
  71. PenName string `json:"penName"`
  72. HeatDate string `json:"heatDate"`
  73. Frameid int32 `json:"frameid"`
  74. CowCount int32 `json:"cowCount"`
  75. AvgHigh int32 `json:"avgHigh"`
  76. SumRumina int32 `json:"sumRumina"`
  77. SumIntake int32 `json:"sumIntake"`
  78. SumRest int32 `json:"sumRest"`
  79. SumGasp int32 `json:"sumGasp"`
  80. RuminaRate int32 `json:"ruminaRate"`
  81. IntakeRate int32 `json:"intakeRate"`
  82. RestRate int32 `json:"restRate"`
  83. GaspRate int32 `json:"gaspRate"`
  84. }