47 lines
1.4 KiB
Go
Executable File
47 lines
1.4 KiB
Go
Executable File
package common
|
|
|
|
import (
|
|
"time"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
|
)
|
|
|
|
func GetPlannerNearestStart(start time.Time, planned map[tools.DataType]map[string]pricing.PricedItemITF, request *tools.APIRequest) float64 {
|
|
near := float64(-1) // unset sentinel
|
|
for _, items := range planned { // loop through the planned items
|
|
for _, priced := range items { // loop through the priced items
|
|
if priced.GetLocationStart() == nil { // if the start is nil,
|
|
continue // skip the iteration
|
|
}
|
|
newS := priced.GetLocationStart() // get the start
|
|
diff := newS.Sub(start).Seconds() // get the difference
|
|
if near < 0 || diff < near { // if the difference is less than the nearest start
|
|
near = diff
|
|
}
|
|
}
|
|
}
|
|
if near < 0 {
|
|
return 0 // no items found, start at the given start time
|
|
}
|
|
return near
|
|
}
|
|
|
|
func GetPlannerLongestTime(end *time.Time, planned map[tools.DataType]map[string]pricing.PricedItemITF, request *tools.APIRequest) float64 {
|
|
if end == nil {
|
|
return -1
|
|
}
|
|
longestTime := float64(0)
|
|
for _, priced := range planned[tools.PROCESSING_RESOURCE] {
|
|
if priced.GetLocationEnd() == nil {
|
|
continue
|
|
}
|
|
newS := priced.GetLocationEnd()
|
|
if end == nil && longestTime < newS.Sub(*end).Seconds() {
|
|
longestTime = newS.Sub(*end).Seconds()
|
|
}
|
|
// get the nearest start from start var
|
|
}
|
|
return longestTime
|
|
}
|