codex/fix: dashboard independent recording values without uniformity

This commit is contained in:
Adnan Zahir
2026-04-08 15:13:31 +07:00
parent 079ae01b94
commit 7638c183f5
@@ -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)