mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'development' into 'codex/dashboard-without-uniformity'
# Conflicts: # internal/modules/dashboards/repositories/dashboard_stats.repository.go # internal/modules/dashboards/services/dashboard.service.go # internal/modules/production/uniformities/services/uniformity.service.go
This commit is contained in:
@@ -265,6 +265,7 @@ func (s dashboardService) buildPerformanceCharts(ctx context.Context, params *va
|
||||
}
|
||||
|
||||
bodyWeightDataset := make([]map[string]interface{}, 0, len(weeks))
|
||||
bodyWeightDatasetIndexByWeek := make(map[int]int, len(weeks))
|
||||
performanceDataset := make([]map[string]interface{}, 0, len(weeks))
|
||||
fcrDataset := make([]map[string]interface{}, 0, len(weeks))
|
||||
deplesiDataset := make([]map[string]interface{}, 0, len(weeks))
|
||||
@@ -358,6 +359,15 @@ func (s dashboardService) buildPerformanceCharts(ctx context.Context, params *va
|
||||
}
|
||||
}
|
||||
|
||||
bodyWeightDataset = extendBodyWeightDatasetUntilEndDate(
|
||||
bodyWeightDataset,
|
||||
bodyWeightDatasetIndexByWeek,
|
||||
uniformities,
|
||||
uniformityMap,
|
||||
standardMap,
|
||||
params.PeriodEnd,
|
||||
)
|
||||
|
||||
qualityRows, err := s.Repository.GetEggQualityWeeklyMetrics(ctx, startDate, endExclusive, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1081,6 +1091,69 @@ func (s dashboardService) avgSellingPrice(ctx context.Context, filter *validatio
|
||||
return result.TotalPrice / result.TotalWeight, nil
|
||||
}
|
||||
|
||||
func extendBodyWeightDatasetUntilEndDate(
|
||||
dataset []map[string]interface{},
|
||||
indexByWeek map[int]int,
|
||||
uniformities []repository.UniformityWeeklyMetric,
|
||||
uniformityMap map[int]repository.UniformityWeeklyMetric,
|
||||
standardMap map[int]repository.StandardWeeklyMetric,
|
||||
periodEnd time.Time,
|
||||
) []map[string]interface{} {
|
||||
latestUniformityWeek := 0
|
||||
var latestUniformityDate time.Time
|
||||
for _, row := range uniformities {
|
||||
if row.Week <= 0 || row.UniformDate.IsZero() {
|
||||
continue
|
||||
}
|
||||
if latestUniformityDate.IsZero() || row.UniformDate.After(latestUniformityDate) || (row.UniformDate.Equal(latestUniformityDate) && row.Week > latestUniformityWeek) {
|
||||
latestUniformityDate = row.UniformDate
|
||||
latestUniformityWeek = row.Week
|
||||
}
|
||||
}
|
||||
|
||||
if latestUniformityWeek <= 0 || latestUniformityDate.IsZero() || periodEnd.IsZero() || !periodEnd.After(latestUniformityDate) {
|
||||
return dataset
|
||||
}
|
||||
|
||||
additionalWeeks := int(math.Ceil(periodEnd.Sub(latestUniformityDate).Hours() / (24 * 7)))
|
||||
if additionalWeeks <= 0 {
|
||||
return dataset
|
||||
}
|
||||
|
||||
lastUniformity := uniformityMap[latestUniformityWeek]
|
||||
lastStandard := standardMap[latestUniformityWeek]
|
||||
latestBodyWeight := roundTo(lastUniformity.AverageWeight, 2)
|
||||
latestStdBodyWeight := roundTo(lastStandard.StdBodyWeight, 2)
|
||||
|
||||
targetWeek := latestUniformityWeek + additionalWeeks
|
||||
for week := latestUniformityWeek + 1; week <= targetWeek; week++ {
|
||||
row := map[string]interface{}{
|
||||
"week": week,
|
||||
"body_weight": latestBodyWeight,
|
||||
"std_body_weight": latestStdBodyWeight,
|
||||
}
|
||||
|
||||
if idx, ok := indexByWeek[week]; ok {
|
||||
dataset[idx] = row
|
||||
continue
|
||||
}
|
||||
|
||||
dataset = append(dataset, row)
|
||||
indexByWeek[week] = len(dataset) - 1
|
||||
}
|
||||
|
||||
sort.Slice(dataset, func(i, j int) bool {
|
||||
return datasetWeek(dataset[i]) < datasetWeek(dataset[j])
|
||||
})
|
||||
|
||||
return dataset
|
||||
}
|
||||
|
||||
func datasetWeek(row map[string]interface{}) int {
|
||||
week, _ := row["week"].(int)
|
||||
return week
|
||||
}
|
||||
|
||||
func feedUsageToGrams(rows []repository.FeedUsageByUom) float64 {
|
||||
total := 0.0
|
||||
for _, row := range rows {
|
||||
|
||||
Reference in New Issue
Block a user