feat: move stuff to numerics
This commit is contained in:
parent
465ad00f7b
commit
b7fd7046ff
5 changed files with 119 additions and 29 deletions
|
|
@ -241,25 +241,31 @@ func buildPiecewise(spec ModelSpec, deps BuildDeps) (BuiltModel, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// resolveSegments converts spec segments to engine.RateSegment using the
|
||||
// stage context to resolve relative references.
|
||||
// resolveSegments converts spec segments to engine.RateSegment, turning each
|
||||
// segment's reference-relative Until into an absolute UNIX time. References
|
||||
// are validated by buildPiecewise, so an unrecognised one here is treated as
|
||||
// absolute rather than re-erroring.
|
||||
func resolveSegments(in []PiecewiseSegmentSpec, ctx StageContext) []RateSegment {
|
||||
out := make([]RateSegment, 0, len(in))
|
||||
for _, s := range in {
|
||||
var until float64
|
||||
switch s.Reference {
|
||||
case "", "absolute":
|
||||
until = s.Until
|
||||
case "profile_start":
|
||||
until = ctx.ProfileStart + s.Until
|
||||
case "propagator_start":
|
||||
until = ctx.PropagatorStart + s.Until
|
||||
}
|
||||
out = append(out, RateSegment{Until: until, Rate: s.Rate})
|
||||
out = append(out, RateSegment{Until: segmentBase(s.Reference, ctx) + s.Until, Rate: s.Rate})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// segmentBase returns the absolute time a piecewise segment's Until is
|
||||
// measured from, per its reference.
|
||||
func segmentBase(reference string, ctx StageContext) float64 {
|
||||
switch reference {
|
||||
case "profile_start":
|
||||
return ctx.ProfileStart
|
||||
case "propagator_start":
|
||||
return ctx.PropagatorStart
|
||||
default: // "", "absolute"
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// maybeAddWind sums a WindTransport model into base when the spec asks for it.
|
||||
func maybeAddWind(base Model, includeWind bool, deps BuildDeps) Model {
|
||||
if !includeWind {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue