diff --git a/services/forecast_service.go b/services/forecast_service.go index b4b1d38286cf30f2e440b313485db8d263f89666..3f86a8791a6b1d6102e0fcfb76d9aea9618fcec2 100644 --- a/services/forecast_service.go +++ b/services/forecast_service.go @@ -189,13 +189,30 @@ func forecast(ctx common.DawnCtx, gddReq models.GddRequest, plantdate time.Time, // convert to output model bins := []models.Bin{} + c := 0 for d, v := range temp { bins = append(bins, models.Bin{ Value: (float64(v) + alpha) / (float64(sum) + float64(binCount)*alpha), Date: plantdate.AddDate(0, 0, d), }) + c += 1 } + // need to fill with zeros because ui requires a certain length + if len(bins) < binCount { + for { + bins = append(bins, models.Bin{ + Value: 0, + Date: bins[c].Date.AddDate(0, 0, 1), + }) + c += 1 + if len(bins) == binCount { + break + } + } + } + + // sort by date sort.Slice(bins, func(i, j int) bool { return bins[i].Date.Before(bins[j].Date) })