浏览代码

cow: behaviorRate 行为占比

Yi 1 月之前
父节点
当前提交
4edd7bd08c
共有 3 个文件被更改,包括 17 次插入11 次删除
  1. 1 1
      go.mod
  2. 2 0
      go.sum
  3. 14 10
      model/event_weight.go

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250416085805-501c91e70d45
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250416102510-604a13fe9d52
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eclipse/paho.mqtt.golang v1.4.3

+ 2 - 0
go.sum

@@ -52,6 +52,8 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250416061435-4d79cc588081 h1:kayy8O7/
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250416061435-4d79cc588081/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250416085805-501c91e70d45 h1:O4vnwyLdVPFXGoiqfQqeaYAzdgTwwwphyVJ/0ws/UqU=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250416085805-501c91e70d45/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250416102510-604a13fe9d52 h1:aCqqT2Y/po3OtkUqzogDOIjqwny03iu1rp47CU1yiz0=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250416102510-604a13fe9d52/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b h1:w05MxH7yqveRlaRbxHhbif5YjPrJFodRPfOjYhXn7Zk=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 14 - 10
model/event_weight.go

@@ -51,12 +51,19 @@ func NewEventWeight(pastureId int64, cow *Cow, currentUser *SystemUser, item *pa
 
 type EventWeightSlice []*EventWeight
 
-func (e EventWeightSlice) ToPB() []*pasturePb.CowGrowthCurveData {
-	res := make([]*pasturePb.CowGrowthCurveData, len(e))
+func (e EventWeightSlice) ToPB() *pasturePb.CowGrowthCurveData {
+	res := &pasturePb.CowGrowthCurveData{
+		Chart: &pasturePb.CowBehaviorCurveChart{
+			Headers:   make([]string, 0),
+			Weight:    make([]float32, 0),
+			EventList: make([]*pasturePb.EventHappen, 0),
+		},
+		Table: make([]*pasturePb.CowBehaviorCurveTable, len(e)),
+	}
 	for i, v := range e {
 		weightAtFormat := ""
 		if v.WeightAt > 0 {
-			weightAtFormat = time.Unix(v.WeightAt, 0).Local().Format(LayoutTime)
+			weightAtFormat = time.Unix(v.WeightAt, 0).Local().Format(LayoutDate2)
 		}
 
 		avgWeight := float32(0)
@@ -64,13 +71,10 @@ func (e EventWeightSlice) ToPB() []*pasturePb.CowGrowthCurveData {
 			avgWeight = float32(v.Weight-e[i-1].Weight) / float32(v.WeightAt-e[i-1].WeightAt) / 24 / 1000
 		}
 
-		res[i] = &pasturePb.CowGrowthCurveData{
-			Weight:          float32(v.Weight) / 1000,
-			WeightAtFormat:  weightAtFormat,
-			AvgWeight:       0,              // 平均体重
-			DayAddWeight:    0,              // 日增重
-			AvgDayAddWeight: avgWeight,      // 阶段日增重
-			MonthAddWeight:  avgWeight * 30, // 月增重
+		res.Table[i] = &pasturePb.CowBehaviorCurveTable{
+			Weight:         float32(v.Weight) / 1000,
+			WeightAtFormat: weightAtFormat,
+			AvgWeight:      avgWeight,
 		}
 	}