adjustment meta

This commit is contained in:
ragilap
2026-01-11 18:54:05 +07:00
parent a54129866e
commit dc7dc0ba47
4 changed files with 72 additions and 44 deletions
@@ -108,14 +108,20 @@ func (s dashboardService) buildPerformanceStatistics(ctx context.Context, params
return nil, err
}
fcrCurrent, fcrLast, err := s.calculateFcr(ctx, filter, startDate, endExclusive, endDate, location)
if err != nil {
return nil, err
}
mortalityCurrent, mortalityLast, err := s.calculateMortality(ctx, filter, startDate, endExclusive, endDate, location)
if err != nil {
return nil, err
hasFilter := filter != nil && (len(filter.LokasiIds) > 0 || len(filter.FlockIds) > 0 || len(filter.KandangIds) > 0)
fcrCurrent := 0.0
fcrLast := 0.0
mortalityCurrent := 0.0
mortalityLast := 0.0
if hasFilter {
fcrCurrent, fcrLast, err = s.calculateFcr(ctx, filter, startDate, endExclusive, endDate, location)
if err != nil {
return nil, err
}
mortalityCurrent, mortalityLast, err = s.calculateMortality(ctx, filter, startDate, endExclusive, endDate, location)
if err != nil {
return nil, err
}
}
hppPercent := 0.0
@@ -128,17 +134,7 @@ func (s dashboardService) buildPerformanceStatistics(ctx context.Context, params
sellingPercent = sellingCurrent / sellingLast * 100
}
fcrPercent := 0.0
if fcrLast > 0 {
fcrPercent = (fcrCurrent - fcrLast) / fcrLast * 100
}
mortalityPercent := 0.0
if mortalityLast > 0 {
mortalityPercent = (mortalityCurrent - mortalityLast) / mortalityLast * 100
}
return []dto.DashboardStatisticsDTO{
stats := []dto.DashboardStatisticsDTO{
{
Label: "HPP Global",
Value: roundTo(hppCurrent, 0),
@@ -149,17 +145,32 @@ func (s dashboardService) buildPerformanceStatistics(ctx context.Context, params
Value: roundTo(sellingCurrent, 0),
PercentLastMonth: sellingPercent,
},
{
Label: "FCR",
Value: roundTo(fcrCurrent, 2),
PercentLastMonth: fcrPercent,
},
{
Label: "Mortality",
Value: roundTo(mortalityCurrent, 2),
PercentLastMonth: mortalityPercent,
},
}, nil
}
if hasFilter {
fcrPercent := 0.0
if fcrLast > 0 {
fcrPercent = (fcrCurrent - fcrLast) / fcrLast * 100
}
mortalityPercent := 0.0
if mortalityLast > 0 {
mortalityPercent = (mortalityCurrent - mortalityLast) / mortalityLast * 100
}
stats = append(stats,
dto.DashboardStatisticsDTO{
Label: "FCR",
Value: roundTo(fcrCurrent, 2),
PercentLastMonth: fcrPercent,
},
dto.DashboardStatisticsDTO{
Label: "Mortality",
Value: roundTo(mortalityCurrent, 2),
PercentLastMonth: mortalityPercent,
},
)
}
return stats, nil
}
func (s dashboardService) buildPerformanceCharts(ctx context.Context, params *validation.Query, filter *validation.DashboardFilter) (map[string]dto.DashboardChartDTO, error) {
@@ -171,6 +182,10 @@ func (s dashboardService) buildPerformanceCharts(ctx context.Context, params *va
return nil, errors.New("period dates are not initialized")
}
if filter == nil || (len(filter.LokasiIds) == 0 && len(filter.FlockIds) == 0 && len(filter.KandangIds) == 0) {
return map[string]dto.DashboardChartDTO{}, nil
}
startDate := params.PeriodStart
endExclusive := params.PeriodEndExclusive