diff --git a/services/forecast_service.go b/services/forecast_service.go index 07d18d25242ceb58c5e58beb07f733cd767352d4..4564c8f9cca143deb849b6061a8109e2eb13a117 100644 --- a/services/forecast_service.go +++ b/services/forecast_service.go @@ -20,8 +20,9 @@ func calculateAccumulatedCfsBasedOnAccumulatedObserved(product enums.Product, st for _, c := range cfs { tempAccum := accumulated temp := []float64{} + sd := startDate - c.Date.Time().YearDay() for i := range c.MinTemps { - if i < startDate { + if i < sd { continue } tempAccum = tempAccum + utils.CalculateSingleGdd(c.MinTemps[i], c.MaxTemps[i], product) @@ -42,11 +43,11 @@ func getDatesForCfsMatches(cfs [][]float64, lastDateInt int, currentMatch int, k for i, v := range c { dist := math.Abs(matches[keys[tempCMatch]] - v) - // if z == 0 { - // fmt.Println(keys[tempCMatch], dist, matches[keys[tempCMatch]], v, lastDateInt+i-1, tempCMatch, len(keys)) - // } // check if the last value is closer than the current. if it is, then the last value is the one to return if dist > lastDist { + // if z == 0 { + // fmt.Println(keys[tempCMatch], dist, matches[keys[tempCMatch]], v, lastDateInt+i-1, tempCMatch, len(keys)) + // } if v, exists := out[keys[tempCMatch]]; exists { out[keys[tempCMatch]] = append(v, lastDateInt+i-1) } else { @@ -170,7 +171,7 @@ func forecast(ctx context.Context, gddReq models.GddRequest, plantdate time.Time lastDist = dist } } else { - date = gddReq.PlantingDate.YearDay() - 1 + date = gddReq.PlantingDate.YearDay() } if currentMatch == len(keys) { @@ -180,6 +181,10 @@ func forecast(ctx context.Context, gddReq models.GddRequest, plantdate time.Time adjustedCfs := calculateAccumulatedCfsBasedOnAccumulatedObserved(product, date, accumulatedGdds, cfs) cfsHist := getDatesForCfsMatches(adjustedCfs, date, currentMatch, keys, matches) // this loop will actually build the 5 bins + // fmt.Println(cfsHist) + // for k, v := range cfsHist { + // fmt.Println(k, v) + // } // fmt.Println(date) for k, v := range cfsHist {