Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dawn-gdd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dawn
go-backend
dawn-gdd
Commits
809f8f30
Commit
809f8f30
authored
3 years ago
by
Tucker Siegel
Browse files
Options
Downloads
Patches
Plain Diff
temp
parent
0a5bfd36
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
models/forecast.go
+27
-36
27 additions, 36 deletions
models/forecast.go
services/forecast_service.go
+30
-41
30 additions, 41 deletions
services/forecast_service.go
with
57 additions
and
77 deletions
models/forecast.go
+
27
−
36
View file @
809f8f30
...
@@ -89,9 +89,7 @@ func (r StageRequest) Validate() error {
...
@@ -89,9 +89,7 @@ func (r StageRequest) Validate() error {
}
}
type
StageData
struct
{
type
StageData
struct
{
MeanGdds
[]
float64
AllGdds
[][]
float64
MaxGdds
[]
float64
MinGdds
[]
float64
}
}
type
StageMatches
struct
{
type
StageMatches
struct
{
...
@@ -100,15 +98,8 @@ type StageMatches struct {
...
@@ -100,15 +98,8 @@ type StageMatches struct {
}
}
type
StageStateInner
struct
{
type
StageStateInner
struct
{
FoundMin
int
Dists
[]
float64
FoundMax
int
Hists
[]
float64
FoundMean
int
MinDist
float64
MaxDist
float64
MeanDist
float64
Done
bool
}
}
func
(
s
StageStateInner
)
AddToAllFound
(
val
int
)
StageStateInner
{
func
(
s
StageStateInner
)
AddToAllFound
(
val
int
)
StageStateInner
{
...
@@ -135,30 +126,30 @@ func BuildStageMatches(mode string, value int, start int, fyData StageData, req
...
@@ -135,30 +126,30 @@ func BuildStageMatches(mode string, value int, start int, fyData StageData, req
harvestVal
=
float64
(
value
)
harvestVal
=
float64
(
value
)
}
}
if
!
req
.
AnchorDate
.
IsZero
()
{
//
if !req.AnchorDate.IsZero() {
mod
:=
1.0
//
mod := 1.0
switch
req
.
AnchorStage
{
//
switch req.AnchorStage {
case
"emergence"
:
//
case "emergence":
mod
=
1.0
/
0.07
//
mod = 1.0 / 0.07
case
"3LeafCollar"
:
//
case "3LeafCollar":
mod
=
1.0
/
0.13
//
mod = 1.0 / 0.13
case
"6LeafCollar"
:
//
case "6LeafCollar":
mod
=
1.0
/
0.2
//
mod = 1.0 / 0.2
case
"silk"
:
//
case "silk":
mod
=
1.0
/
0.545
//
mod = 1.0 / 0.545
case
"milk"
:
//
case "milk":
mod
=
1.0
/
0.725
//
mod = 1.0 / 0.725
}
//
}
accMean
:=
0.0
//
accMean := 0.0
for
i
:=
start
;
i
<
len
(
fyData
.
MaxGdds
);
i
++
{
//
for i := start; i < len(fyData.MaxGdds); i++ {
accMean
+=
fyData
.
MeanGdds
[
i
]
//
accMean += fyData.MeanGdds[i]
meanDate
:=
req
.
PlantDate
.
AddDate
(
0
,
0
,
i
-
start
)
//
meanDate := req.PlantDate.AddDate(0, 0, i-start)
if
req
.
AnchorDate
==
meanDate
{
//
if req.AnchorDate == meanDate {
harvestVal
=
accMean
*
mod
//
harvestVal = accMean * mod
break
//
break
}
//
}
}
//
}
}
//
}
return
map
[
string
]
float64
{
return
map
[
string
]
float64
{
"emergence"
:
harvestVal
*
0.07
,
"emergence"
:
harvestVal
*
0.07
,
...
...
This diff is collapsed.
Click to expand it.
services/forecast_service.go
+
30
−
41
View file @
809f8f30
...
@@ -15,26 +15,24 @@ func GetStageYearData(ctx common.DawnCtx, request models.GddRequest) models.Stag
...
@@ -15,26 +15,24 @@ func GetStageYearData(ctx common.DawnCtx, request models.GddRequest) models.Stag
product
:=
enums
.
GetProductFromString
(
request
.
Product
)
product
:=
enums
.
GetProductFromString
(
request
.
Product
)
gddData
:=
persistence
.
CurrentGddFindFirstByYearAndLocation
(
ctx
,
request
.
BuildLocation
())
gddData
:=
persistence
.
CurrentGddFindFirstByYearAndLocation
(
ctx
,
request
.
BuildLocation
())
gdds
:=
utils
.
CalculateGddValues
(
gddData
.
MinTemps
,
gddData
.
MaxTemps
,
product
,
false
)
gdds
:=
utils
.
CalculateGddValues
(
gddData
.
MinTemps
,
gddData
.
MaxTemps
,
product
,
false
)
cfsData
:=
GetCfsGddValues
(
request
)
//
cfsData := GetCfsGddValues(request)
request
.
Year
=
gddData
.
AnalogYear
request
.
Year
=
gddData
.
AnalogYear
analogYearData
:=
GetGddValues
(
ctx
,
request
)
// analogYearData := GetGddValues(ctx, request)
normalGdd
:=
GetNormalValues
(
request
)
meanGdds
:=
append
(
gdds
,
cfsData
.
GddValues
...
)
allCfs
:=
persistence
.
CfsFindByLocation
(
request
.
BuildLocation
())
maxGdds
:=
append
(
gdds
,
cfsData
.
UpperBound
...
)
minGdds
:=
append
(
gdds
,
cfsData
.
LowerBound
...
)
if
len
(
meanGdds
)
!=
len
(
analogYearData
.
GddValues
)
{
gddArr
:=
[][]
float64
{}
meanGdds
=
append
(
meanGdds
,
analogYearData
.
GddValues
[
len
(
meanGdds
)
:
]
...
)
for
i
,
c
:=
range
allCfs
{
minGdds
=
append
(
minGdds
,
analogYearData
.
GddValues
[
len
(
minGdds
)
:
]
...
)
// gddArr = append(gddArr, )
maxGdds
=
append
(
maxGdds
,
analogYearData
.
GddValues
[
len
(
maxGdds
)
:
]
...
)
gddArr
=
append
(
gddArr
,
gdds
)
gddArr
[
i
]
=
append
(
gddArr
[
i
],
utils
.
CalculateGddValues
(
c
.
MinTemps
,
c
.
MaxTemps
,
product
,
false
)
...
)
gddArr
[
i
]
=
append
(
gddArr
[
i
],
normalGdd
.
GddValues
[
len
(
gddArr
[
i
])
:
]
...
)
}
}
// fmt.Println(time.Since(t).Milliseconds())
returnData
:=
models
.
StageData
{
returnData
:=
models
.
StageData
{
MeanGdds
:
meanGdds
,
AllGdds
:
gddArr
,
MaxGdds
:
maxGdds
,
MinGdds
:
minGdds
,
}
}
return
returnData
return
returnData
}
}
...
@@ -55,43 +53,34 @@ func CalculateStages(ctx common.DawnCtx, request models.StageRequest) map[string
...
@@ -55,43 +53,34 @@ func CalculateStages(ctx common.DawnCtx, request models.StageRequest) map[string
start
-=
1
start
-=
1
}
}
accMin
:=
0.0
accMax
:=
0.0
accMean
:=
0.0
state
:=
map
[
string
]
models
.
StageStateInner
{}
state
:=
map
[
string
]
models
.
StageStateInner
{}
stageMatches
:=
models
.
BuildStageMatches
(
request
.
Mode
,
request
.
Value
,
start
,
fyData
,
request
)
stageMatches
:=
models
.
BuildStageMatches
(
request
.
Mode
,
request
.
Value
,
start
,
fyData
,
request
)
for
i
:=
start
;
i
<
len
(
fyData
.
MaxGdds
);
i
++
{
accMin
+=
fyData
.
MinGdds
[
i
]
accs
:=
make
([]
float64
,
len
(
fyData
.
AllGdds
))
accMax
+=
fyData
.
MaxGdds
[
i
]
accMean
+=
fyData
.
MeanGdds
[
i
]
for
i
:=
start
;
i
<
len
(
fyData
.
AllGdds
[
0
]);
i
++
{
for
r
,
v
:=
range
fyData
.
AllGdds
{
accs
[
r
]
+=
v
[
i
]
}
for
stage
,
stageVal
:=
range
stageMatches
{
for
stage
,
stageVal
:=
range
stageMatches
{
dists
:=
make
([]
float64
,
len
(
fyData
.
AllGdds
))
for
r
,
v
:=
range
accs
{
dists
[
r
]
=
math
.
Abs
(
stageVal
-
v
)
}
if
val
,
ok
:=
state
[
stage
];
!
ok
{
if
val
,
ok
:=
state
[
stage
];
!
ok
{
state
[
stage
]
=
models
.
StageStateInner
{
state
[
stage
]
=
models
.
StageStateInner
{
MinDist
:
math
.
Abs
(
accMin
-
stageVal
),
Dists
:
dists
,
MaxDist
:
math
.
Abs
(
accMax
-
stageVal
),
Hists
:
make
([]
int
,
len
(
fyData
.
AllGdds
)),
MeanDist
:
math
.
Abs
(
accMean
-
stageVal
),
FoundMin
:
i
,
FoundMax
:
i
,
FoundMean
:
i
,
}
}
}
else
{
}
else
{
if
math
.
Abs
(
accMin
-
stageVal
)
<
val
.
MinDist
{
for
r
:=
range
accs
{
val
.
FoundMin
=
i
if
dists
[
r
]
<
val
.
Dists
[
r
]
{
val
.
MinDist
=
math
.
Abs
(
accMin
-
stageVal
)
val
.
Hists
[
r
]
=
i
state
[
stage
]
=
val
val
.
Dists
[
r
]
=
dists
[
r
]
}
state
[
stage
]
=
val
if
math
.
Abs
(
accMean
-
stageVal
)
<
val
.
MeanDist
{
}
val
.
FoundMean
=
i
val
.
MeanDist
=
math
.
Abs
(
accMean
-
stageVal
)
state
[
stage
]
=
val
}
if
math
.
Abs
(
accMax
-
stageVal
)
<
val
.
MaxDist
{
val
.
FoundMax
=
i
val
.
MaxDist
=
math
.
Abs
(
accMax
-
stageVal
)
state
[
stage
]
=
val
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment