diff --git a/services/gdd_service.go b/services/gdd_service.go index 3b73b2f62895f17889cd7a7066dd53229712bd1a..7ed187c29bf73b2a7fcb616a7d9d4f23311a8dc8 100644 --- a/services/gdd_service.go +++ b/services/gdd_service.go @@ -43,11 +43,20 @@ func GetNormalValues(request models.GddRequest) models.GddResponse { var returnGdds models.GddResponse var gdds []float64 rows := [][]float64{} - for i := 0; i < len(gs[0].MinTemps); i++ { //; i++ { + + // get the int of the planting date. If the date is less than the first date, we do nothing + // otherwise, we adjust + // need to do before because of accumulations + sliceDateInt := request.PlantingDate.YearDay() - 1 + if sliceDateInt < 0 { + sliceDateInt = 0 + } + + for i := sliceDateInt; i < len(gs[0].MinTemps); i++ { //; i++ { row := []float64{} for j := 0; j < len(gs); j++ { row = append(row, utils.CalculateSingleGdd(gs[j].MinTemps[i], gs[j].MaxTemps[i], product)) - if request.Accumulate && i > 0 { + if request.Accumulate && i > sliceDateInt { row[j] += rows[len(rows)-1][j] } }