|
@@ -100,7 +100,7 @@ func (e *Entry) FirstFilterUpdate(pastureId int64, xToDay *XToday) (processIds [
|
|
|
Where("heat_date >= ?", time.Now().Local().AddDate(0, 0, -7).Format(model.LayoutDate2)).
|
|
|
Where("pasture_id = ?", pastureId).
|
|
|
Where("is_show = ?", pasturePb.IsShow_No).
|
|
|
- Where(e.DB.Where("high >= ?", xToDay.High).Or("rumina >= ?", xToDay.Rumina)).
|
|
|
+ //Where(e.DB.Where("high >= ?", xToDay.High).Or("rumina >= ?", xToDay.Rumina)).
|
|
|
Order("heat_date,neck_ring_number,frameid").
|
|
|
Limit(int(limit)).
|
|
|
Find(&newNeckActiveHabitList).Error; err != nil {
|
|
@@ -109,6 +109,9 @@ func (e *Entry) FirstFilterUpdate(pastureId int64, xToDay *XToday) (processIds [
|
|
|
|
|
|
// 活动量滤波
|
|
|
for _, v := range newNeckActiveHabitList {
|
|
|
+ if !(v.High >= xToDay.High || v.Rumina >= xToDay.Rumina) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
// 4小时数据不全的不参与滤波
|
|
|
activeTime, _ := util.TimeParseLocal(model.LayoutTime, v.ActiveTime)
|
|
|
if v.RecordCount != model.DefaultRecordCount && time.Now().Local().Sub(activeTime).Hours() <= 4 {
|
|
@@ -320,13 +323,14 @@ func (e *Entry) FilterCorrectAndScoreUpdate(pastureId int64, processIds []int64,
|
|
|
Where("active_time <= ?", beginDayDate.Add(-12*time.Hour).Format(model.LayoutTime)).
|
|
|
Where("change_filter > ?", MinChangeFilter).
|
|
|
Where("neck_ring_number = ?", v.NeckRingNumber).
|
|
|
- Having("nb > ?", DefaultNb).
|
|
|
+ Having("nb >= ?", DefaultNb).
|
|
|
First(&activityVolume).Error; err != nil {
|
|
|
zaplog.Error("ActivityVolumeChanges-0", zap.Any("error", err), zap.Any("xToday", xToday))
|
|
|
continue
|
|
|
}
|
|
|
if activityVolume != nil && activityVolume.NeckRingNumber != "" {
|
|
|
- filterCorrect := model.DefaultFilterCorrect - int(math.Floor(activityVolume.AvgFilter/3+float64(activityVolume.StdFilter)/2))
|
|
|
+ //filterCorrect := model.DefaultFilterCorrect - int(math.Floor(activityVolume.AvgFilter/3+float64(activityVolume.StdFilter)/2))
|
|
|
+ filterCorrect := model.DefaultFilterCorrect - int(math.Round(activityVolume.AvgFilter/3+float64(int(math.Round(activityVolume.StdFilter))/2)))
|
|
|
// 活动量校正系数
|
|
|
if err := e.DB.Model(new(model.NeckActiveHabit)).
|
|
|
Where("id = ?", v.Id).
|
|
@@ -382,11 +386,10 @@ func (e *Entry) UpdateChangeAdJust(pastureId int64, xToday *XToday) {
|
|
|
if err := e.DB.Table(fmt.Sprintf("%s as h", new(model.NeckActiveHabit).TableName())).
|
|
|
Select(`h.neck_ring_number,h.heat_date, h.frameid, c.pen_id, c.pen_name, COUNT(*) as nb,
|
|
|
ROUND(AVG(h.change_high)) as change_high, ROUND(AVG(h.change_filter)) as change_filter`).
|
|
|
- Joins("JOIN cow as c ON h.neck_ring_number = c.neck_ring_number").
|
|
|
+ Joins("JOIN cow as c ON h.cow_id = c.id").
|
|
|
Where("h.pasture_id = ?", pastureId).
|
|
|
Where("h.heat_date >= ?", oneDayAgo).
|
|
|
- Where("h.is_show = ?", pasturePb.IsShow_Ok).
|
|
|
- Where("h.cow_id >= ?", 0).
|
|
|
+ Where("h.cow_id > ?", 0).
|
|
|
Where("c.pen_id > ?", 0).
|
|
|
Group("h.heat_date, h.frameid, c.pen_id").
|
|
|
Order("h.heat_date, h.frameid, c.pen_id").
|
|
@@ -402,6 +405,7 @@ func (e *Entry) UpdateChangeAdJust(pastureId int64, xToday *XToday) {
|
|
|
Where("pasture_id = ?", pastureId).
|
|
|
Where("neck_ring_number = ?", v.NeckRingNumber).
|
|
|
Where("heat_date = ?", v.HeatDate).
|
|
|
+ Where("pen_id = ?", v.PenId).
|
|
|
Where("frameid = ?", v.FrameId).
|
|
|
Update("change_adjust", v.ChangeFilter).Error; err != nil {
|
|
|
zaplog.Error("UpdateChangeAdJust-1", zap.Any("error", err), zap.Any("xToday", xToday))
|