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
95ba8786
Commit
95ba8786
authored
2 years ago
by
Tucker Gary Siegel
Browse files
Options
Downloads
Patches
Plain Diff
optimize
parent
0b38a7f8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/forecast_service.go
+14
-21
14 additions, 21 deletions
services/forecast_service.go
with
14 additions
and
21 deletions
services/forecast_service.go
+
14
−
21
View file @
95ba8786
...
@@ -58,10 +58,14 @@ func getDatesForCfsMatches(cfs [][]float64, lastDateInt int, currentMatch int, k
...
@@ -58,10 +58,14 @@ func getDatesForCfsMatches(cfs [][]float64, lastDateInt int, currentMatch int, k
return
out
return
out
}
}
// bin array of dates into a frequency map and return that map and keys
// bin array of dates into a frequency map
func
bin
(
data
[]
int
)
(
map
[
int
]
int
,
[]
int
)
{
//
// returns: frequency map, keys, and the key with the highest frequency
func
bin
(
data
[]
int
)
(
map
[
int
]
int
,
[]
int
,
int
)
{
out
:=
map
[
int
]
int
{}
out
:=
map
[
int
]
int
{}
keys
:=
[]
int
{}
keys
:=
[]
int
{}
maxKey
:=
0
max
:=
0
for
_
,
d
:=
range
data
{
for
_
,
d
:=
range
data
{
if
count
,
exists
:=
out
[
d
];
exists
{
if
count
,
exists
:=
out
[
d
];
exists
{
out
[
d
]
=
count
+
1
out
[
d
]
=
count
+
1
...
@@ -69,21 +73,12 @@ func bin(data []int) (map[int]int, []int) {
...
@@ -69,21 +73,12 @@ func bin(data []int) (map[int]int, []int) {
out
[
d
]
=
1
out
[
d
]
=
1
keys
=
append
(
keys
,
d
)
keys
=
append
(
keys
,
d
)
}
}
}
if
out
[
d
]
>
max
{
return
out
,
keys
max
=
out
[
d
]
}
maxKey
=
d
// get the highest frequency bin
func
getLargestBinCount
(
bins
map
[
int
]
int
)
int
{
largest
:=
0
largestKey
:=
0
for
key
,
count
:=
range
bins
{
if
count
>
largest
{
largest
=
count
largestKey
=
key
}
}
}
}
return
largest
Key
return
out
,
keys
,
max
Key
}
}
// get keys of the stage matches in sorted order
// get keys of the stage matches in sorted order
...
@@ -161,9 +156,8 @@ func forecast(ctx common.DawnCtx, gddReq models.GddRequest, plantdate time.Time,
...
@@ -161,9 +156,8 @@ func forecast(ctx common.DawnCtx, gddReq models.GddRequest, plantdate time.Time,
// 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
{
binnedDates
,
keys
:=
bin
(
v
)
binnedDates
,
keys
,
largestKey
:=
bin
(
v
)
stepSize
:=
int
(
math
.
Ceil
(
AvgDiff
(
keys
))
+
1
)
// add 1 to increase range and for uncertainty
stepSize
:=
int
(
math
.
Ceil
(
AvgDiff
(
keys
))
+
1
)
// add 1 to increase range and for uncertainty
largestKey
:=
getLargestBinCount
(
binnedDates
)
sort
.
Ints
(
keys
)
sort
.
Ints
(
keys
)
...
@@ -333,14 +327,13 @@ func CalculateStages(ctx common.DawnCtx, request models.StageRequest) map[string
...
@@ -333,14 +327,13 @@ func CalculateStages(ctx common.DawnCtx, request models.StageRequest) map[string
Accumulate
:
false
,
Accumulate
:
false
,
Product
:
"CORN"
,
Product
:
"CORN"
,
}
}
gdds
,
cfs
:=
asyncCollectGddsAndCfs
(
ctx
,
gddReq
)
stageMatches
:=
models
.
BuildStageMatches
(
request
.
Mode
,
request
.
Value
)
stageMatches
:=
models
.
BuildStageMatches
(
request
.
Mode
,
request
.
Value
)
comparisonThread
:=
dispatch
.
New
[
map
[
string
]
time
.
Time
]()
comparisonThread
:=
dispatch
.
New
[
map
[
string
]
time
.
Time
]()
go
comparisonGoRoutine
(
gddReq
,
request
.
PlantDate
,
stageMatches
,
request
.
Comparison
,
comparisonThread
)
go
comparisonGoRoutine
(
gddReq
,
request
.
PlantDate
,
stageMatches
,
request
.
Comparison
,
comparisonThread
)
gdds
,
cfs
:=
asyncCollectGddsAndCfs
(
ctx
,
gddReq
)
out
:=
forecast
(
ctx
,
gddReq
,
request
.
PlantDate
,
stageMatches
,
gdds
,
cfs
)
out
:=
forecast
(
ctx
,
gddReq
,
request
.
PlantDate
,
stageMatches
,
gdds
,
cfs
)
// block, wait for comparison results
// block, wait for comparison results
...
...
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