From 7638c183f50eee0b20a6c0da8fcc46a3bf8417dc Mon Sep 17 00:00:00 2001 From: Adnan Zahir Date: Wed, 8 Apr 2026 15:13:31 +0700 Subject: [PATCH] codex/fix: dashboard independent recording values without uniformity --- .../dashboards/services/dashboard.service.go | 96 ++++++++++++------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/internal/modules/dashboards/services/dashboard.service.go b/internal/modules/dashboards/services/dashboard.service.go index 928205d2..4ad5cc8e 100644 --- a/internal/modules/dashboards/services/dashboard.service.go +++ b/internal/modules/dashboards/services/dashboard.service.go @@ -274,10 +274,10 @@ func (s dashboardService) buildPerformanceCharts(ctx context.Context, params *va cumFeed := 0.0 for _, week := range weeks { - rec := recordingMap[week] - uni := uniformityMap[week] - std := standardMap[week] - stdFcr := standardFcrMap[week] + rec, hasRec := recordingMap[week] + uni, hasUni := uniformityMap[week] + std, hasStd := standardMap[week] + stdFcr, hasStdFcr := standardFcrMap[week] weekEgg := weeklyEggMap[week] weekFeed := weeklyFeedMap[week] @@ -293,37 +293,69 @@ func (s dashboardService) buildPerformanceCharts(ctx context.Context, params *va actFcrCum = cumFeed / cumEgg } - bodyWeightDataset = append(bodyWeightDataset, map[string]interface{}{ - "week": week, - "body_weight": roundTo(uni.AverageWeight, 2), - "std_body_weight": roundTo(std.StdBodyWeight, 2), - }) + bodyWeightRow := map[string]interface{}{ + "week": week, + } + if hasUni { + bodyWeightRow["body_weight"] = roundTo(uni.AverageWeight, 2) + } + if hasStd { + bodyWeightRow["std_body_weight"] = roundTo(std.StdBodyWeight, 2) + } + if len(bodyWeightRow) > 1 { + bodyWeightDataset = append(bodyWeightDataset, bodyWeightRow) + } - performanceDataset = append(performanceDataset, map[string]interface{}{ - "week": week, - "act_laying": roundTo(rec.HenDay, 2), - "std_laying": roundTo(std.StdLaying, 2), - "act_egg_weight": roundTo(rec.EggWeight, 2), - "std_egg_weight": roundTo(std.StdEggWeight, 2), - "act_feed_intake": roundTo(rec.FeedIntake, 2), - "std_feed_intake": roundTo(std.StdFeedIntake, 2), - "act_uniformity": roundTo(uni.Uniformity, 2), - "std_uniformity": roundTo(std.StdUniformity, 2), - }) + performanceRow := map[string]interface{}{ + "week": week, + } + if hasRec { + performanceRow["act_laying"] = roundTo(rec.HenDay, 2) + performanceRow["act_egg_weight"] = roundTo(rec.EggWeight, 2) + performanceRow["act_feed_intake"] = roundTo(rec.FeedIntake, 2) + } + if hasUni { + performanceRow["act_uniformity"] = roundTo(uni.Uniformity, 2) + } + if hasStd { + performanceRow["std_laying"] = roundTo(std.StdLaying, 2) + performanceRow["std_egg_weight"] = roundTo(std.StdEggWeight, 2) + performanceRow["std_feed_intake"] = roundTo(std.StdFeedIntake, 2) + performanceRow["std_uniformity"] = roundTo(std.StdUniformity, 2) + } + if len(performanceRow) > 1 { + performanceDataset = append(performanceDataset, performanceRow) + } - fcrDataset = append(fcrDataset, map[string]interface{}{ - "week": week, - "act_fcr": roundTo(actFcr, 2), - "std_fcr": roundTo(stdFcr, 2), - "act_fcr_cum": roundTo(actFcrCum, 2), - "std_fcr_cum": roundTo(stdFcr, 2), - }) + fcrRow := map[string]interface{}{ + "week": week, + } + if weekEgg > 0 && weekFeed > 0 { + fcrRow["act_fcr"] = roundTo(actFcr, 2) + } + if cumEgg > 0 && cumFeed > 0 { + fcrRow["act_fcr_cum"] = roundTo(actFcrCum, 2) + } + if hasStdFcr { + fcrRow["std_fcr"] = roundTo(stdFcr, 2) + fcrRow["std_fcr_cum"] = roundTo(stdFcr, 2) + } + if len(fcrRow) > 1 { + fcrDataset = append(fcrDataset, fcrRow) + } - deplesiDataset = append(deplesiDataset, map[string]interface{}{ - "week": week, - "act_deplesi": roundTo(rec.CumDepletionRate, 2), - "std_deplesi": roundTo(std.StdDepletion, 2), - }) + deplesiRow := map[string]interface{}{ + "week": week, + } + if hasRec { + deplesiRow["act_deplesi"] = roundTo(rec.CumDepletionRate, 2) + } + if hasStd { + deplesiRow["std_deplesi"] = roundTo(std.StdDepletion, 2) + } + if len(deplesiRow) > 1 { + deplesiDataset = append(deplesiDataset, deplesiRow) + } } qualityRows, err := s.Repository.GetEggQualityWeeklyMetrics(ctx, startDate, endExclusive, filter)