Implement sortSeries

This commit is contained in:
Alexander Zobnin
2021-05-27 12:57:09 +03:00
parent 67289c91f7
commit 24e9129fbe
3 changed files with 41 additions and 10 deletions

View File

@@ -64,8 +64,9 @@ func init() {
}
filterFuncMap = map[string]AggDataProcessingFunc{
"top": applyTop,
"bottom": applyBottom,
"top": applyTop,
"bottom": applyBottom,
"sortSeries": applySortSeries,
}
// Functions processing on the frontend
@@ -244,6 +245,17 @@ func applyBottom(series []*timeseries.TimeSeriesData, params ...interface{}) ([]
return filteredSeries, nil
}
func applySortSeries(series []*timeseries.TimeSeriesData, params ...interface{}) ([]*timeseries.TimeSeriesData, error) {
order, err := MustString(params[0])
if err != nil {
return nil, errParsingFunctionParam(err)
}
aggFunc := timeseries.AggAvg
sorted := timeseries.SortBy(series, order, aggFunc)
return sorted, nil
}
func getAggFunc(agg string) timeseries.AggFunc {
switch agg {
case "avg":
@@ -266,3 +278,9 @@ func getAggFunc(agg string) timeseries.AggFunc {
return timeseries.AggAvg
}
}
func sortSeriesPoints(series []*timeseries.TimeSeriesData) {
for _, s := range series {
s.TS.Sort()
}
}

View File

@@ -74,7 +74,6 @@ func (ds *ZabbixDatasourceInstance) queryNumericDataForItems(ctx context.Context
}
series := convertHistoryToTimeSeries(history, items)
// TODO: handle time series functions
series, err = applyFunctions(series, query.Functions)
if err != nil {
return nil, err