Skip to content
Snippets Groups Projects
Commit 57092657 authored by Tucker Gary Siegel's avatar Tucker Gary Siegel
Browse files

fill so ui doesnt bug out

parent a66a8238
No related branches found
No related tags found
No related merge requests found
...@@ -189,13 +189,30 @@ func forecast(ctx common.DawnCtx, gddReq models.GddRequest, plantdate time.Time, ...@@ -189,13 +189,30 @@ func forecast(ctx common.DawnCtx, gddReq models.GddRequest, plantdate time.Time,
// convert to output model // convert to output model
bins := []models.Bin{} bins := []models.Bin{}
c := 0
for d, v := range temp { for d, v := range temp {
bins = append(bins, models.Bin{ bins = append(bins, models.Bin{
Value: (float64(v) + alpha) / (float64(sum) + float64(binCount)*alpha), Value: (float64(v) + alpha) / (float64(sum) + float64(binCount)*alpha),
Date: plantdate.AddDate(0, 0, d), 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 { sort.Slice(bins, func(i, j int) bool {
return bins[i].Date.Before(bins[j].Date) return bins[i].Date.Before(bins[j].Date)
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment