Skip to content

Commit

Permalink
Merge branch 'zero-filled-ts'
Browse files Browse the repository at this point in the history
Conflicts:
	js/services.js
  • Loading branch information
Spencer Alger committed Aug 22, 2013
2 parents 13d3da0 + c8638e0 commit 69ab6bb
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 75 deletions.
75 changes: 0 additions & 75 deletions js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,79 +868,4 @@ angular.module('kibana.services', [])
return false;
});
};
})
.service('timeSeries', function () {
/**
* Certain graphs require 0 entries to be specified for them to render
* properly (like the line graph). So with this we will caluclate all of
* the expected time measurements, and fill the missing ones in with 0
* @param date start The start time for the result set
* @param date end The end time for the result set
* @param integer interval The length between measurements, in es interval
* notation (1m, 30s, 1h, 15d)
*/
var undef;
function dateToSecondsWithBlankMs(date) {
// return the date as millis since epoch, with 0 millis
return Math.floor(date.getTime() / 1000)*1000;
}
function base10Int(val) {
return parseInt(val, 10);
}
this.ZeroFilled = function (interval, start, end) {
// the expected differenece between readings.
this.interval_ms = parseInt(kbn.interval_to_seconds(interval), 10) * 1000;
// will keep all values here, keyed by their time
this._data = {};

if (start) {
this.addValue(start, null);
}
if (end) {
this.addValue(end, null);
}
}
/**
* Add a row
* @param int time The time for the value, in
* @param any value The value at this time
*/
this.ZeroFilled.prototype.addValue = function (time, value) {
if (time instanceof Date) {
time = dateToSecondsWithBlankMs(time);
} else {
time = parseInt(time, 10);
}
if (!isNaN(time)) {
this._data[time] = (value === undef ? 0 : value);
}
};
/**
* return the rows in the format:
* [ [time, value], [time, value], ... ]
* @return array
*/
this.ZeroFilled.prototype.getFlotPairs = function () {
// var startTime = performance.now();
var times = _.map(_.keys(this._data), base10Int).sort()
, result = []
, i
, next
, expected_next;
for(i = 0; i < times.length; i++) {
result.push([ times[i], this._data[times[i]] ]);
next = times[i + 1];
expected_next = times[i] + this.interval_ms;
for(; times.length > i && next > expected_next; expected_next+= this.interval_ms) {
/**
* since we don't know how the server will round subsequent segments
* we have to recheck for blanks each time.
*/
// this._data[expected_next] = 0;
result.push([expected_next, 0]);
}
}
// console.log(Math.round((performance.now() - startTime)*100)/100, 'ms to get', result.length, 'pairs');
return result;
};
});
71 changes: 71 additions & 0 deletions panels/histogram/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,75 @@ angular.module('kibana.histogram', [])
});
}
};
})
.service('timeSeries', function () {
/**
* Certain graphs require 0 entries to be specified for them to render
* properly (like the line graph). So with this we will caluclate all of
* the expected time measurements, and fill the missing ones in with 0
* @param date start The start time for the result set
* @param date end The end time for the result set
* @param integer interval The length between measurements, in es interval
* notation (1m, 30s, 1h, 15d)
*/
var undef;
function base10Int(val) {
return parseInt(val, 10);
}
this.ZeroFilled = function (interval, start, end) {
// the expected differenece between readings.
this.interval_ms = base10Int(kbn.interval_to_seconds(interval)) * 1000;
// will keep all values here, keyed by their time
this._data = {};

if (start) {
this.addValue(start, null);
}
if (end) {
this.addValue(end, null);
}
}
/**
* Add a row
* @param int time The time for the value, in
* @param any value The value at this time
*/
this.ZeroFilled.prototype.addValue = function (time, value) {
if (time instanceof Date) {
time = Math.floor(time.getTime() / 1000)*1000;
} else {
time = base10Int(time);
}
if (!isNaN(time)) {
this._data[time] = (value === undef ? 0 : value);
}
};
/**
* return the rows in the format:
* [ [time, value], [time, value], ... ]
* @return array
*/
this.ZeroFilled.prototype.getFlotPairs = function () {
// var startTime = performance.now();
var times = _.map(_.keys(this._data), base10Int).sort()
, result = []
, i
, next
, expected_next;
for(i = 0; i < times.length; i++) {
result.push([ times[i], this._data[times[i]] ]);
next = times[i + 1];
expected_next = times[i] + this.interval_ms;
for(; times.length > i && next > expected_next; expected_next+= this.interval_ms) {
/**
* since we don't know how the server will round subsequent segments
* we have to recheck for blanks each time.
*/
// this._data[expected_next] = 0;
result.push([expected_next, 0]);
}
}
// console.log(Math.round((performance.now() - startTime)*100)/100, 'ms to get', result.length, 'pairs');
return result;
};
});

1 comment on commit 69ab6bb

@olej-a
Copy link

@olej-a olej-a commented on 69ab6bb Aug 23, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not OK. If I use bars, it not looks good. Do you really need add zeroes for each interval in timeframe?

Check olej-a@63be4e7

How looks bar histogram after added zeroes to each interval>
graph-2

Please sign in to comment.