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
e49c023a
Commit
e49c023a
authored
3 years ago
by
Tucker Siegel
Browse files
Options
Downloads
Patches
Plain Diff
change logic
parent
1f820123
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/forecast_service.go
+87
-17
87 additions, 17 deletions
services/forecast_service.go
with
87 additions
and
17 deletions
services/forecast_service.go
+
87
−
17
View file @
e49c023a
package
services
import
(
"fmt"
"math"
"sort"
"time"
"github.com/montanaflynn/stats"
...
...
@@ -94,8 +96,8 @@ func CalculateStages(ctx common.DawnCtx, request models.StageRequest) map[string
}
normal
,
_
:=
stats
.
Mean
(
accs2
)
min
,
_
:=
stats
.
PercentileNearestRank
(
accs2
,
5
)
max
,
_
:=
stats
.
PercentileNearestRank
(
accs2
,
95
)
min
,
_
:=
stats
.
PercentileNearestRank
(
accs2
,
2.
5
)
max
,
_
:=
stats
.
PercentileNearestRank
(
accs2
,
9
7.
5
)
accNormal
=
normal
acc5thNormal
=
min
...
...
@@ -152,6 +154,22 @@ func CalculateStages(ctx common.DawnCtx, request models.StageRequest) map[string
}
func
AvgDiff
(
data
[]
int
)
float64
{
sort
.
Ints
(
data
)
sum
:=
0.0
c
:=
0
for
i
:=
0
;
i
<
len
(
data
)
-
1
;
i
++
{
diff
:=
math
.
Abs
(
float64
(
data
[
i
]
-
data
[
i
+
1
]))
sum
+=
diff
c
+=
1
}
return
sum
/
float64
(
c
)
}
func
Min
(
data
[]
int
)
int
{
sort
.
Ints
(
data
)
return
data
[
0
]
}
func
BinStageMatches
(
stageState
map
[
string
]
models
.
StageStateInner
,
year
int
,
start
int
,
plantDate
time
.
Time
)
map
[
string
]
models
.
Bins
{
response
:=
map
[
string
]
models
.
Bins
{}
alpha
:=
1.0
...
...
@@ -161,24 +179,13 @@ func BinStageMatches(stageState map[string]models.StageStateInner, year int, sta
}
for
state
,
stateVal
:=
range
stageState
{
min
:=
stateVal
.
Normal95thIdx
max
:=
stateVal
.
Normal5thIdx
// min := stateVal.Normal95thIdx
min
:=
Min
(
stateVal
.
Hists
)
stepSize
:=
int
(
math
.
Ceil
(
AvgDiff
(
stateVal
.
Hists
))
+
1
)
// add 1 to increase range (cheating a little) and for uncertainty
max
:=
min
+
int
(
stepSize
)
*
5
rangeSize
:=
max
-
min
if
rangeSize
%
5
!=
0
{
target
:=
math
.
Ceil
(
float64
(
rangeSize
)
/
5
)
*
5
dist
:=
math
.
Abs
((
target
-
float64
(
rangeSize
)))
move
:=
math
.
Ceil
(
dist
/
2
)
max
+=
int
(
move
)
min
-=
int
(
move
)
rangeSize
=
max
-
min
if
rangeSize
%
5
!=
0
{
min
-=
1
}
rangeSize
=
max
-
min
}
arr
:=
[]
float64
{}
idxs
:=
[]
int
{}
stepSize
:=
rangeSize
/
5
base
:=
min
total
:=
0
for
i
:=
0
;
i
<
5
;
i
++
{
...
...
@@ -209,11 +216,74 @@ func BinStageMatches(stageState map[string]models.StageStateInner, year int, sta
inner
.
NormalMax
=
plantDate
.
AddDate
(
0
,
0
,
max
-
start
)
inner
.
NormalMean
=
plantDate
.
AddDate
(
0
,
0
,
stateVal
.
NormalMeanIdx
-
start
)
inner
.
Count
=
total
fmt
.
Println
(
state
,
rangeSize
,
stepSize
,
total
)
response
[
state
]
=
inner
}
return
response
}
// func BinStageMatches(stageState map[string]models.StageStateInner, year int, start int, plantDate time.Time) map[string]models.Bins {
// response := map[string]models.Bins{}
// alpha := 1.0
// add := 0
// if year%4 == 0 && year%100 != 0 || year%400 == 0 {
// add -= 1
// }
// for state, stateVal := range stageState {
// min := stateVal.Normal95thIdx
// max := stateVal.Normal5thIdx
// rangeSize := max - min
// if rangeSize%5 != 0 {
// target := math.Ceil(float64(rangeSize)/5) * 5
// dist := math.Abs((target - float64(rangeSize)))
// move := math.Ceil(dist / 2)
// max += int(move)
// min -= int(move)
// rangeSize = max - min
// if rangeSize%5 != 0 {
// min -= 1
// }
// rangeSize = max - min
// }
// arr := []float64{}
// idxs := []int{}
// stepSize := rangeSize / 5
// base := min
// total := 0
// for i := 0; i < 5; i++ {
// count := 0.0
// for _, h := range stateVal.Hists {
// if base <= h && h < base+stepSize {
// count += 1
// total += 1
// }
// }
// idxs = append(idxs, base)
// arr = append(arr, count)
// base += stepSize
// }
// inner := models.Bins{}
// inner.Bins = []models.Bin{}
// for i := 0; i < 5; i++ {
// idx := idxs[i] + add
// date := plantDate.AddDate(0, 0, idx-start)
// val := arr[i]
// smoothedVal := (val + alpha) / (float64(total) + 5*alpha) // modified version of laplace smoothing to remove 0%
// inner.Bins = append(inner.Bins, models.Bin{
// Date: date,
// Value: smoothedVal,
// })
// }
// inner.NormalMin = plantDate.AddDate(0, 0, min-start)
// inner.NormalMax = plantDate.AddDate(0, 0, max-start)
// inner.NormalMean = plantDate.AddDate(0, 0, stateVal.NormalMeanIdx-start)
// inner.Count = total
// response[state] = inner
// }
// return response
// }
func
ForecastFirstLastFreeze
(
ctx
common
.
DawnCtx
,
request
models
.
FreezingForecastRequest
)
models
.
FreezingForecastResponse
{
lastFreezeIdx
:=
0
firstFreezeIdx
:=
0
...
...
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