mirror of
https://github.com/nasa/openmct.git
synced 2025-01-20 03:36:44 +00:00
Merge pull request #2717 from nasa/dave/conditions-telemetry
[Conditions] Use latest incoming telemetry timestamp for providing telemetry
This commit is contained in:
commit
95f855f905
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user