[Tables] Increase default table size

This commit is contained in:
Henry 2017-01-19 21:18:53 -08:00
parent 0c3ff82cfe
commit ae2b73a4f5
2 changed files with 67 additions and 39 deletions

View File

@ -21,44 +21,72 @@
*****************************************************************************/ *****************************************************************************/
define( define(
['lodash'], [
function (_) { 'lodash',
'eventEmitter'
],
function (_, eventEmitter) {
function TelemetryCollection() { function TelemetryCollection() {
eventEmitter.call(this, arguments);
this.telemetry = []; this.telemetry = [];
this.forwardBuffer = [];
this.sortField = undefined; this.sortField = undefined;
this.lastBounds = {}; this.lastBounds = {};
this.lastStartIndex = 0;
this.lastEndIndex = 0;
_.bindAll(this,[ _.bindAll(this,[
'iteratee' 'iteratee'
]); ]);
} }
TelemetryCollection.prototype = Object.create(eventEmitter.prototype);
TelemetryCollection.prototype.iteratee = function (element) { TelemetryCollection.prototype.iteratee = function (element) {
return _.get(element, this.sortField); return _.get(element, this.sortField);
}; };
TelemetryCollection.prototype.bounds = function (bounds) { /**
* This function is optimized for ticking - it assumes that start and end bounds
* will only increase and as such this cannot be used for decreasing bounds changes.
* For arbitrary bounds changes, it's assumed that a telemetry requery is performed anyway, and the
* collection is cleared and repopulated.
* @param bounds
*/
TelemetryCollection.prototype.tick = function (bounds) {
var startChanged = this.lastBounds.start !== bounds.start; var startChanged = this.lastBounds.start !== bounds.start;
var endChanged = this.lastBounds.end !== bounds.end; var endChanged = this.lastBounds.end !== bounds.end;
var fromStart = 0; var startIndex = 0;
var fromEnd = 0; var endIndex = 0;
var discarded = []; var discarded = undefined;
var added = undefined;
if (startChanged){ if (startChanged){
var testValue = _.set({}, this.sortField, bounds.start); var testValue = _.set({}, this.sortField, bounds.start);
fromStart = _.sortedIndex(this.telemetry, testValue, this.sortField); // Calculate the new index of the first element within the bounds
discarded = this.telemetry.splice(0, fromStart); startIndex = _.sortedIndex(this.telemetry, testValue, this.sortField);
discarded = this.telemetry.slice(this.lastStartIndex, startIndex + 1);
} }
if (endChanged) { if (endChanged) {
var testValue = _.set({}, this.sortField, bounds.end); var testValue = _.set({}, this.sortField, bounds.end);
fromEnd = _.sortedLastIndex(this.telemetry, testValue, this.sortField); // Calculate the new index of the last element in bounds
discarded = discarded.concat(this.telemetry.splice(fromEnd, this.telemetry.length - fromEnd)); endIndex = _.sortedLastIndex(this.telemetry, testValue, this.sortField);
added = this.telemetry.slice(this.lastEndIndex, endIndex + 1);
}
if (discarded.length > 0){
this.emit('discarded', discarded);
}
if (added.length > 0){
this.emit('added', added);
} }
this.lastBounds = bounds; this.lastBounds = bounds;
return discarded;
}; };
TelemetryCollection.prototype.isValid = function (element) { /*collection.on('added');
collection.on('discarded');*/
TelemetryCollection.prototype.inBounds = function (element) {
var noBoundsDefined = !this.lastBounds || (!this.lastBounds.start && !this.lastBounds.end); var noBoundsDefined = !this.lastBounds || (!this.lastBounds.start && !this.lastBounds.end);
var withinBounds = _.get(element, this.sortField) >= this.lastBounds.start && var withinBounds = _.get(element, this.sortField) >= this.lastBounds.start &&
_.get(element, this.sortField) <= this.lastBounds.end; _.get(element, this.sortField) <= this.lastBounds.end;
@ -66,37 +94,37 @@ define(
return noBoundsDefined || withinBounds; return noBoundsDefined || withinBounds;
}; };
//Todo: addAll for initial historical data
TelemetryCollection.prototype.add = function (element) { TelemetryCollection.prototype.add = function (element) {
//console.log('data: ' + element.Time.value); // Going to check for duplicates. Bound the search problem to
if (this.isValid(element)){ // elements around the given time. Use sortedIndex because it
// Going to check for duplicates. Bound the search problem to // employs a binary search which is O(log n). Can use binary search
// elements around the given time. Use sortedIndex because it // based on time stamp because the array is guaranteed ordered due
// employs a binary search which is O(log n). Can use binary search // to sorted insertion.
// based on time stamp because the array is guaranteed ordered due
// to sorted insertion.
var isDuplicate = false; var isDuplicate = false;
var startIx = _.sortedIndex(this.telemetry, element, this.sortField); var startIx = _.sortedIndex(this.telemetry, element, this.sortField);
if (startIx !== this.telemetry.length) { if (startIx !== this.telemetry.length) {
var endIx = _.sortedLastIndex(this.telemetry, element, this.sortField); var endIx = _.sortedLastIndex(this.telemetry, element, this.sortField);
// Create an array of potential dupes, based on having the // Create an array of potential dupes, based on having the
// same time stamp // same time stamp
var potentialDupes = this.telemetry.slice(startIx, endIx + 1); var potentialDupes = this.telemetry.slice(startIx, endIx + 1);
// Search potential dupes for exact dupe // Search potential dupes for exact dupe
isDuplicate = _.findIndex(potentialDupes, _.isEqual.bind(undefined, element)) > -1; isDuplicate = _.findIndex(potentialDupes, _.isEqual.bind(undefined, element)) > -1;
}
if (!isDuplicate) {
this.telemetry.splice(startIx, 0, element);
if (this.inBounds(element)) {
// If new element is within bounds, then the index within the
// master of the last element in bounds has just increased by one.
this.lastEndIndex++;
//If the new element is within bounds, add it immediately
this.emit('added', [element]);
} }
if (!isDuplicate) {
this.telemetry.splice(startIx, 0, element);
return true;
} else {
return false;
}
} else {
return false;
} }
}; };

View File

@ -18,7 +18,7 @@ define(
this.$scope = $scope; this.$scope = $scope;
this.element = $(element[0]); this.element = $(element[0]);
this.$window = $window; this.$window = $window;
this.maxDisplayRows = 50; this.maxDisplayRows = 100;
this.scrollable = this.element.find('.l-view-section.scrolling').first(); this.scrollable = this.element.find('.l-view-section.scrolling').first();
this.resultsHeader = this.element.find('.mct-table>thead').first(); this.resultsHeader = this.element.find('.mct-table>thead').first();