Merge pull request #2717 from nasa/dave/conditions-telemetry

[Conditions] Use latest incoming telemetry timestamp for providing telemetry
This commit is contained in:
Joel McKinnon 2020-03-04 12:05:33 -08:00 committed by GitHub
commit 95f855f905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 14 deletions

View File

@ -191,14 +191,12 @@ export default class ConditionClass extends EventEmitter {
handleCriterionResult(eventData) { handleCriterionResult(eventData) {
const id = eventData.id; const id = eventData.id;
const conditionData = eventData.data;
if (this.findCriterion(id)) { if (this.findCriterion(id)) {
this.criteriaResults[id] = eventData.data.result; this.criteriaResults[id] = eventData.data.result;
} }
conditionData.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL); this.handleConditionUpdated(eventData.data);
this.emitEvent('conditionResultUpdated', conditionData);
} }
subscribe() { subscribe() {
@ -208,6 +206,14 @@ export default class ConditionClass extends EventEmitter {
}) })
} }
handleConditionUpdated(datum) {
// trigger an updated event so that consumers can react accordingly
this.evaluate();
this.emitEvent('conditionResultUpdated',
Object.assign({}, datum, { result: this.result })
);
}
getCriteria() { getCriteria() {
return this.criteria; return this.criteria;
} }
@ -221,6 +227,10 @@ export default class ConditionClass extends EventEmitter {
return success; return success;
} }
evaluate() {
this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
}
emitEvent(eventName, data) { emitEvent(eventName, data) {
this.emit(eventName, { this.emit(eventName, {
id: this.id, id: this.id,

View File

@ -29,6 +29,8 @@ export default class ConditionManager extends EventEmitter {
super(); super();
this.domainObject = domainObject; this.domainObject = domainObject;
this.openmct = openmct; this.openmct = openmct;
this.timeAPI = this.openmct.time;
this.latestTimestamp = {};
this.instantiate = this.openmct.$injector.get('instantiate'); this.instantiate = this.openmct.$injector.get('instantiate');
this.initialize(); this.initialize();
} }
@ -213,6 +215,7 @@ export default class ConditionManager extends EventEmitter {
if (this.findConditionById(idAsString)) { if (this.findConditionById(idAsString)) {
this.conditionResults[idAsString] = resultObj.data.result; this.conditionResults[idAsString] = resultObj.data.result;
} }
this.updateTimestamp(resultObj.data);
} }
for (let i = 0; i < conditionCollection.length - 1; i++) { for (let i = 0; i < conditionCollection.length - 1; i++) {
@ -226,15 +229,25 @@ export default class ConditionManager extends EventEmitter {
this.openmct.objects.get(currentConditionIdentifier).then((obj) => { this.openmct.objects.get(currentConditionIdentifier).then((obj) => {
this.emit('conditionSetResultUpdated', this.emit('conditionSetResultUpdated',
Object.assign({}, Object.assign(
resultObj ? resultObj.data : {},
{ {
output: obj.configuration.output, output: obj.configuration.output,
id: this.domainObject.identifier, id: this.domainObject.identifier,
conditionId: currentConditionIdentifier conditionId: currentConditionIdentifier
},
this.latestTimestamp
)
)
});
}
updateTimestamp(timestamp) {
this.timeAPI.getAllTimeSystems().forEach(timeSystem => {
if (!this.latestTimestamp[timeSystem.key]
|| timestamp[timeSystem.key] > this.latestTimestamp[timeSystem.key]
) {
this.latestTimestamp[timeSystem.key] = timestamp[timeSystem.key];
} }
)
)
}); });
} }

View File

@ -56,12 +56,14 @@ export default class TelemetryCriterion extends EventEmitter {
} }
handleSubscription(data) { handleSubscription(data) {
const datum = {}; const datum = {
const timeSystemKey = this.timeAPI.timeSystem().key; result: this.computeResult(data)
};
datum.result = this.computeResult(data); if (data) {
if (data && data[timeSystemKey]) { // TODO check back to see if we should format times here
datum[timeSystemKey] = data[timeSystemKey] this.timeAPI.getAllTimeSystems().forEach(timeSystem => {
datum[timeSystem.key] = data[timeSystem.key]
});
} }
this.emitEvent('criterionResultUpdated', datum); this.emitEvent('criterionResultUpdated', datum);

View File

@ -63,10 +63,11 @@ describe("The telemetry criterion", function () {
openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values); openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values);
openmct.time = jasmine.createSpyObj('timeAPI', openmct.time = jasmine.createSpyObj('timeAPI',
['timeSystem', 'bounds'] ['timeSystem', 'bounds', 'getAllTimeSystems']
); );
openmct.time.timeSystem.and.returnValue({key: 'system'}); openmct.time.timeSystem.and.returnValue({key: 'system'});
openmct.time.bounds.and.returnValue({start: 0, end: 1}); openmct.time.bounds.and.returnValue({start: 0, end: 1});
openmct.time.getAllTimeSystems.and.returnValue([{key: 'system'}]);
testCriterionDefinition = { testCriterionDefinition = {
id: 'test-criterion-id', id: 'test-criterion-id',