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