Commit dc30b9d3 by carl bergquist

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

parent 37cfe2a3
......@@ -96,8 +96,13 @@ function (angular, _, queryDef) {
$scope.agg.field = $scope.target.timeField;
settingsLinkText = 'Interval: ' + settings.interval;
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) {
seriesList.push(series);
};
ElasticResponse.prototype.dropFirstLast = function(aggregations, target) {
ElasticResponse.prototype.trimDatapoints = function(aggregations, target) {
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) {
var trim = histogram.settings.trimEdges;
for(var prop in aggregations) {
var points = aggregations[prop];
if (points.datapoints.length > 2) {
points.datapoints = points.datapoints.slice(1, points.datapoints.length-1);
if (points.datapoints.length > trim * 2) {
points.datapoints = points.datapoints.slice(trim, points.datapoints.length - trim);
}
}
}
......@@ -303,7 +304,7 @@ function (_, queryDef) {
var docs = [];
this.processBuckets(aggregations, target, tmpSeriesList, docs, {}, 0);
this.dropFirstLast(tmpSeriesList, target);
this.trimDatapoints(tmpSeriesList, target);
this.nameSeries(tmpSeriesList, target);
for (var y = 0; y < tmpSeriesList.length; y++) {
......
......@@ -37,7 +37,7 @@
<div class="tight-form-inner-box" ng-if="agg.type === 'date_histogram'">
<div class="tight-form">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 140px">
<li class="tight-form-item" style="width: 170px">
Interval
</li>
<li>
......@@ -48,7 +48,7 @@
</div>
<div class="tight-form">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 140px">
<li class="tight-form-item" style="width: 170px">
Min Doc Count
</li>
<li>
......@@ -59,16 +59,14 @@
</div>
<div class="tight-form last">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 140px">
Drop first &amp; last value
<li class="tight-form-item" style="width: 170px">
Trim edges on timeserie
</li>
<li class="tight-form-item">
<input class="cr1" type="checkbox" id="{{$id}}.dropFirstLast"
ng-model="agg.settings.dropFirstLast" ng-checked="agg.settings.dropFirstLast" ng-change="onChangeInternal()">
<label for="{{$id}}.dropFirstLast" class="cr1"></label>
<li>
<input class="tight-form-input" type="number" ng-model="agg.settings.trimEdges" ng-change="onChangeInternal()">
</li>
<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>
</ul>
<div class="clearfix"></div>
......
......@@ -416,7 +416,7 @@ describe('ElasticResponse', function() {
targets = [{
refId: 'A',
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 = {
......
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