Files
oc-lib/models/common/planner.go

45 lines
1.3 KiB
Go
Raw Normal View History

2025-01-15 10:56:44 +01:00
package common
import (
"time"
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
"cloud.o-forge.io/core/oc-lib/tools"
)
2026-03-20 14:20:26 +01:00
func GetPlannerNearestStart(start time.Time, planned map[tools.DataType]map[string]pricing.PricedItemITF) float64 {
2026-03-20 15:21:48 +01:00
near := float64(-1) // unset sentinel
2025-01-15 10:56:44 +01:00
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
}
2026-03-20 15:21:48 +01:00
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
2026-03-16 15:59:19 +01:00
near = diff
2025-01-15 10:56:44 +01:00
}
}
}
2026-03-16 15:59:19 +01:00
if near < 0 {
return 0 // no items found, start at the given start time
}
2025-01-15 10:56:44 +01:00
return near
}
2026-04-27 11:16:50 +02:00
// GetPlannerLongestTime returns the sum of all processing+service durations.
// Returns -1 if any item is open-ended (no deadline).
2026-03-20 15:09:52 +01:00
func GetPlannerLongestTime(planned map[tools.DataType]map[string]pricing.PricedItemITF) float64 {
2025-01-15 10:56:44 +01:00
longestTime := float64(0)
2026-04-27 11:16:50 +02:00
for _, dt := range []tools.DataType{tools.PROCESSING_RESOURCE, tools.SERVICE_RESOURCE} {
for _, priced := range planned[dt] {
d := priced.GetExplicitDurationInS()
if d < 0 {
return -1
}
longestTime += d
2026-03-20 16:14:07 +01:00
}
2025-01-15 10:56:44 +01:00
}
return longestTime
}