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
f9f22f88
Commit
f9f22f88
authored
2 years ago
by
Tucker Gary Siegel
Browse files
Options
Downloads
Patches
Plain Diff
add confidence interval plantingDate
parent
5db1b81e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
controllers/misc_controller.go
+1
-0
1 addition, 0 deletions
controllers/misc_controller.go
models/confidence_interval.go
+25
-10
25 additions, 10 deletions
models/confidence_interval.go
services/confidence_interval_service.go
+10
-2
10 additions, 2 deletions
services/confidence_interval_service.go
with
36 additions
and
12 deletions
controllers/misc_controller.go
+
1
−
0
View file @
f9f22f88
...
@@ -52,6 +52,7 @@ func GetAnalogYear(c *fiber.Ctx) error {
...
@@ -52,6 +52,7 @@ func GetAnalogYear(c *fiber.Ctx) error {
// @Param Interval query number true "Interval values" Enums(80, 85, 90, 95, 99, 99.5, 99.9)
// @Param Interval query number true "Interval values" Enums(80, 85, 90, 95, 99, 99.5, 99.9)
// @Param latitude query number true "Latitude to search for"
// @Param latitude query number true "Latitude to search for"
// @Param longitude query number true "Longitude to search for"
// @Param longitude query number true "Longitude to search for"
// @Param plantingDate query string true "Plant date, ISO8601 or RFC3339 format"
// @Router /gdd/confidence [get]
// @Router /gdd/confidence [get]
func
GetConfidenceInterval
(
c
*
fiber
.
Ctx
)
error
{
func
GetConfidenceInterval
(
c
*
fiber
.
Ctx
)
error
{
r
:=
models
.
ConfidenceIntervalRequest
{}
.
Build
(
c
)
r
:=
models
.
ConfidenceIntervalRequest
{}
.
Build
(
c
)
...
...
This diff is collapsed.
Click to expand it.
models/confidence_interval.go
+
25
−
10
View file @
f9f22f88
package
models
package
models
import
(
import
(
"
errors
"
"
fmt
"
"strconv"
"strconv"
"time"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/config"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/config"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/models/enums"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/models/enums"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence/entities"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence/entities"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/utils"
validation
"github.com/go-ozzo/ozzo-validation"
validation
"github.com/go-ozzo/ozzo-validation"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2"
"github.com/tgs266/dawn-go-common/errors"
)
)
type
ConfidenceIntervalRequest
struct
{
type
ConfidenceIntervalRequest
struct
{
Product
enums
.
Product
`json:"product"`
Product
enums
.
Product
`json:"product"`
Latitude
float64
`json:"latitude"`
Latitude
float64
`json:"latitude"`
Longitude
float64
`json:"longitude"`
Longitude
float64
`json:"longitude"`
Interval
float64
`json:"interval"`
Interval
float64
`json:"interval"`
PlantingDate
time
.
Time
`json:"plantingDate"`
}
}
type
ConfidenceIntervalResposne
struct
{
type
ConfidenceIntervalResposne
struct
{
...
@@ -50,7 +54,7 @@ func validateInterval(value interface{}) error {
...
@@ -50,7 +54,7 @@ func validateInterval(value interface{}) error {
return
nil
return
nil
}
}
}
}
return
errors
.
New
(
"Interval not in allowed intervals"
)
return
fmt
.
Errorf
(
"Interval not in allowed intervals"
)
}
}
func
(
r
ConfidenceIntervalRequest
)
Validate
()
error
{
func
(
r
ConfidenceIntervalRequest
)
Validate
()
error
{
...
@@ -67,12 +71,23 @@ func (r ConfidenceIntervalRequest) Build(c *fiber.Ctx) ConfidenceIntervalRequest
...
@@ -67,12 +71,23 @@ func (r ConfidenceIntervalRequest) Build(c *fiber.Ctx) ConfidenceIntervalRequest
latitude
,
_
:=
strconv
.
ParseFloat
(
c
.
Query
(
"latitude"
,
"-100000.0"
),
64
)
latitude
,
_
:=
strconv
.
ParseFloat
(
c
.
Query
(
"latitude"
,
"-100000.0"
),
64
)
longitude
,
_
:=
strconv
.
ParseFloat
(
c
.
Query
(
"longitude"
,
"-100000.0"
),
64
)
longitude
,
_
:=
strconv
.
ParseFloat
(
c
.
Query
(
"longitude"
,
"-100000.0"
),
64
)
interval
,
_
:=
strconv
.
ParseFloat
(
c
.
Query
(
"interval"
,
"-100000.0"
),
64
)
interval
,
_
:=
strconv
.
ParseFloat
(
c
.
Query
(
"interval"
,
"-100000.0"
),
64
)
pd
:=
c
.
Query
(
"plantingDate"
,
utils
.
GetFirstOfTheYear
()
.
Format
(
time
.
RFC3339
))
plantingDate
,
errDate
:=
time
.
Parse
(
time
.
RFC3339
,
pd
)
if
errDate
!=
nil
{
panic
(
errors
.
NewBadRequest
(
nil
)
.
PutDetail
(
"reason"
,
"no planting date provided"
))
}
if
errDate
!=
nil
&&
pd
!=
""
{
panic
(
errors
.
NewBadRequest
(
nil
)
.
PutDetail
(
"reason"
,
"date must be ISO8601 or RFC3339 format"
))
}
rNew
:=
ConfidenceIntervalRequest
{
rNew
:=
ConfidenceIntervalRequest
{
Product
:
enums
.
GetProductFromString
(
product
),
Product
:
enums
.
GetProductFromString
(
product
),
Latitude
:
latitude
,
Latitude
:
latitude
,
Longitude
:
longitude
,
Longitude
:
longitude
,
Interval
:
interval
,
Interval
:
interval
,
PlantingDate
:
plantingDate
,
}
}
if
rNew
.
Validate
()
!=
nil
{
if
rNew
.
Validate
()
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
services/confidence_interval_service.go
+
10
−
2
View file @
f9f22f88
...
@@ -17,12 +17,20 @@ func GetConfidenceInterval(request models.ConfidenceIntervalRequest) models.Conf
...
@@ -17,12 +17,20 @@ func GetConfidenceInterval(request models.ConfidenceIntervalRequest) models.Conf
var
lowerBound
[]
float64
var
lowerBound
[]
float64
var
upperBound
[]
float64
var
upperBound
[]
float64
// get the int of the planting date. If the date is less than the first date, we do nothing
// otherwise, we adjust
// need to do before because of accumulations
sliceDateInt
:=
request
.
PlantingDate
.
YearDay
()
-
1
if
sliceDateInt
<
0
{
sliceDateInt
=
0
}
rows
:=
[][]
float64
{}
rows
:=
[][]
float64
{}
for
i
:=
0
;
i
<
len
(
gs
[
0
]
.
MinTemps
);
i
++
{
for
i
:=
sliceDateInt
;
i
<
len
(
gs
[
0
]
.
MinTemps
);
i
++
{
row
:=
[]
float64
{}
row
:=
[]
float64
{}
for
j
:=
0
;
j
<
len
(
gs
);
j
++
{
for
j
:=
0
;
j
<
len
(
gs
);
j
++
{
row
=
append
(
row
,
utils
.
CalculateSingleGdd
(
gs
[
j
]
.
MinTemps
[
i
],
gs
[
j
]
.
MaxTemps
[
i
],
product
))
row
=
append
(
row
,
utils
.
CalculateSingleGdd
(
gs
[
j
]
.
MinTemps
[
i
],
gs
[
j
]
.
MaxTemps
[
i
],
product
))
if
i
>
0
{
if
i
>
sliceDateInt
{
row
[
j
]
+=
rows
[
len
(
rows
)
-
1
][
j
]
row
[
j
]
+=
rows
[
len
(
rows
)
-
1
][
j
]
}
}
}
}
...
...
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