mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
adjustment meta
This commit is contained in:
@@ -61,9 +61,9 @@ func (u *DashboardController) GetAll(c *fiber.Ctx) error {
|
|||||||
return ids, nil
|
return ids, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lokasiIds, err := parseUintListParam(c.Query("lokasi_ids", ""))
|
lokasiIds, err := parseUintListParam(c.Query("location_ids", ""))
|
||||||
if err != nil {
|
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", ""))
|
flockIds, err := parseUintListParam(c.Query("flock_ids", ""))
|
||||||
@@ -128,16 +128,29 @@ func (u *DashboardController) GetAll(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
filters := dto.DashboardFiltersDTO{
|
hasFilter := query.StartDate != "" ||
|
||||||
StartDate: query.StartDate,
|
query.EndDate != "" ||
|
||||||
EndDate: query.EndDate,
|
len(query.LokasiIds) > 0 ||
|
||||||
AnalysisMode: query.AnalysisMode,
|
len(query.FlockIds) > 0 ||
|
||||||
ComparisonType: query.ComparisonType,
|
len(query.KandangIds) > 0 ||
|
||||||
Metric: query.Metric,
|
len(query.Include) > 0 ||
|
||||||
LokasiIds: defaultUintSlice(query.LokasiIds),
|
query.ComparisonType != "" ||
|
||||||
FlockIds: defaultUintSlice(query.FlockIds),
|
query.Metric != "" ||
|
||||||
KandangIds: defaultUintSlice(query.KandangIds),
|
query.AnalysisMode != validation.AnalysisModeOverview
|
||||||
Include: query.Include,
|
|
||||||
|
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).
|
return c.Status(fiber.StatusOK).
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type DashboardFiltersDTO struct {
|
|||||||
AnalysisMode string `json:"analysis_mode"`
|
AnalysisMode string `json:"analysis_mode"`
|
||||||
ComparisonType string `json:"comparison_type,omitempty"`
|
ComparisonType string `json:"comparison_type,omitempty"`
|
||||||
Metric string `json:"metric,omitempty"`
|
Metric string `json:"metric,omitempty"`
|
||||||
LokasiIds []uint `json:"lokasi_ids"`
|
LokasiIds []uint `json:"location_ids"`
|
||||||
FlockIds []uint `json:"flock_ids"`
|
FlockIds []uint `json:"flock_ids"`
|
||||||
KandangIds []uint `json:"kandang_ids"`
|
KandangIds []uint `json:"kandang_ids"`
|
||||||
Include []string `json:"include,omitempty"`
|
Include []string `json:"include,omitempty"`
|
||||||
|
|||||||
@@ -108,14 +108,20 @@ func (s dashboardService) buildPerformanceStatistics(ctx context.Context, params
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fcrCurrent, fcrLast, err := s.calculateFcr(ctx, filter, startDate, endExclusive, endDate, location)
|
hasFilter := filter != nil && (len(filter.LokasiIds) > 0 || len(filter.FlockIds) > 0 || len(filter.KandangIds) > 0)
|
||||||
if err != nil {
|
fcrCurrent := 0.0
|
||||||
return nil, err
|
fcrLast := 0.0
|
||||||
}
|
mortalityCurrent := 0.0
|
||||||
|
mortalityLast := 0.0
|
||||||
mortalityCurrent, mortalityLast, err := s.calculateMortality(ctx, filter, startDate, endExclusive, endDate, location)
|
if hasFilter {
|
||||||
if err != nil {
|
fcrCurrent, fcrLast, err = s.calculateFcr(ctx, filter, startDate, endExclusive, endDate, location)
|
||||||
return nil, err
|
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
|
hppPercent := 0.0
|
||||||
@@ -128,17 +134,7 @@ func (s dashboardService) buildPerformanceStatistics(ctx context.Context, params
|
|||||||
sellingPercent = sellingCurrent / sellingLast * 100
|
sellingPercent = sellingCurrent / sellingLast * 100
|
||||||
}
|
}
|
||||||
|
|
||||||
fcrPercent := 0.0
|
stats := []dto.DashboardStatisticsDTO{
|
||||||
if fcrLast > 0 {
|
|
||||||
fcrPercent = (fcrCurrent - fcrLast) / fcrLast * 100
|
|
||||||
}
|
|
||||||
|
|
||||||
mortalityPercent := 0.0
|
|
||||||
if mortalityLast > 0 {
|
|
||||||
mortalityPercent = (mortalityCurrent - mortalityLast) / mortalityLast * 100
|
|
||||||
}
|
|
||||||
|
|
||||||
return []dto.DashboardStatisticsDTO{
|
|
||||||
{
|
{
|
||||||
Label: "HPP Global",
|
Label: "HPP Global",
|
||||||
Value: roundTo(hppCurrent, 0),
|
Value: roundTo(hppCurrent, 0),
|
||||||
@@ -149,17 +145,32 @@ func (s dashboardService) buildPerformanceStatistics(ctx context.Context, params
|
|||||||
Value: roundTo(sellingCurrent, 0),
|
Value: roundTo(sellingCurrent, 0),
|
||||||
PercentLastMonth: sellingPercent,
|
PercentLastMonth: sellingPercent,
|
||||||
},
|
},
|
||||||
{
|
}
|
||||||
Label: "FCR",
|
|
||||||
Value: roundTo(fcrCurrent, 2),
|
if hasFilter {
|
||||||
PercentLastMonth: fcrPercent,
|
fcrPercent := 0.0
|
||||||
},
|
if fcrLast > 0 {
|
||||||
{
|
fcrPercent = (fcrCurrent - fcrLast) / fcrLast * 100
|
||||||
Label: "Mortality",
|
}
|
||||||
Value: roundTo(mortalityCurrent, 2),
|
mortalityPercent := 0.0
|
||||||
PercentLastMonth: mortalityPercent,
|
if mortalityLast > 0 {
|
||||||
},
|
mortalityPercent = (mortalityCurrent - mortalityLast) / mortalityLast * 100
|
||||||
}, nil
|
}
|
||||||
|
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) {
|
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")
|
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
|
startDate := params.PeriodStart
|
||||||
endExclusive := params.PeriodEndExclusive
|
endExclusive := params.PeriodEndExclusive
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ type PerformanceOverviewFilter struct {
|
|||||||
AnalysisMode string `query:"analysis_mode" validate:"omitempty,oneof=OVERVIEW COMPARASION"`
|
AnalysisMode string `query:"analysis_mode" validate:"omitempty,oneof=OVERVIEW COMPARASION"`
|
||||||
ComparisonType string `query:"comparison_type" validate:"omitempty,oneof=FARM FLOCK KANDANG"`
|
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"`
|
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"`
|
FlockIds []uint `query:"flock_ids" validate:"omitempty,dive,gt=0"`
|
||||||
KandangIds []uint `query:"kandang_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"`
|
Include []string `query:"include" validate:"omitempty,dive,oneof=statistics charts"`
|
||||||
|
|||||||
Reference in New Issue
Block a user