|
@@ -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,
|
|
|
}
|
|
|
}
|
|
|
|