Commit dc30b9d3 by carl bergquist

feat(elastic): change concept to trim edges instead.

parent 37cfe2a3
...@@ -96,8 +96,13 @@ function (angular, _, queryDef) { ...@@ -96,8 +96,13 @@ function (angular, _, queryDef) {
$scope.agg.field = $scope.target.timeField; $scope.agg.field = $scope.target.timeField;
settingsLinkText = 'Interval: ' + settings.interval; settingsLinkText = 'Interval: ' + settings.interval;
settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count; settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count;
if (settings.dropFirstLast) {
settingsLinkText += ', Drop first & last value'; if (settings.trimEdges === undefined || settings.trimEdges < 0) {
settings.trimEdges = 0;
}
if (settings.trimEdges && settings.trimEdges > 0) {
settingsLinkText += ', Trim edges: ' + settings.trimEdges;
} }
} }
} }
......
...@@ -269,15 +269,16 @@ function (_, queryDef) { ...@@ -269,15 +269,16 @@ function (_, queryDef) {
seriesList.push(series); seriesList.push(series);
}; };
ElasticResponse.prototype.dropFirstLast = function(aggregations, target) { ElasticResponse.prototype.trimDatapoints = function(aggregations, target) {
var histogram = _.findWhere(target.bucketAggs, { type: 'date_histogram'}); var histogram = _.findWhere(target.bucketAggs, { type: 'date_histogram'});
var shouldDropFirstAndLast = histogram && histogram.settings && histogram.settings.dropFirstLast; var shouldDropFirstAndLast = histogram && histogram.settings && histogram.settings.trimEdges;
if (shouldDropFirstAndLast) { if (shouldDropFirstAndLast) {
var trim = histogram.settings.trimEdges;
for(var prop in aggregations) { for(var prop in aggregations) {
var points = aggregations[prop]; var points = aggregations[prop];
if (points.datapoints.length > 2) { if (points.datapoints.length > trim * 2) {
points.datapoints = points.datapoints.slice(1, points.datapoints.length-1); points.datapoints = points.datapoints.slice(trim, points.datapoints.length - trim);
} }
} }
} }
...@@ -303,7 +304,7 @@ function (_, queryDef) { ...@@ -303,7 +304,7 @@ function (_, queryDef) {
var docs = []; var docs = [];
this.processBuckets(aggregations, target, tmpSeriesList, docs, {}, 0); this.processBuckets(aggregations, target, tmpSeriesList, docs, {}, 0);
this.dropFirstLast(tmpSeriesList, target); this.trimDatapoints(tmpSeriesList, target);
this.nameSeries(tmpSeriesList, target); this.nameSeries(tmpSeriesList, target);
for (var y = 0; y < tmpSeriesList.length; y++) { for (var y = 0; y < tmpSeriesList.length; y++) {
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<div class="tight-form-inner-box" ng-if="agg.type === 'date_histogram'"> <div class="tight-form-inner-box" ng-if="agg.type === 'date_histogram'">
<div class="tight-form"> <div class="tight-form">
<ul class="tight-form-list"> <ul class="tight-form-list">
<li class="tight-form-item" style="width: 140px"> <li class="tight-form-item" style="width: 170px">
Interval Interval
</li> </li>
<li> <li>
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
</div> </div>
<div class="tight-form"> <div class="tight-form">
<ul class="tight-form-list"> <ul class="tight-form-list">
<li class="tight-form-item" style="width: 140px"> <li class="tight-form-item" style="width: 170px">
Min Doc Count Min Doc Count
</li> </li>
<li> <li>
...@@ -59,16 +59,14 @@ ...@@ -59,16 +59,14 @@
</div> </div>
<div class="tight-form last"> <div class="tight-form last">
<ul class="tight-form-list"> <ul class="tight-form-list">
<li class="tight-form-item" style="width: 140px"> <li class="tight-form-item" style="width: 170px">
Drop first &amp; last value Trim edges on timeserie
</li> </li>
<li class="tight-form-item"> <li>
<input class="cr1" type="checkbox" id="{{$id}}.dropFirstLast" <input class="tight-form-input" type="number" ng-model="agg.settings.trimEdges" ng-change="onChangeInternal()">
ng-model="agg.settings.dropFirstLast" ng-checked="agg.settings.dropFirstLast" ng-change="onChangeInternal()">
<label for="{{$id}}.dropFirstLast" class="cr1"></label>
</li> </li>
<li class="tight-form-item last"> <li class="tight-form-item last">
<i class="fa fa-question-circle" bs-tooltip="'Ignore the first and last values of the dataset'" data-placement="right"></i> <i class="fa fa-question-circle" bs-tooltip="'Trim the edges on the timeserie x datapoints'" data-placement="right"></i>
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
......
...@@ -416,7 +416,7 @@ describe('ElasticResponse', function() { ...@@ -416,7 +416,7 @@ describe('ElasticResponse', function() {
targets = [{ targets = [{
refId: 'A', refId: 'A',
metrics: [{ type: 'avg', id: '1' }, { type: 'count' }], metrics: [{ type: 'avg', id: '1' }, { type: 'count' }],
bucketAggs: [{ id: '2', type: 'date_histogram', field: 'host', settings: { dropFirstLast: true} }], bucketAggs: [{ id: '2', type: 'date_histogram', field: 'host', settings: { trimEdges: 1} }],
}]; }];
response = { response = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment