Resolved #201 - add scale() function.
This commit is contained in:
@@ -142,6 +142,15 @@ export default class DataProcessor {
|
||||
return timeseries;
|
||||
}
|
||||
|
||||
static scale(factor, datapoints) {
|
||||
return _.map(datapoints, point => {
|
||||
return [
|
||||
point[0] * factor,
|
||||
point[1]
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
static groupByWrapper(interval, groupFunc, datapoints) {
|
||||
var groupByCallback = DataProcessor.aggregationFunctions[groupFunc];
|
||||
return DataProcessor.groupBy(interval, groupByCallback, datapoints);
|
||||
@@ -171,6 +180,7 @@ export default class DataProcessor {
|
||||
static get metricFunctions() {
|
||||
return {
|
||||
groupBy: this.groupByWrapper,
|
||||
scale: this.scale,
|
||||
aggregateBy: this.aggregateByWrapper,
|
||||
average: _.partial(this.aggregateWrapper, this.AVERAGE),
|
||||
min: _.partial(this.aggregateWrapper, this.MIN),
|
||||
|
||||
@@ -176,10 +176,10 @@ export class ZabbixAPIDatasource {
|
||||
// Apply transformation functions
|
||||
timeseries_data = _.map(timeseries_data, timeseries => {
|
||||
|
||||
// Filter only transform functions
|
||||
// Filter only transformation functions
|
||||
var transformFunctions = bindFunctionDefs(target.functions, 'Transform', DataProcessor);
|
||||
|
||||
// Metric data processing
|
||||
// Timeseries processing
|
||||
var dp = timeseries.datapoints;
|
||||
for (var i = 0; i < transformFunctions.length; i++) {
|
||||
dp = transformFunctions[i](dp);
|
||||
|
||||
@@ -102,7 +102,8 @@ angular
|
||||
$input.attr('data-provide', 'typeahead');
|
||||
|
||||
var options = funcDef.params[paramIndex].options;
|
||||
if (funcDef.params[paramIndex].type === 'int') {
|
||||
if (funcDef.params[paramIndex].type === 'int' ||
|
||||
funcDef.params[paramIndex].type === 'float') {
|
||||
options = _.map(options, function(val) { return val.toString(); });
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,15 @@ addFuncDef({
|
||||
defaultParams: ['1m', 'avg'],
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'scale',
|
||||
category: 'Transform',
|
||||
params: [
|
||||
{ name: 'factor', type: 'float', options: [100, 0.01, 10, -1]}
|
||||
],
|
||||
defaultParams: [100],
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'sumSeries',
|
||||
category: 'Aggregate',
|
||||
@@ -126,8 +135,16 @@ class FuncInstance {
|
||||
|
||||
// Bind function arguments
|
||||
var bindedFunc = func;
|
||||
var param;
|
||||
for (var i = 0; i < this.params.length; i++) {
|
||||
bindedFunc = _.partial(bindedFunc, this.params[i]);
|
||||
param = this.params[i];
|
||||
|
||||
// Convert numeric params
|
||||
if (this.def.params[i].type === 'int' ||
|
||||
this.def.params[i].type === 'float') {
|
||||
param = Number(param);
|
||||
}
|
||||
bindedFunc = _.partial(bindedFunc, param);
|
||||
}
|
||||
return bindedFunc;
|
||||
} else {
|
||||
@@ -140,7 +157,10 @@ class FuncInstance {
|
||||
var parameters = _.map(this.params, function(value, index) {
|
||||
|
||||
var paramType = this.def.params[index].type;
|
||||
if (paramType === 'int' || paramType === 'value_or_series' || paramType === 'boolean') {
|
||||
if (paramType === 'int' ||
|
||||
paramType === 'float' ||
|
||||
paramType === 'value_or_series' ||
|
||||
paramType === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
else if (paramType === 'int_or_interval' && $.isNumeric(value)) {
|
||||
|
||||
Reference in New Issue
Block a user