Browse Source

crontab: score update

Yi 1 week ago
parent
commit
d55c0429cf
2 changed files with 89 additions and 7 deletions
  1. 24 6
      module/crontab/neck_ring_merge.go
  2. 65 1
      module/crontab/neck_ring_merge_test.go

+ 24 - 6
module/crontab/neck_ring_merge.go

@@ -232,12 +232,12 @@ func CalculateScore(appPasture *model.AppPastureList, habit *model.NeckActiveHab
 		part1 = math.Min((float64(habit.SumRumina+habit.SumIntake)-(100+math.Min(7, float64(habit.CalvingAge))*60))/10*2, 0)
 	case habit.ChangeFilter > -99:
 		if appPasture.Category == pasturePb.PastureCategory_Beef {
-			part1 = math.Min(0, math.Min(getValueOrDefault(float64(habit.ChangeFilter)-math.Min(float64(habit.ChangeAdjust), 0), 0), getValueOrDefault(float64(habit.SumMinHigh), 0)))*0.2 +
+			part1 = getBeefSoreV1(habit) +
 				getBeefSportsRuminaScore(habit) +
 				getBeefRuminaSumIntakeSumScore(habit) +
 				getBeefAdditionalScore(habit)
 		} else {
-			part1 = math.Min(0, math.Min(getValueOrDefault(float64(habit.ChangeFilter), 0), getValueOrDefault(float64(habit.SumMinHigh), 0)))*0.2 +
+			part1 = getCowSoreV1(habit) +
 				getCowSportsRuminaScore(habit) +
 				getCowRuminaSumIntakeSumScore(habit) +
 				getCowAdditionalScore(habit)
@@ -246,6 +246,12 @@ func CalculateScore(appPasture *model.AppPastureList, habit *model.NeckActiveHab
 		part1 = -299
 	}
 
+	fmt.Println("part1", part1)
+	fmt.Println("v1", getBeefSoreV1(habit))
+	fmt.Println("v2", getBeefSportsRuminaScore(habit))
+	fmt.Println("v3", getBeefRuminaSumIntakeSumScore(habit))
+	fmt.Println("v4", getBeefAdditionalScore(habit))
+
 	// 第二部分逻辑
 	var part2 float64
 	versionMod := habit.FirmwareVersion % 100
@@ -268,6 +274,14 @@ func getValueOrDefault(value, defaultValue float64) float64 {
 	return defaultValue
 }
 
+func getCowSoreV1(habit *model.NeckActiveHabit) float64 {
+	return math.Min(0, math.Min(getValueOrDefault(float64(habit.ChangeFilter), 0), getValueOrDefault(float64(habit.SumMinHigh), 0))) * 0.2
+}
+
+func getBeefSoreV1(habit *model.NeckActiveHabit) float64 {
+	return math.Min(0, math.Min(getValueOrDefault(float64(habit.ChangeFilter)-math.Min(float64(habit.ChangeAdjust), 0), 0), getValueOrDefault(float64(habit.SumMinHigh), 0))) * 0.2
+}
+
 // 奶牛运动得反刍分
 // LEAST(0, IF(h.chew_filter>-99, h.chew_filter, 0), IF(h.sum_min_chew>-99, h.sum_min_chew, 0))*0.2
 func getCowSportsRuminaScore(habit *model.NeckActiveHabit) float64 {
@@ -297,7 +311,7 @@ func getCowRuminaSumIntakeSumScore(habit *model.NeckActiveHabit) float64 {
 // 肉牛累计反刍得分
 func getBeefRuminaSumIntakeSumScore(habit *model.NeckActiveHabit) float64 {
 	sum := float64(habit.SumRumina + habit.SumIntake)
-	return math.Min(0, sum-380/10)
+	return math.Min(0, (sum-380)/10)
 }
 
 // 奶牛当前变化趋势是否是峰值
@@ -313,11 +327,15 @@ func getCowAdditionalScore(habit *model.NeckActiveHabit) float64 {
 }
 
 // 肉牛当前变化趋势是否是峰值
-// IF((h.change_filter -LEAST(h.change_adjust,0))<-30 AND (h.change_filter -LEAST(h.change_adjust,0))<=h.sum_min_high AND h.chew_filter<-30 AND h.chew_filter<=h.sum_min_chew, -5, 0)
+// + IF(((h.sum_rumina + h.sum_intake )<280 OR (h.sum_min_high +h.sum_min_chew)<-50) AND h.sum_max_high>50, 10, 0)
+// + IF((h.change_filter -LEAST(h.change_adjust,0))<-30 AND (h.change_filter -LEAST(h.change_adjust,0))<=h.sum_min_high AND h.chew_filter<-30 AND h.chew_filter<=h.sum_min_chew, -5, 0)
 func getBeefAdditionalScore(habit *model.NeckActiveHabit) float64 {
 	var score float64
-	if (float64(habit.ChangeFilter)-math.Min(float64(habit.ChangeAdjust), 0)) < -30 &&
-		(float64(habit.ChangeFilter)-math.Min(float64(habit.ChangeAdjust), 0)) <= float64(habit.SumMinHigh) &&
+	if (habit.SumRumina+habit.SumIntake < 280 || habit.SumMinHigh+habit.SumMinChew < -50) && habit.SumMaxHigh > 50 {
+		score += 10
+	}
+	if float64(habit.ChangeFilter)-math.Min(float64(habit.ChangeAdjust), 0) < -30 &&
+		float64(habit.ChangeFilter)-math.Min(float64(habit.ChangeAdjust), 0) <= float64(habit.SumMinHigh) &&
 		habit.ChewFilter < -30 && habit.ChewFilter <= habit.SumMinChew {
 		score -= 5
 	}

+ 65 - 1
module/crontab/neck_ring_merge_test.go

@@ -1,7 +1,71 @@
 package crontab
 
-import "testing"
+import (
+	"fmt"
+	"kpt-pasture/model"
+	"testing"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
 
 func TestEntry_CalculateScore(t *testing.T) {
+	app := &model.AppPastureList{
+		Id:       4,
+		Category: pasturePb.PastureCategory_Beef,
+	}
 
+	habit := &model.NeckActiveHabit{
+		Id:                   5287253,
+		PastureId:            4,
+		NeckRingNumber:       "324",
+		CowId:                11246,
+		EarNumber:            "210868",
+		Lact:                 3,
+		CalvingAge:           312,
+		PenId:                16,
+		ActiveTime:           "2025-07-09",
+		Frameid:              7,
+		HeatDate:             "2025-07-09 11:00:00",
+		Rumina:               9,
+		Intake:               21,
+		Inactive:             74,
+		Gasp:                 0,
+		Other:                0,
+		High:                 642,
+		Active:               36,
+		FilterHigh:           974,
+		FilterRumina:         10,
+		FilterChew:           29,
+		WeekHigh:             1112,
+		HighHabit:            1755,
+		RuminaHabit:          23,
+		IntakeHabit:          38,
+		ChewHabit:            49,
+		InactiveHabit:        36,
+		OtherHabit:           0,
+		ChangeHigh:           -45,
+		ChangeRumina:         -57,
+		ChangeChew:           -41,
+		ChangeAdjust:         0,
+		ChangeFilter:         53,
+		RuminaFilter:         -57,
+		ChewFilter:           -39,
+		FilterCorrect:        95,
+		SumRumina:            129,
+		SumIntake:            106,
+		SumInactive:          456,
+		SumActive:            668,
+		SumMinHigh:           -55,
+		SumMaxHigh:           96,
+		SumMinChew:           -68,
+		BeforeThreeSumRumina: 508,
+		BeforeThreeSumIntake: 159,
+		Score:                0,
+		IsShow:               1,
+		Cft:                  60.35,
+		Voltage:              301,
+		RecordCount:          6,
+		FirmwareVersion:      57,
+	}
+	fmt.Println(CalculateScore(app, habit))
 }