Skip to content
Snippets Groups Projects
Commit 3c822540 authored by Tucker Gary Siegel's avatar Tucker Gary Siegel
Browse files

update

parent 8584ad42
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@ require (
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0
github.com/swaggo/swag v1.7.1
github.com/tgs266/dawn-go-common v0.0.0-20220926200401-63ec7d7119a0
github.com/tgs266/dawn-go-common v0.0.0-20221004165044-41b33c8b0598
go.mongodb.org/mongo-driver v1.7.3
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 // indirect
......
......@@ -608,6 +608,8 @@ github.com/tgs266/dawn-go-common v0.0.0-20220926193741-599d4be5ecec h1:jvkc3mNjV
github.com/tgs266/dawn-go-common v0.0.0-20220926193741-599d4be5ecec/go.mod h1:XUnuQ0jNkFoFhUY/835EMgZWvPx/ZJUhn3VOds9y3Fg=
github.com/tgs266/dawn-go-common v0.0.0-20220926200401-63ec7d7119a0 h1:omtLZNoFqJf8p5IorD6MMDpG8qwCDtjVEkXdXCu2zj0=
github.com/tgs266/dawn-go-common v0.0.0-20220926200401-63ec7d7119a0/go.mod h1:XUnuQ0jNkFoFhUY/835EMgZWvPx/ZJUhn3VOds9y3Fg=
github.com/tgs266/dawn-go-common v0.0.0-20221004165044-41b33c8b0598 h1:lHi3/3mME+COppqH7Txv5TQyYiyDfqVjMpahr2/IsrU=
github.com/tgs266/dawn-go-common v0.0.0-20221004165044-41b33c8b0598/go.mod h1:XUnuQ0jNkFoFhUY/835EMgZWvPx/ZJUhn3VOds9y3Fg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
......
package services
import (
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/models"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/utils"
"gonum.org/v1/gonum/stat"
)
func GetConfidenceInterval(request models.ConfidenceIntervalRequest) models.ConfidenceIntervalResposne {
gs := persistence.GetLastNormalsYearly(request.BuildLocation())
product := request.Product
// zScore := models.IntervalConvert[request.Interval]
// zScore := models.IntervalConvertPercentiles[request.Interval]
var lowerBound []float64
var upperBound []float64
rows := [][]float64{}
for i := 0; i < len(gs[0].MinTemps); i++ {
row := []float64{}
for j := 0; j < len(gs); j++ {
row = append(row, utils.CalculateSingleGdd(gs[j].MinTemps[i], gs[j].MaxTemps[i], product))
if i > 0 {
row[j] += rows[len(rows)-1][j]
}
}
rows = append(rows, row)
mean, std := stat.MeanStdDev(row, nil)
moe := std * 1.645
// moe := std / math.Pow(30, 0.5) * zScore
upperBound = append(upperBound, utils.ClipMinFloat(mean+moe, 0))
lowerBound = append(lowerBound, utils.ClipMinFloat(mean-moe, 0))
}
return models.ConfidenceIntervalResposne{
LowerBound: lowerBound,
UpperBound: upperBound,
ClosestLatitude: gs[0].Location.Coordinates[1],
ClosestLongitude: gs[0].Location.Coordinates[0],
}
}
package services
import (
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/models"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/persistence"
"gitlab.cs.umd.edu/dawn/go-backend/dawn-gdd/utils"
"gonum.org/v1/gonum/stat"
)
func GetConfidenceInterval(request models.ConfidenceIntervalRequest) models.ConfidenceIntervalResposne {
gs := persistence.GetLastNormalsYearly(request.BuildLocation())
product := request.Product
// zScore := models.IntervalConvert[request.Interval]
// zScore := models.IntervalConvertPercentiles[request.Interval]
var lowerBound []float64
var upperBound []float64
rows := [][]float64{}
for i := 0; i < len(gs[0].MinTemps); i++ {
row := []float64{}
for j := 0; j < len(gs); j++ {
row = append(row, utils.CalculateSingleGdd(gs[j].MinTemps[i], gs[j].MaxTemps[i], product))
if i > 0 {
row[j] += rows[len(rows)-1][j]
}
}
rows = append(rows, row)
mean, std := stat.MeanStdDev(row, nil)
moe := std * 1.645
// moe := std / math.Pow(30, 0.5) * zScore
upperBound = append(upperBound, utils.ClipMinFloat(mean+moe, 0))
lowerBound = append(lowerBound, utils.ClipMinFloat(mean-moe, 0))
}
return models.ConfidenceIntervalResposne{
LowerBound: lowerBound,
UpperBound: upperBound,
ClosestLatitude: gs[0].Location.Coordinates[1],
ClosestLongitude: gs[0].Location.Coordinates[0],
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment