mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
adjustment meta
This commit is contained in:
@@ -61,9 +61,9 @@ func (u *DashboardController) GetAll(c *fiber.Ctx) error {
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
lokasiIds, err := parseUintListParam(c.Query("lokasi_ids", ""))
|
||||
lokasiIds, err := parseUintListParam(c.Query("location_ids", ""))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid lokasi_ids")
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid location_ids")
|
||||
}
|
||||
|
||||
flockIds, err := parseUintListParam(c.Query("flock_ids", ""))
|
||||
@@ -128,16 +128,29 @@ func (u *DashboardController) GetAll(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
filters := dto.DashboardFiltersDTO{
|
||||
StartDate: query.StartDate,
|
||||
EndDate: query.EndDate,
|
||||
AnalysisMode: query.AnalysisMode,
|
||||
ComparisonType: query.ComparisonType,
|
||||
Metric: query.Metric,
|
||||
LokasiIds: defaultUintSlice(query.LokasiIds),
|
||||
FlockIds: defaultUintSlice(query.FlockIds),
|
||||
KandangIds: defaultUintSlice(query.KandangIds),
|
||||
Include: query.Include,
|
||||
hasFilter := query.StartDate != "" ||
|
||||
query.EndDate != "" ||
|
||||
len(query.LokasiIds) > 0 ||
|
||||
len(query.FlockIds) > 0 ||
|
||||
len(query.KandangIds) > 0 ||
|
||||
len(query.Include) > 0 ||
|
||||
query.ComparisonType != "" ||
|
||||
query.Metric != "" ||
|
||||
query.AnalysisMode != validation.AnalysisModeOverview
|
||||
|
||||
var filters interface{}
|
||||
if hasFilter {
|
||||
filters = dto.DashboardFiltersDTO{
|
||||
StartDate: query.StartDate,
|
||||
EndDate: query.EndDate,
|
||||
AnalysisMode: query.AnalysisMode,
|
||||
ComparisonType: query.ComparisonType,
|
||||
Metric: query.Metric,
|
||||
LokasiIds: defaultUintSlice(query.LokasiIds),
|
||||
FlockIds: defaultUintSlice(query.FlockIds),
|
||||
KandangIds: defaultUintSlice(query.KandangIds),
|
||||
Include: query.Include,
|
||||
}
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
|
||||
@@ -27,7 +27,7 @@ type DashboardFiltersDTO struct {
|
||||
AnalysisMode string `json:"analysis_mode"`
|
||||
ComparisonType string `json:"comparison_type,omitempty"`
|
||||
Metric string `json:"metric,omitempty"`
|
||||
LokasiIds []uint `json:"lokasi_ids"`
|
||||
LokasiIds []uint `json:"location_ids"`
|
||||
FlockIds []uint `json:"flock_ids"`
|
||||
KandangIds []uint `json:"kandang_ids"`
|
||||
Include []string `json:"include,omitempty"`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ type PerformanceOverviewFilter struct {
|
||||
AnalysisMode string `query:"analysis_mode" validate:"omitempty,oneof=OVERVIEW COMPARASION"`
|
||||
ComparisonType string `query:"comparison_type" validate:"omitempty,oneof=FARM FLOCK KANDANG"`
|
||||
Metric string `query:"metric" validate:"omitempty,oneof=fcr mortality laying egg_weight feed_intake"`
|
||||
LokasiIds []uint `query:"lokasi_ids" validate:"omitempty,dive,gt=0"`
|
||||
LokasiIds []uint `query:"location_ids" validate:"omitempty,dive,gt=0"`
|
||||
FlockIds []uint `query:"flock_ids" validate:"omitempty,dive,gt=0"`
|
||||
KandangIds []uint `query:"kandang_ids" validate:"omitempty,dive,gt=0"`
|
||||
Include []string `query:"include" validate:"omitempty,dive,oneof=statistics charts"`
|
||||
|
||||
Reference in New Issue
Block a user