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) {
const id = eventData.id;
const conditionData = eventData.data;
if (this.findCriterion(id)) {
this.criteriaResults[id] = eventData.data.result;
}
conditionData.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
this.emitEvent('conditionResultUpdated', conditionData);
this.handleConditionUpdated(eventData.data);
}
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() {
return this.criteria;
}
@ -221,6 +227,10 @@ export default class ConditionClass extends EventEmitter {
return success;
}
evaluate() {
this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
}
emitEvent(eventName, data) {
this.emit(eventName, {
id: this.id,

View File

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

View File

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

View File

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