2015-09-05 21:41:04 +08:00
|
|
|
define([
|
|
|
|
'lodash'
|
|
|
|
],
|
|
|
|
function (_) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
return {
|
|
|
|
metricAggTypes: [
|
2015-11-05 15:36:51 +08:00
|
|
|
{text: "Count", value: 'count', requiresField: false},
|
2015-12-12 01:20:53 +08:00
|
|
|
{text: "Average", value: 'avg', requiresField: true, supportsInlineScript: true, supportsMissing: true},
|
|
|
|
{text: "Sum", value: 'sum', requiresField: true, supportsInlineScript: true, supportsMissing: true},
|
|
|
|
{text: "Max", value: 'max', requiresField: true, supportsInlineScript: true, supportsMissing: true},
|
|
|
|
{text: "Min", value: 'min', requiresField: true, supportsInlineScript: true, supportsMissing: true},
|
|
|
|
{text: "Extended Stats", value: 'extended_stats', requiresField: true, supportsMissing: true, supportsInlineScript: true},
|
|
|
|
{text: "Percentiles", value: 'percentiles', requiresField: true, supportsMissing: true, supportsInlineScript: true},
|
|
|
|
{text: "Unique Count", value: "cardinality", requiresField: true, supportsMissing: true},
|
2015-12-11 19:41:40 +08:00
|
|
|
{text: "Moving Average", value: 'moving_avg', requiresField: false, isPipelineAgg: true },
|
|
|
|
{text: "Derivative", value: 'derivative', requiresField: false, isPipelineAgg: true },
|
2015-11-05 15:36:51 +08:00
|
|
|
{text: "Raw Document", value: "raw_document", requiresField: false}
|
2015-09-05 21:41:04 +08:00
|
|
|
],
|
|
|
|
|
|
|
|
bucketAggTypes: [
|
|
|
|
{text: "Terms", value: 'terms' },
|
2015-09-22 01:23:18 +08:00
|
|
|
{text: "Filters", value: 'filters' },
|
2015-09-05 21:41:04 +08:00
|
|
|
{text: "Date Histogram", value: 'date_histogram' },
|
|
|
|
],
|
|
|
|
|
|
|
|
orderByOptions: [
|
|
|
|
{text: "Doc Count", value: '_count' },
|
|
|
|
{text: "Term value", value: '_term' },
|
|
|
|
],
|
|
|
|
|
|
|
|
orderOptions: [
|
|
|
|
{text: "Top", value: 'desc' },
|
|
|
|
{text: "Bottom", value: 'asc' },
|
|
|
|
],
|
|
|
|
|
|
|
|
sizeOptions: [
|
|
|
|
{text: "No limit", value: '0' },
|
|
|
|
{text: "1", value: '1' },
|
|
|
|
{text: "2", value: '2' },
|
2015-10-05 17:17:37 +08:00
|
|
|
{text: "3", value: '3' },
|
2015-09-05 21:41:04 +08:00
|
|
|
{text: "5", value: '5' },
|
|
|
|
{text: "10", value: '10' },
|
|
|
|
{text: "15", value: '15' },
|
|
|
|
{text: "20", value: '20' },
|
|
|
|
],
|
|
|
|
|
2015-09-07 19:13:19 +08:00
|
|
|
extendedStats: [
|
|
|
|
{text: 'Avg', value: 'avg'},
|
|
|
|
{text: 'Min', value: 'min'},
|
|
|
|
{text: 'Max', value: 'max'},
|
|
|
|
{text: 'Sum', value: 'sum'},
|
|
|
|
{text: 'Count', value: 'count'},
|
|
|
|
{text: 'Std Dev', value: 'std_deviation'},
|
|
|
|
{text: 'Std Dev Upper', value: 'std_deviation_bounds_upper'},
|
|
|
|
{text: 'Std Dev Lower', value: 'std_deviation_bounds_lower'},
|
|
|
|
],
|
|
|
|
|
2015-09-07 22:35:40 +08:00
|
|
|
intervalOptions: [
|
|
|
|
{text: 'auto', value: 'auto'},
|
|
|
|
{text: '10s', value: '10s'},
|
|
|
|
{text: '1m', value: '1m'},
|
|
|
|
{text: '5m', value: '5m'},
|
|
|
|
{text: '10m', value: '10m'},
|
|
|
|
{text: '20m', value: '20m'},
|
|
|
|
{text: '1h', value: '1h'},
|
|
|
|
{text: '1d', value: '1d'},
|
|
|
|
],
|
|
|
|
|
2015-12-11 00:03:46 +08:00
|
|
|
pipelineOptions: {
|
|
|
|
'moving_avg' : [
|
2015-12-11 16:19:05 +08:00
|
|
|
{text: 'window', default: 5},
|
|
|
|
{text: 'model', default: 'simple'}
|
2015-12-11 00:03:46 +08:00
|
|
|
],
|
2015-12-10 20:34:49 +08:00
|
|
|
'derivative': []
|
|
|
|
},
|
|
|
|
|
2015-12-11 00:03:46 +08:00
|
|
|
getPipelineOptions: function(metric) {
|
2015-12-11 00:42:31 +08:00
|
|
|
if (!this.isPipelineAgg(metric.type)) {
|
2015-12-10 20:34:49 +08:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2015-12-11 00:03:46 +08:00
|
|
|
return this.pipelineOptions[metric.type];
|
2015-12-10 20:34:49 +08:00
|
|
|
},
|
|
|
|
|
2015-12-11 00:42:31 +08:00
|
|
|
isPipelineAgg: function(metricType) {
|
|
|
|
if (metricType) {
|
|
|
|
var po = this.pipelineOptions[metricType];
|
2015-12-11 00:03:46 +08:00
|
|
|
return po !== null && po !== undefined;
|
2015-12-09 23:25:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-12-11 00:12:52 +08:00
|
|
|
getPipelineAggOptions: function(targets) {
|
2015-12-09 15:31:01 +08:00
|
|
|
var self = this;
|
|
|
|
var result = [];
|
|
|
|
_.each(targets.metrics, function(metric) {
|
2015-12-11 00:42:31 +08:00
|
|
|
if (!self.isPipelineAgg(metric.type)) {
|
2015-12-09 15:31:01 +08:00
|
|
|
result.push({text: self.describeMetric(metric), value: metric.id });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2015-09-05 21:41:04 +08:00
|
|
|
getOrderByOptions: function(target) {
|
|
|
|
var self = this;
|
|
|
|
var metricRefs = [];
|
|
|
|
_.each(target.metrics, function(metric) {
|
|
|
|
if (metric.type !== 'count') {
|
|
|
|
metricRefs.push({text: self.describeMetric(metric), value: metric.id});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return this.orderByOptions.concat(metricRefs);
|
|
|
|
},
|
|
|
|
|
|
|
|
describeOrder: function(order) {
|
|
|
|
var def = _.findWhere(this.orderOptions, {value: order});
|
|
|
|
return def.text;
|
|
|
|
},
|
|
|
|
|
|
|
|
describeMetric: function(metric) {
|
|
|
|
var def = _.findWhere(this.metricAggTypes, {value: metric.type});
|
|
|
|
return def.text + ' ' + metric.field;
|
|
|
|
},
|
|
|
|
|
|
|
|
describeOrderBy: function(orderBy, target) {
|
|
|
|
var def = _.findWhere(this.orderByOptions, {value: orderBy});
|
|
|
|
if (def) {
|
|
|
|
return def.text;
|
|
|
|
}
|
|
|
|
var metric = _.findWhere(target.metrics, {id: orderBy});
|
|
|
|
if (metric) {
|
|
|
|
return this.describeMetric(metric);
|
|
|
|
} else {
|
|
|
|
return "metric not found";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|