mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
adjust api closing data produksi
This commit is contained in:
@@ -586,11 +586,21 @@ func (s closingService) GetClosingDataProduksi(c *fiber.Ctx, projectFlockID uint
|
||||
averageFeedIntake := targetAverages.FeedIntakeAvg
|
||||
|
||||
feedIntakeStd := 0.0
|
||||
var mortalityStdFromGrowth *float64
|
||||
if project.ProductionStandardId > 0 && currentWeek > 0 && s.StandardGrowthDetailRepo != nil {
|
||||
feedIntakeStd, err = s.calculateFeedIntakeStd(c.Context(), project.ProductionStandardId, currentWeek)
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to compute feed intake std for project flock %d: %+v", projectFlockID, err)
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch feed intake standard data")
|
||||
growthDetail, growthErr := s.StandardGrowthDetailRepo.GetByStandardIDAndWeek(c.Context(), project.ProductionStandardId, currentWeek)
|
||||
if growthErr != nil {
|
||||
if !errors.Is(growthErr, gorm.ErrRecordNotFound) {
|
||||
s.Log.Errorf("Failed to fetch growth detail for project flock %d: %+v", projectFlockID, growthErr)
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch growth standard data")
|
||||
}
|
||||
} else if growthDetail != nil {
|
||||
if growthDetail.FeedIntake != nil {
|
||||
feedIntakeStd = *growthDetail.FeedIntake
|
||||
}
|
||||
if growthDetail.MaxDepletion != nil {
|
||||
mortalityStdFromGrowth = growthDetail.MaxDepletion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,6 +764,14 @@ func (s closingService) GetClosingDataProduksi(c *fiber.Ctx, projectFlockID uint
|
||||
}
|
||||
performance.FeedIntake = averageFeedIntake
|
||||
performance.FeedIntakeStd = feedIntakeStd
|
||||
if targetAverages.CumDepletionRateCount > 0 {
|
||||
performance.MortalityAct = targetAverages.CumDepletionRateAvg
|
||||
performance.DeffMortality = performance.MortalityAct - performance.MortalityStd
|
||||
}
|
||||
if mortalityStdFromGrowth != nil {
|
||||
performance.MortalityStd = *mortalityStdFromGrowth
|
||||
performance.DeffMortality = performance.MortalityAct - performance.MortalityStd
|
||||
}
|
||||
if !isGrowing {
|
||||
if targetAverages.HenDayCount > 0 {
|
||||
henDayAct := targetAverages.HenDayAvg
|
||||
@@ -876,24 +894,6 @@ func (s closingService) determineProductionWeek(ctx context.Context, projectFloc
|
||||
return week, nil
|
||||
}
|
||||
|
||||
func (s closingService) calculateFeedIntakeStd(ctx context.Context, productionStandardID uint, week int) (float64, error) {
|
||||
if productionStandardID == 0 || week <= 0 || s.StandardGrowthDetailRepo == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
detail, err := s.StandardGrowthDetailRepo.GetByStandardIDAndWeek(ctx, productionStandardID, week)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return 0, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
if detail == nil || detail.FeedIntake == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return *detail.FeedIntake, nil
|
||||
}
|
||||
|
||||
func calculatePerformanceMetrics(averageWeight, totalWeight, feedUsed, basePopulation, depletion, age float64, standards []entity.FcrStandard) dto.ClosingPerformanceDTO {
|
||||
mortalityStd, fcrStd := closestFcrValues(standards, averageWeight)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user