mirror of
https://github.com/nasa/openmct.git
synced 2025-02-01 00:45:41 +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) {
|
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,
|
||||||
|
@ -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,18 +229,28 @@ 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];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
persist() {
|
persist() {
|
||||||
this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.domainObject.configuration.conditionCollection);
|
this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.domainObject.configuration.conditionCollection);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user