mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 07:45:44 +00:00
Merge branch 'feat/BE/US-390-Dashboard' into 'development'
Feat/be/us 390 dashboard changes calculate kilo units See merge request mbugroup/lti-api!166
This commit is contained in:
@@ -98,12 +98,14 @@ func (s dashboardService) buildPerformanceStatistics(ctx context.Context, params
|
|||||||
endDate := params.PeriodEnd
|
endDate := params.PeriodEnd
|
||||||
endExclusive := params.PeriodEndExclusive
|
endExclusive := params.PeriodEndExclusive
|
||||||
|
|
||||||
hppCurrent, hppLast, err := s.calculateHppGlobal(ctx, filter, startDate, endExclusive, endDate, location)
|
globalStartDate, globalEndDate, globalEndExclusive := currentPeriodDates(location)
|
||||||
|
|
||||||
|
hppCurrent, hppLast, err := s.calculateHppGlobal(ctx, globalStartDate, globalEndExclusive, globalEndDate, location)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sellingCurrent, sellingLast, err := s.calculateSellingPrice(ctx, filter, endDate, location)
|
sellingCurrent, sellingLast, err := s.calculateSellingPrice(ctx, globalEndDate, location)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -271,15 +273,15 @@ func (s dashboardService) buildPerformanceCharts(ctx context.Context, params *va
|
|||||||
weekFeed := weeklyFeedMap[week]
|
weekFeed := weeklyFeedMap[week]
|
||||||
|
|
||||||
actFcr := 0.0
|
actFcr := 0.0
|
||||||
if weekFeed > 0 {
|
if weekEgg > 0 {
|
||||||
actFcr = weekEgg / weekFeed
|
actFcr = weekFeed / weekEgg
|
||||||
}
|
}
|
||||||
|
|
||||||
cumEgg += weekEgg
|
cumEgg += weekEgg
|
||||||
cumFeed += weekFeed
|
cumFeed += weekFeed
|
||||||
actFcrCum := 0.0
|
actFcrCum := 0.0
|
||||||
if cumFeed > 0 {
|
if cumEgg > 0 {
|
||||||
actFcrCum = cumEgg / cumFeed
|
actFcrCum = cumFeed / cumEgg
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyWeightDataset = append(bodyWeightDataset, map[string]interface{}{
|
bodyWeightDataset = append(bodyWeightDataset, map[string]interface{}{
|
||||||
@@ -357,10 +359,10 @@ func (s dashboardService) buildPerformanceCharts(ctx context.Context, params *va
|
|||||||
},
|
},
|
||||||
"fcr": {
|
"fcr": {
|
||||||
Series: []dto.DashboardChartSeriesDTO{
|
Series: []dto.DashboardChartSeriesDTO{
|
||||||
{Id: "act_fcr", Label: "Act. FCR", Unit: "%"},
|
{Id: "act_fcr", Label: "Act. FCR", Unit: "kg/kg"},
|
||||||
{Id: "std_fcr", Label: "STD. FCR", Unit: "%"},
|
{Id: "std_fcr", Label: "STD. FCR", Unit: "kg/kg"},
|
||||||
{Id: "act_fcr_cum", Label: "Act. FCR Cummulative", Unit: "%"},
|
{Id: "act_fcr_cum", Label: "Act. FCR Cummulative", Unit: "kg/kg"},
|
||||||
{Id: "std_fcr_cum", Label: "STD. FCR Cummulative", Unit: "%"},
|
{Id: "std_fcr_cum", Label: "STD. FCR Cummulative", Unit: "kg/kg"},
|
||||||
},
|
},
|
||||||
Dataset: fcrDataset,
|
Dataset: fcrDataset,
|
||||||
},
|
},
|
||||||
@@ -843,12 +845,12 @@ func percentDelta(current, last float64) float64 {
|
|||||||
return (current - last) / last
|
return (current - last) / last
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s dashboardService) calculateHppGlobal(ctx context.Context, filter *validation.DashboardFilter, startDate, endExclusive, endDate time.Time, location *time.Location) (float64, float64, error) {
|
func (s dashboardService) calculateHppGlobal(ctx context.Context, startDate, endExclusive, endDate time.Time, location *time.Location) (float64, float64, error) {
|
||||||
totalEggKg, err := s.Repository.SumEggProductionWeightKg(ctx, startDate, endExclusive, filter)
|
totalEggKg, err := s.Repository.SumEggProductionWeightKg(ctx, startDate, endExclusive, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
totalCost, err := s.sumHppCost(ctx, filter, startDate, endExclusive)
|
totalCost, err := s.sumHppCost(ctx, nil, startDate, endExclusive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
@@ -859,11 +861,11 @@ func (s dashboardService) calculateHppGlobal(ctx context.Context, filter *valida
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastMonthStart, lastMonthEndExclusive := monthRange(endDate.AddDate(0, -1, 0), location)
|
lastMonthStart, lastMonthEndExclusive := monthRange(endDate.AddDate(0, -1, 0), location)
|
||||||
lastEggKg, err := s.Repository.SumEggProductionWeightKg(ctx, lastMonthStart, lastMonthEndExclusive, filter)
|
lastEggKg, err := s.Repository.SumEggProductionWeightKg(ctx, lastMonthStart, lastMonthEndExclusive, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
lastCost, err := s.sumHppCost(ctx, filter, lastMonthStart, lastMonthEndExclusive)
|
lastCost, err := s.sumHppCost(ctx, nil, lastMonthStart, lastMonthEndExclusive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
@@ -876,16 +878,16 @@ func (s dashboardService) calculateHppGlobal(ctx context.Context, filter *valida
|
|||||||
return hppCurrent, hppLast, nil
|
return hppCurrent, hppLast, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s dashboardService) calculateSellingPrice(ctx context.Context, filter *validation.DashboardFilter, endDate time.Time, location *time.Location) (float64, float64, error) {
|
func (s dashboardService) calculateSellingPrice(ctx context.Context, endDate time.Time, location *time.Location) (float64, float64, error) {
|
||||||
startPrevMonth, endPrevMonthExclusive := monthRange(endDate.AddDate(0, -1, 0), location)
|
startPrevMonth, endPrevMonthExclusive := monthRange(endDate.AddDate(0, -1, 0), location)
|
||||||
currentEndExclusive := endDate.AddDate(0, 0, 1)
|
currentEndExclusive := endDate.AddDate(0, 0, 1)
|
||||||
|
|
||||||
currentAvg, err := s.avgSellingPrice(ctx, filter, startPrevMonth, currentEndExclusive)
|
currentAvg, err := s.avgSellingPrice(ctx, nil, startPrevMonth, currentEndExclusive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
lastAvg, err := s.avgSellingPrice(ctx, filter, startPrevMonth, endPrevMonthExclusive)
|
lastAvg, err := s.avgSellingPrice(ctx, nil, startPrevMonth, endPrevMonthExclusive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
@@ -935,11 +937,11 @@ func (s dashboardService) fcrValue(ctx context.Context, filter *validation.Dashb
|
|||||||
}
|
}
|
||||||
feedUsageGrams := feedUsageToGrams(feedRows)
|
feedUsageGrams := feedUsageToGrams(feedRows)
|
||||||
|
|
||||||
if feedUsageGrams <= 0 {
|
if eggWeightGrams <= 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return eggWeightGrams / feedUsageGrams, nil
|
return feedUsageGrams / eggWeightGrams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s dashboardService) mortalityValue(ctx context.Context, filter *validation.DashboardFilter, startDate, endExclusive time.Time) (float64, error) {
|
func (s dashboardService) mortalityValue(ctx context.Context, filter *validation.DashboardFilter, startDate, endExclusive time.Time) (float64, error) {
|
||||||
@@ -1027,3 +1029,11 @@ func monthRange(t time.Time, location *time.Location) (time.Time, time.Time) {
|
|||||||
endExclusive := start.AddDate(0, 1, 0)
|
endExclusive := start.AddDate(0, 1, 0)
|
||||||
return start, endExclusive
|
return start, endExclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func currentPeriodDates(location *time.Location) (time.Time, time.Time, time.Time) {
|
||||||
|
now := time.Now().In(location)
|
||||||
|
startDate := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, location)
|
||||||
|
endDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, location)
|
||||||
|
endExclusive := endDate.AddDate(0, 0, 1)
|
||||||
|
return startDate, endDate, endExclusive
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user