Fix percentile aggregation with $__range_series interval
This commit is contained in:
@@ -307,6 +307,13 @@ func applyPercentileAgg(series []*timeseries.TimeSeriesData, params ...interface
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
}
|
||||
aggFunc := timeseries.AggPercentile(percentile)
|
||||
|
||||
if pInterval == RANGE_VARIABLE_VALUE {
|
||||
aggregatedSeries := timeseries.AggregateByRange(series, aggFunc)
|
||||
aggregatedSeries.Meta.Name = fmt.Sprintf("percentileAgg(%s, %v)", pInterval, percentile)
|
||||
return []*timeseries.TimeSeriesData{aggregatedSeries}, nil
|
||||
}
|
||||
|
||||
interval, err := gtime.ParseInterval(pInterval)
|
||||
if err != nil {
|
||||
@@ -316,7 +323,6 @@ func applyPercentileAgg(series []*timeseries.TimeSeriesData, params ...interface
|
||||
return series, nil
|
||||
}
|
||||
|
||||
aggFunc := timeseries.AggPercentile(percentile)
|
||||
aggregatedSeries := timeseries.AggregateBy(series, interval, aggFunc)
|
||||
aggregatedSeries.Meta.Name = fmt.Sprintf("percentileAgg(%s, %v)", pInterval, percentile)
|
||||
|
||||
|
||||
@@ -166,6 +166,24 @@ func AggregateBy(series []*TimeSeriesData, interval time.Duration, aggFunc AggFu
|
||||
return aggregatedSeriesData
|
||||
}
|
||||
|
||||
func AggregateByRange(series []*TimeSeriesData, aggFunc AggFunc) *TimeSeriesData {
|
||||
aggregatedSeries := NewTimeSeries()
|
||||
|
||||
// Combine all points into one time series
|
||||
for _, s := range series {
|
||||
aggregatedSeries = append(aggregatedSeries, s.TS...)
|
||||
}
|
||||
|
||||
value := aggFunc(aggregatedSeries)
|
||||
aggregatedSeriesData := NewTimeSeriesData()
|
||||
aggregatedSeriesData.TS = []TimePoint{
|
||||
{Time: aggregatedSeries[0].Time, Value: value},
|
||||
{Time: aggregatedSeries[aggregatedSeries.Len()-1].Time, Value: value},
|
||||
}
|
||||
|
||||
return aggregatedSeriesData
|
||||
}
|
||||
|
||||
func (ts TimeSeries) Sort() {
|
||||
sorted := sort.SliceIsSorted(ts, ts.less())
|
||||
if !sorted {
|
||||
|
||||
Reference in New Issue
Block a user