Skip to content

Commit c394fe9

Browse files
author
Pete Richards
committed
Merge remote-tracking branch 'origin/open1465'
2 parents a2bf92d + 06f4a95 commit c394fe9

File tree

5 files changed

+128
-38
lines changed

5 files changed

+128
-38
lines changed

platform/features/table/src/TelemetryCollection.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,6 @@ define(
112112
this.lastBounds = bounds;
113113
};
114114

115-
/**
116-
* Determines is a given telemetry datum is within the bounds currently
117-
* defined for this telemetry collection.
118-
* @private
119-
* @param datum
120-
* @returns {boolean}
121-
*/
122-
TelemetryCollection.prototype.inBounds = function (datum) {
123-
var noBoundsDefined = !this.lastBounds || (this.lastBounds.start === undefined && this.lastBounds.end === undefined);
124-
var withinBounds =
125-
_.get(datum, this.sortField) >= this.lastBounds.start &&
126-
_.get(datum, this.sortField) <= this.lastBounds.end;
127-
128-
return noBoundsDefined || withinBounds;
129-
};
130-
131115
/**
132116
* Adds an individual item to the collection. Used internally only
133117
* @private
@@ -173,9 +157,10 @@ define(
173157
// based on time stamp because the array is guaranteed ordered due
174158
// to sorted insertion.
175159
var startIx = _.sortedIndex(array, item, this.sortField);
160+
var endIx;
176161

177162
if (startIx !== array.length) {
178-
var endIx = _.sortedLastIndex(array, item, this.sortField);
163+
endIx = _.sortedLastIndex(array, item, this.sortField);
179164

180165
// Create an array of potential dupes, based on having the
181166
// same time stamp
@@ -185,7 +170,7 @@ define(
185170
}
186171

187172
if (!isDuplicate) {
188-
array.splice(startIx, 0, item);
173+
array.splice(endIx || startIx, 0, item);
189174

190175
//Return true if it was added and in bounds
191176
return array === this.telemetry;

platform/features/table/src/controllers/MCTTableController.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,38 @@ define(
425425
}
426426
};
427427

428+
/**
429+
* Finds the correct insertion point for a new row, which takes into
430+
* account duplicates to make sure new rows are inserted in a way that
431+
* maintains arrival order.
432+
*
433+
* @private
434+
* @param {Array} searchArray
435+
* @param {Object} searchElement Object to find the insertion point for
436+
*/
437+
MCTTableController.prototype.findInsertionPoint = function (searchArray, searchElement) {
438+
//First, use a binary search to find the correct insertion point
439+
var index = this.binarySearch(searchArray, searchElement, 0, searchArray.length - 1);
440+
var testIndex = index;
441+
442+
//It's possible that the insertion point is a duplicate of the element to be inserted
443+
var isDupe = function () {
444+
return this.sortComparator(searchElement,
445+
searchArray[testIndex][this.$scope.sortColumn].text) === 0;
446+
}.bind(this);
447+
448+
// In the event of a duplicate, scan left or right (depending on
449+
// sort order) to find an insertion point that maintains order received
450+
while (testIndex >= 0 && testIndex < searchArray.length && isDupe()) {
451+
if (this.$scope.sortDirection === 'asc') {
452+
index = ++testIndex;
453+
} else {
454+
index = testIndex--;
455+
}
456+
}
457+
return index;
458+
};
459+
428460
/**
429461
* @private
430462
*/
@@ -439,9 +471,9 @@ define(
439471
case -1:
440472
return this.binarySearch(searchArray, searchElement, min,
441473
sampleAt - 1);
442-
case 0 :
474+
case 0:
443475
return sampleAt;
444-
case 1 :
476+
case 1:
445477
return this.binarySearch(searchArray, searchElement,
446478
sampleAt + 1, max);
447479
}
@@ -458,7 +490,7 @@ define(
458490
index = array.length;
459491
} else {
460492
//Sort is enabled, perform binary search to find insertion point
461-
index = this.binarySearch(array, element[this.$scope.sortColumn].text, 0, array.length - 1);
493+
index = this.findInsertionPoint(array, element[this.$scope.sortColumn].text);
462494
}
463495
if (index === -1) {
464496
array.unshift(element);

platform/features/table/src/controllers/TelemetryTableController.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,8 @@ define(
364364
var telemetryApi = this.openmct.telemetry;
365365
var telemetryCollection = this.telemetry;
366366
//Set table max length to avoid unbounded growth.
367-
//var maxRows = 100000;
368-
var maxRows = Number.MAX_VALUE;
369367
var limitEvaluator;
370368
var added = false;
371-
var scope = this.$scope;
372369
var table = this.table;
373370

374371
this.subscriptions.forEach(function (subscription) {
@@ -379,16 +376,6 @@ define(
379376
function newData(domainObject, datum) {
380377
limitEvaluator = telemetryApi.limitEvaluator(domainObject);
381378
added = telemetryCollection.add([table.getRowValues(limitEvaluator, datum)]);
382-
383-
//Inform table that a new row has been added
384-
if (scope.rows.length > maxRows) {
385-
scope.$broadcast('remove:rows', scope.rows[0]);
386-
scope.rows.shift();
387-
}
388-
if (!scope.loading && added) {
389-
scope.$broadcast('add:row',
390-
scope.rows.length - 1);
391-
}
392379
}
393380

394381
objects.forEach(function (object) {

platform/features/table/test/TelemetryCollectionSpec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ define(
138138
};
139139
collection.add([addedObjectB, addedObjectA]);
140140

141+
expect(collection.telemetry[11]).toBe(addedObjectB);
142+
}
143+
);
144+
it("maintains insertion order in the case of duplicate time stamps",
145+
function () {
146+
var addedObjectA = {
147+
timestamp: 10000,
148+
value: {
149+
integer: 10,
150+
text: integerTextMap[10]
151+
}
152+
};
153+
var addedObjectB = {
154+
timestamp: 10000,
155+
value: {
156+
integer: 11,
157+
text: integerTextMap[11]
158+
}
159+
};
160+
collection.add([addedObjectA, addedObjectB]);
161+
141162
expect(collection.telemetry[11]).toBe(addedObjectB);
142163
}
143164
);

platform/features/table/test/controllers/MCTTableControllerSpec.js

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,14 @@ define(
459459

460460
beforeEach(function () {
461461
row4 = {
462-
'col1': {'text': 'row5 col1'},
462+
'col1': {'text': 'row4 col1'},
463463
'col2': {'text': 'xyz'},
464-
'col3': {'text': 'row5 col3'}
464+
'col3': {'text': 'row4 col3'}
465465
};
466466
row5 = {
467-
'col1': {'text': 'row6 col1'},
467+
'col1': {'text': 'row5 col1'},
468468
'col2': {'text': 'aaa'},
469-
'col3': {'text': 'row6 col3'}
469+
'col3': {'text': 'row5 col3'}
470470
};
471471
row6 = {
472472
'col1': {'text': 'row6 col1'},
@@ -490,6 +490,71 @@ define(
490490
expect(mockScope.displayRows[3].col2.text).toEqual('ggg');
491491
});
492492

493+
it('Inserts duplicate values for sort column in order received when sorted descending', function () {
494+
mockScope.sortColumn = 'col2';
495+
mockScope.sortDirection = 'desc';
496+
497+
mockScope.displayRows = controller.sortRows(testRows.slice(0));
498+
499+
var row6b = {
500+
'col1': {'text': 'row6b col1'},
501+
'col2': {'text': 'ggg'},
502+
'col3': {'text': 'row6b col3'}
503+
};
504+
var row6c = {
505+
'col1': {'text': 'row6c col1'},
506+
'col2': {'text': 'ggg'},
507+
'col3': {'text': 'row6c col3'}
508+
};
509+
510+
controller.addRows(undefined, [row4, row5]);
511+
controller.addRows(undefined, [row6, row6b, row6c]);
512+
expect(mockScope.displayRows[0].col2.text).toEqual('xyz');
513+
expect(mockScope.displayRows[7].col2.text).toEqual('aaa');
514+
515+
// Added duplicate rows
516+
expect(mockScope.displayRows[2].col2.text).toEqual('ggg');
517+
expect(mockScope.displayRows[3].col2.text).toEqual('ggg');
518+
expect(mockScope.displayRows[4].col2.text).toEqual('ggg');
519+
520+
// Check that original order is maintained with dupes
521+
expect(mockScope.displayRows[2].col3.text).toEqual('row6c col3');
522+
expect(mockScope.displayRows[3].col3.text).toEqual('row6b col3');
523+
expect(mockScope.displayRows[4].col3.text).toEqual('row6 col3');
524+
});
525+
526+
it('Inserts duplicate values for sort column in order received when sorted ascending', function () {
527+
mockScope.sortColumn = 'col2';
528+
mockScope.sortDirection = 'asc';
529+
530+
mockScope.displayRows = controller.sortRows(testRows.slice(0));
531+
532+
var row6b = {
533+
'col1': {'text': 'row6b col1'},
534+
'col2': {'text': 'ggg'},
535+
'col3': {'text': 'row6b col3'}
536+
};
537+
var row6c = {
538+
'col1': {'text': 'row6c col1'},
539+
'col2': {'text': 'ggg'},
540+
'col3': {'text': 'row6c col3'}
541+
};
542+
543+
controller.addRows(undefined, [row4, row5, row6]);
544+
controller.addRows(undefined, [row6b, row6c]);
545+
expect(mockScope.displayRows[0].col2.text).toEqual('aaa');
546+
expect(mockScope.displayRows[7].col2.text).toEqual('xyz');
547+
548+
// Added duplicate rows
549+
expect(mockScope.displayRows[3].col2.text).toEqual('ggg');
550+
expect(mockScope.displayRows[4].col2.text).toEqual('ggg');
551+
expect(mockScope.displayRows[5].col2.text).toEqual('ggg');
552+
// Check that original order is maintained with dupes
553+
expect(mockScope.displayRows[3].col3.text).toEqual('row6 col3');
554+
expect(mockScope.displayRows[4].col3.text).toEqual('row6b col3');
555+
expect(mockScope.displayRows[5].col3.text).toEqual('row6c col3');
556+
});
557+
493558
it('Adds new rows at the correct sort position when' +
494559
' sorted and filtered', function () {
495560
mockScope.sortColumn = 'col2';

0 commit comments

Comments
 (0)