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

u

parent 7838e3fe
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,8 @@ func getDatesForCfsMatches(cfs [][]float64, lastDateInt int, currentMatch int, k
lastDist := matches[keys[currentMatch]]
tempCMatch := currentMatch
for i, v := range c {
dist := math.Abs(matches[keys[currentMatch]] - v)
dist := math.Abs(matches[keys[tempCMatch]] - v)
// 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 v, exists := out[keys[tempCMatch]]; exists {
......@@ -49,6 +50,7 @@ func getDatesForCfsMatches(cfs [][]float64, lastDateInt int, currentMatch int, k
if tempCMatch >= len(keys) {
break
}
dist = matches[keys[tempCMatch]]
}
lastDist = dist
}
......@@ -120,41 +122,42 @@ func forecast(ctx common.DawnCtx, gddReq models.GddRequest, plantdate time.Time,
// start at plantdate, begin accumulating OBSERVED until we run out
// since this observed, we should only have 1 bin with a value of 100%
// at the end, we should have all observed stages along with all accumulated gdds of the planting year
observedValues := observed.GddValues[start:]
accumulatedGdds := 0.0
lastDist := matches[keys[currentMatch]]
date := 0
for i := 0; i < len(observedValues); i++ {
date = i
dist := math.Abs(matches[keys[currentMatch]] - accumulatedGdds)
// 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 {
out[keys[currentMatch]] = &models.Bins{
Bins: []models.Bin{
{
Value: 1,
Date: plantdate.AddDate(0, 0, i-1),
if start < len(observed.GddValues) {
observedValues := observed.GddValues[start:]
lastDist := matches[keys[currentMatch]]
for i := 0; i < len(observedValues); i++ {
date = i
dist := math.Abs(matches[keys[currentMatch]] - accumulatedGdds)
// 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 {
out[keys[currentMatch]] = &models.Bins{
Bins: []models.Bin{
{
Value: 1,
Date: plantdate.AddDate(0, 0, i-1),
},
},
},
}
currentMatch += 1
if currentMatch >= len(keys) {
break
}
currentMatch += 1
if currentMatch >= len(keys) {
break
}
dist = matches[keys[currentMatch]]
}
dist = matches[keys[currentMatch]]
accumulatedGdds += observedValues[i]
lastDist = dist
}
accumulatedGdds += observedValues[i]
lastDist = dist
}
if currentMatch == len(keys) {
return out
}
// adjust cfs values to start at the accumulated value
adjustedCfs := calculateAccumulatedCfsBasedOnAccumulatedObserved(product, accumulatedGdds, cfs)
cfsHist := getDatesForCfsMatches(adjustedCfs, date, currentMatch, keys, matches)
// this loop will actually build the 5 bins
for k, v := range cfsHist {
......
......@@ -18,8 +18,6 @@ Example:
gddThread.Result(gdds)
}()
gddThread.Wait()
gdds, err := gddThread.Get()
if err != nil {
panic(err)
......
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