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
c5d4e7cf
Commit
c5d4e7cf
authored
2 years ago
by
Tucker Gary Siegel
Browse files
Options
Downloads
Patches
Plain Diff
fix date issues
parent
9b985bfa
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
persistence/repositories/nomads.go
+29
-0
29 additions, 0 deletions
persistence/repositories/nomads.go
services/forecast_service.go
+12
-4
12 additions, 4 deletions
services/forecast_service.go
with
41 additions
and
4 deletions
persistence/repositories/nomads.go
+
29
−
0
View file @
c5d4e7cf
...
...
@@ -3,11 +3,13 @@ package repositories
import
(
"context"
errs
"errors"
"time"
"github.com/bradfitz/slice"
"github.com/tgs266/dawn-go-common/common"
"github.com/tgs266/dawn-go-common/errors"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence/entities"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
...
...
@@ -15,6 +17,7 @@ import (
type
NomadsRepository
interface
{
FindCfsByLocation
(
ctx
context
.
Context
,
location
entities
.
Location
)
[]
entities
.
CfsGdd
FindCfsByLocationWithExpand
(
ctx
context
.
Context
,
location
entities
.
Location
,
areaExpand
int
)
[]
entities
.
CfsGdd
FindCfsByLocationWithExpandByPlantingDate
(
ctx
context
.
Context
,
plantingDate
time
.
Time
,
location
entities
.
Location
,
areaExpand
int
)
[]
entities
.
CfsGdd
FindCfsAverageByLocation
(
ctx
context
.
Context
,
location
entities
.
Location
)
entities
.
CfsGdd
FindGefsByLocation
(
ctx
context
.
Context
,
location
entities
.
Location
)
[]
entities
.
GefsGdd
}
...
...
@@ -112,3 +115,29 @@ func (g *nomadsRepositoryImpl) FindCfsByLocation(ctx context.Context, location e
func
(
g
*
nomadsRepositoryImpl
)
FindCfsByLocationWithExpand
(
ctx
context
.
Context
,
location
entities
.
Location
,
areaExpand
int
)
[]
entities
.
CfsGdd
{
return
g
.
findCfsByLocationInternal
(
ctx
,
location
,
areaExpand
)
}
func
(
g
*
nomadsRepositoryImpl
)
FindCfsByLocationWithExpandByPlantingDate
(
ctx
context
.
Context
,
plantingDate
time
.
Time
,
location
entities
.
Location
,
areaExpand
int
)
[]
entities
.
CfsGdd
{
count
:=
g
.
FindCfsAverageByLocation
(
ctx
,
location
)
.
Count
coll
:=
g
.
session
.
Collection
(
"cfs"
)
filter
:=
buildLocationRequestLarger
(
location
,
nil
)
filter
[
"date"
]
=
bson
.
M
{
"$gte"
:
plantingDate
}
cursor
,
err
:=
coll
.
Find
(
ctx
,
filter
,
options
.
Find
()
.
SetLimit
(
int64
(
count
*
areaExpand
)))
var
gs
[]
entities
.
CfsGdd
if
err
!=
nil
{
panic
(
errors
.
NewInternal
(
err
)
.
PutDetail
(
"reason"
,
"cfs"
))
}
if
err
=
cursor
.
All
(
ctx
,
&
gs
);
err
!=
nil
{
panic
(
errors
.
NewInternal
(
err
))
}
if
len
(
gs
)
==
0
{
panic
(
errors
.
NewNotFound
(
nil
)
.
PutDetail
(
"reason"
,
"cfs"
))
}
return
gs
}
This diff is collapsed.
Click to expand it.
services/forecast_service.go
+
12
−
4
View file @
c5d4e7cf
...
...
@@ -15,12 +15,15 @@ import (
)
// this just adjusts cfs by accumulating it with the base value being the provided accumulated value
func
calculateAccumulatedCfsBasedOnAccumulatedObserved
(
product
enums
.
Product
,
accumulated
float64
,
cfs
[]
entities
.
CfsGdd
)
[][]
float64
{
func
calculateAccumulatedCfsBasedOnAccumulatedObserved
(
product
enums
.
Product
,
startDate
int
,
accumulated
float64
,
cfs
[]
entities
.
CfsGdd
)
[][]
float64
{
out
:=
[][]
float64
{}
for
_
,
c
:=
range
cfs
{
tempAccum
:=
accumulated
temp
:=
[]
float64
{}
for
i
:=
range
c
.
MinTemps
{
if
i
<
startDate
{
continue
}
tempAccum
=
tempAccum
+
utils
.
CalculateSingleGdd
(
c
.
MinTemps
[
i
],
c
.
MaxTemps
[
i
],
product
)
temp
=
append
(
temp
,
tempAccum
)
}
...
...
@@ -39,6 +42,9 @@ func getDatesForCfsMatches(cfs [][]float64, lastDateInt int, currentMatch int, k
for
i
,
v
:=
range
c
{
dist
:=
math
.
Abs
(
matches
[
keys
[
tempCMatch
]]
-
v
)
// if z == 0 {
// fmt.Println(keys[tempCMatch], dist, matches[keys[tempCMatch]], v, lastDateInt+i-1)
// }
// 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
{
...
...
@@ -162,13 +168,15 @@ func forecast(ctx context.Context, gddReq models.GddRequest, plantdate time.Time
accumulatedGdds
+=
observedValues
[
i
]
lastDist
=
dist
}
}
else
{
date
=
gddReq
.
PlantingDate
.
YearDay
()
-
1
}
if
currentMatch
==
len
(
keys
)
{
return
out
}
// adjust cfs values to start at the accumulated value
adjustedCfs
:=
calculateAccumulatedCfsBasedOnAccumulatedObserved
(
product
,
accumulatedGdds
,
cfs
)
adjustedCfs
:=
calculateAccumulatedCfsBasedOnAccumulatedObserved
(
product
,
date
,
accumulatedGdds
,
cfs
)
cfsHist
:=
getDatesForCfsMatches
(
adjustedCfs
,
date
,
currentMatch
,
keys
,
matches
)
// this loop will actually build the 5 bins
for
k
,
v
:=
range
cfsHist
{
...
...
@@ -204,7 +212,7 @@ func forecast(ctx context.Context, gddReq models.GddRequest, plantdate time.Time
for
d
,
v
:=
range
temp
{
bins
=
append
(
bins
,
models
.
Bin
{
Value
:
(
float64
(
v
)
+
alpha
)
/
(
float64
(
sum
)
+
float64
(
binCount
)
*
alpha
),
Date
:
plantdate
.
AddDate
(
0
,
0
,
d
),
Date
:
plantdate
.
AddDate
(
0
,
0
,
d
-
date
),
})
c
+=
1
}
...
...
@@ -252,7 +260,7 @@ func comparisonNormals(ctx context.Context, request models.GddRequest, plantdate
start
-=
1
}
i
:=
start
i
:=
0
date
:=
0
out
:=
map
[
string
]
time
.
Time
{}
...
...
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