Documentation ¶
Overview ¶
Package modepb contains utilities for working with traits.ElectricMode values.
Index ¶
- func ActiveAt(t time.Time, mode *traits.ElectricMode) (elapsed time.Duration, index int)
- func Cut(t time.Time, mode *traits.ElectricMode) (before, after *traits.ElectricMode, outside bool)
- func MagnitudeAt(t time.Time, mode *traits.ElectricMode) (level float32, ok bool)
- func MaxSegmentAfter(t time.Time, mode *traits.ElectricMode) (index int)
- func MinAt(t time.Time, modes map[string]*traits.ElectricMode) (mode *traits.ElectricMode, magnitude float32)
- func Shift(d time.Duration, mode *traits.ElectricMode) *traits.ElectricMode
- func Sum(modes ...*traits.ElectricMode) *traits.ElectricMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActiveAt ¶
ActiveAt finds the modes active segment at time t. The index of the active segment in mode is returned along with the elapsed time before that segment started. If mode.Segments is empty, (0,0) is returned. If t is before mode starts, index will be 0 and elapsed will be negative, indicating how far before mode.StartTime t is. If t is after all segments, the total length of the segments is returned as elapsed, and len(mode.Segments) as index. If mode.StartTime is nil, t will be used as the start time, i.e. (0, 0) will be returned.
func Cut ¶
func Cut(t time.Time, mode *traits.ElectricMode) (before, after *traits.ElectricMode, outside bool)
Cut cuts the given mode around the time t. If mode has no start time then start time is assumed to be t, implying (nil, mode, false) is returned. The returned value outside indicates whether t is outside the bounds of mode.
func MagnitudeAt ¶
MagnitudeAt returns the magnitude of the mode at t. If there is no segment at t, ok will be false. If mode does not have a StartTime, returns the magnitude of the first segment.
func MaxSegmentAfter ¶
func MaxSegmentAfter(t time.Time, mode *traits.ElectricMode) (index int)
MaxSegmentAfter returns the index in mode.Segments of the segment with the largest magnitude after the given time. If mode.StartTime is nil, this function is equivalent to segmentpb.Max(mode.Segments), i.e. mode.StartTime == t.
func MinAt ¶
func MinAt(t time.Time, modes map[string]*traits.ElectricMode) (mode *traits.ElectricMode, magnitude float32)
MinAt returns the mode with the smalled magnitude at the given time, and that magnitude. The returned mode will be nil if modes is empty. If a mode exists without a segment at time t, it's magnitude is treated as 0 and is a candidate to be returned.
func Shift ¶
func Shift(d time.Duration, mode *traits.ElectricMode) *traits.ElectricMode
Shift adjusts the given mode until it's start time is offset by d. Where a start time exists, this simply changes the start time of the mode by d. If no start time exists, this is equivalent to calling segmentpb.Shift on the mode segments.
If d is not 0, a new mode instance will be returned.
func Sum ¶
func Sum(modes ...*traits.ElectricMode) *traits.ElectricMode
Sum combines all the given modes together into a single mode. The magnitudes of each modes segment are added together to produce a new segment array. No metadata will be set on the returned mode: id, description, etc. Voltage will be ignored and unset in the response.
Regarding start times ¶
If no modes have a start time, we assume all segments are relative to the same time and will combine them as such. If only one mode has a start time, we follow the rules above but also set the start time of the returned mode to this. Any mode without a start time is assumed to start at the most recent start time of the modes that do. The returned mode will have a start time equal to the earliest start time of the given modes, if one exists.
Types ¶
This section is empty.