|
@@ -1,6 +1,7 @@
|
|
|
package model
|
|
|
|
|
|
import (
|
|
|
+ "kpt-pasture/util"
|
|
|
"math"
|
|
|
"time"
|
|
|
|
|
@@ -16,6 +17,7 @@ type EventWeight struct {
|
|
|
LactationDay int64 `json:"lactationDay"`
|
|
|
PenId int32 `json:"penId"`
|
|
|
Lact int32 `json:"lact"`
|
|
|
+ AdmissionAge int32 `json:"admissionAge"`
|
|
|
Weight int32 `json:"weight"`
|
|
|
Height int32 `json:"height"`
|
|
|
WeightAt int64 `json:"weightAt"`
|
|
@@ -47,12 +49,13 @@ func NewEventWeight(pastureId int64, cow *Cow, currentUser *SystemUser, item *pa
|
|
|
MessageName: currentUser.Name,
|
|
|
OperationId: item.OperationId,
|
|
|
OperationName: item.OperationName,
|
|
|
+ AdmissionAge: cow.GetEventAdmissionAge(int64(item.WeightAt)),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
type EventWeightSlice []*EventWeight
|
|
|
|
|
|
-func (e EventWeightSlice) ToPB(cowInfo *Cow, eventCowLogList []*EventCowLog) *pasturePb.CowGrowthCurveData {
|
|
|
+func (e EventWeightSlice) ToPB(eventCowLogList []*EventCowLog) *pasturePb.CowGrowthCurveData {
|
|
|
res := &pasturePb.CowGrowthCurveData{
|
|
|
Chart: &pasturePb.CowBehaviorCurveChart{
|
|
|
Headers: make([]string, 0),
|
|
@@ -72,9 +75,9 @@ func (e EventWeightSlice) ToPB(cowInfo *Cow, eventCowLogList []*EventCowLog) *pa
|
|
|
weight = float32(v.Weight) / 1000
|
|
|
}
|
|
|
|
|
|
- avgWeight := float32(0)
|
|
|
+ avgWeight := float64(0)
|
|
|
if i > 0 {
|
|
|
- avgWeight = float32(v.Weight-e[i-1].Weight) / float32(v.WeightAt-e[i-1].WeightAt) / 24 / 1000
|
|
|
+ avgWeight = float64(v.Weight-e[i-1].Weight) / float64(v.WeightAt-e[i-1].WeightAt) / 24 / 1000
|
|
|
}
|
|
|
|
|
|
// 阶段日增重
|
|
@@ -93,11 +96,11 @@ func (e EventWeightSlice) ToPB(cowInfo *Cow, eventCowLogList []*EventCowLog) *pa
|
|
|
}
|
|
|
res.Table[i] = &pasturePb.CowBehaviorCurveTable{
|
|
|
Weight: weight,
|
|
|
- AvgWeight: avgWeight,
|
|
|
+ AvgWeight: float32(util.RoundToTwoDecimals(avgWeight)),
|
|
|
StageDayAddWeight: stageDayAddWeight,
|
|
|
MonthAvgAddWeight: monthAvgAddWeight,
|
|
|
WeightAtFormat: weightAtFormat,
|
|
|
- AdmissionAge: cowInfo.AdmissionAge,
|
|
|
+ AdmissionAge: v.AdmissionAge,
|
|
|
}
|
|
|
res.Chart.Headers = append(res.Chart.Headers, weightAtFormat)
|
|
|
res.Chart.Weight = append(res.Chart.Weight, weight)
|