Implement removeAboveValue/removeBelowValue
This commit is contained in:
@@ -60,6 +60,8 @@ func init() {
|
|||||||
"groupBy": applyGroupBy,
|
"groupBy": applyGroupBy,
|
||||||
"scale": applyScale,
|
"scale": applyScale,
|
||||||
"offset": applyOffset,
|
"offset": applyOffset,
|
||||||
|
"removeAboveValue": applyRemoveAboveValue,
|
||||||
|
"removeBelowValue": applyRemoveBelowValue,
|
||||||
"transformNull": applyTransformNull,
|
"transformNull": applyTransformNull,
|
||||||
"percentile": applyPercentile,
|
"percentile": applyPercentile,
|
||||||
"timeShift": applyTimeShiftPost,
|
"timeShift": applyTimeShiftPost,
|
||||||
@@ -203,6 +205,26 @@ func applyOffset(series timeseries.TimeSeries, params ...interface{}) (timeserie
|
|||||||
return series.Transform(transformFunc), nil
|
return series.Transform(transformFunc), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyRemoveAboveValue(series timeseries.TimeSeries, params ...interface{}) (timeseries.TimeSeries, error) {
|
||||||
|
threshold, err := MustFloat64(params[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, errParsingFunctionParam(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
transformFunc := timeseries.TransformRemoveAboveValue(threshold)
|
||||||
|
return series.Transform(transformFunc), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyRemoveBelowValue(series timeseries.TimeSeries, params ...interface{}) (timeseries.TimeSeries, error) {
|
||||||
|
threshold, err := MustFloat64(params[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, errParsingFunctionParam(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
transformFunc := timeseries.TransformRemoveBelowValue(threshold)
|
||||||
|
return series.Transform(transformFunc), nil
|
||||||
|
}
|
||||||
|
|
||||||
func applyTransformNull(series timeseries.TimeSeries, params ...interface{}) (timeseries.TimeSeries, error) {
|
func applyTransformNull(series timeseries.TimeSeries, params ...interface{}) (timeseries.TimeSeries, error) {
|
||||||
nullValue, err := MustFloat64(params[0])
|
nullValue, err := MustFloat64(params[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,53 +4,55 @@ import "time"
|
|||||||
|
|
||||||
func TransformScale(factor float64) TransformFunc {
|
func TransformScale(factor float64) TransformFunc {
|
||||||
return func(point TimePoint) TimePoint {
|
return func(point TimePoint) TimePoint {
|
||||||
return transformScale(point, factor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TransformOffset(offset float64) TransformFunc {
|
|
||||||
return func(point TimePoint) TimePoint {
|
|
||||||
return transformOffset(point, offset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TransformNull(nullValue float64) TransformFunc {
|
|
||||||
return func(point TimePoint) TimePoint {
|
|
||||||
return transformNull(point, nullValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TransformShiftTime(interval time.Duration) TransformFunc {
|
|
||||||
return func(point TimePoint) TimePoint {
|
|
||||||
return transformShiftTime(point, interval)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func transformScale(point TimePoint, factor float64) TimePoint {
|
|
||||||
if point.Value != nil {
|
if point.Value != nil {
|
||||||
newValue := *point.Value * factor
|
newValue := *point.Value * factor
|
||||||
point.Value = &newValue
|
point.Value = &newValue
|
||||||
}
|
}
|
||||||
return point
|
return point
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func transformOffset(point TimePoint, offset float64) TimePoint {
|
func TransformOffset(offset float64) TransformFunc {
|
||||||
|
return func(point TimePoint) TimePoint {
|
||||||
if point.Value != nil {
|
if point.Value != nil {
|
||||||
newValue := *point.Value + offset
|
newValue := *point.Value + offset
|
||||||
point.Value = &newValue
|
point.Value = &newValue
|
||||||
}
|
}
|
||||||
return point
|
return point
|
||||||
}
|
}
|
||||||
|
|
||||||
func transformShiftTime(point TimePoint, interval time.Duration) TimePoint {
|
|
||||||
shiftedTime := point.Time.Add(interval)
|
|
||||||
point.Time = shiftedTime
|
|
||||||
return point
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func transformNull(point TimePoint, nullValue float64) TimePoint {
|
func TransformNull(nullValue float64) TransformFunc {
|
||||||
|
return func(point TimePoint) TimePoint {
|
||||||
if point.Value == nil {
|
if point.Value == nil {
|
||||||
point.Value = &nullValue
|
point.Value = &nullValue
|
||||||
}
|
}
|
||||||
return point
|
return point
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TransformRemoveAboveValue(threshold float64) TransformFunc {
|
||||||
|
return func(point TimePoint) TimePoint {
|
||||||
|
if *point.Value > threshold {
|
||||||
|
point.Value = nil
|
||||||
|
}
|
||||||
|
return point
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TransformRemoveBelowValue(threshold float64) TransformFunc {
|
||||||
|
return func(point TimePoint) TimePoint {
|
||||||
|
if *point.Value < threshold {
|
||||||
|
point.Value = nil
|
||||||
|
}
|
||||||
|
return point
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TransformShiftTime(interval time.Duration) TransformFunc {
|
||||||
|
return func(point TimePoint) TimePoint {
|
||||||
|
shiftedTime := point.Time.Add(interval)
|
||||||
|
point.Time = shiftedTime
|
||||||
|
return point
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user