move target extraction logic to query def

This commit is contained in:
carl bergquist 2015-12-09 08:31:01 +01:00
parent dd7a13930f
commit b4763290de
2 changed files with 61 additions and 1 deletions

View File

@ -13,7 +13,7 @@ function (_) {
{text: "Min", value: 'min', requiresField: true},
{text: "Extended Stats", value: 'extended_stats', requiresField: true},
{text: "Percentiles", value: 'percentiles', requiresField: true},
{text: "Moving Avg", value: 'moving_avg', requiresField: true, requiresBucketsPath: true},
{text: "Moving Avg", value: 'moving_avg', requiresField: false, requiresBucketsPath: true},
{text: "Unique Count", value: "cardinality", requiresField: true},
{text: "Raw Document", value: "raw_document", requiresField: false}
],
@ -67,6 +67,18 @@ function (_) {
{text: '1d', value: '1d'},
],
getMovingAverageSourceOptions: function(targets) {
var self = this;
var result = [];
_.each(targets.metrics, function(metric) {
if (metric.type !== 'moving_avg') {
result.push({text: self.describeMetric(metric), value: metric.id });
}
});
return result;
},
getOrderByOptions: function(target) {
var self = this;
var metricRefs = [];

View File

@ -0,0 +1,48 @@
///<amd-dependency path="../query_def" name="QueryDef" />
///<amd-dependency path="test/specs/helpers" name="helpers" />
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
declare var helpers: any;
declare var QueryDef: any;
describe('ElasticQueryDef', function() {
describe('with zero targets', function() {
var response = QueryDef.getMovingAverageSourceOptions([]);
it('should return zero', function() {
expect(response.length).to.be(0);
});
});
describe('with count and sum targets', function() {
var targets = {
metrics: [
{ type: 'count', field: '@value' },
{ type: 'sum', field: '@value' }
]
};
var response = QueryDef.getMovingAverageSourceOptions(targets);
it('should return zero', function() {
expect(response.length).to.be(2);
});
});
describe('with count and moving average targets', function() {
var targets = {
metrics: [
{ type: 'count', field: '@value' },
{ type: 'moving_avg', field: '@value' }
]
};
var response = QueryDef.getMovingAverageSourceOptions(targets);
it('should return zero', function() {
expect(response.length).to.be(1);
});
});
});