provide telemetry with timestamps

This commit is contained in:
David Tsay 2020-02-28 11:15:19 -08:00
parent 583f4dac85
commit 89ae6ef8c7
4 changed files with 32 additions and 35 deletions

View File

@ -58,7 +58,7 @@ export default class ConditionClass extends EventEmitter {
this.id = this.openmct.objects.makeKeyString(conditionConfiguration.identifier);
this.criteria = [];
this.criteriaResults = {};
this.result = null;
this.result = undefined;
if (conditionConfiguration.configuration.criteria) {
this.createCriteria(conditionConfiguration.configuration.criteria);
}
@ -163,6 +163,7 @@ export default class ConditionClass extends EventEmitter {
if (found) {
let criterion = found.item;
criterion.destroy();
// TODO this is passing the wrong args
criterion.off('criterionUpdated', (result) => {
this.handleCriterionUpdated(id, result);
});
@ -180,6 +181,7 @@ export default class ConditionClass extends EventEmitter {
if (found) {
this.criteria[found.index] = criterion.data;
this.subscribe();
// TODO nothing is listening to this
this.emitEvent('conditionUpdated', {
trigger: this.trigger,
criteria: this.criteria
@ -189,26 +191,22 @@ export default class ConditionClass extends EventEmitter {
handleCriterionResult(eventData) {
let id = eventData.id;
let result = eventData.data.result;
let found = this.findCriterion(id);
if (found) {
this.criteriaResults[id] = result;
if (this.findCriterion(id)) {
this.criteriaResults[id] = eventData.data.result;
}
this.handleConditionUpdated();
// change criterion result to be condition result as passed down the line
// hacky but trying not to make sweeping changes to current architecture
eventData.data.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
this.emitEvent('conditionResultUpdated', eventData.data);
}
subscribe() {
// TODO it looks like on any single criterion update subscriptions fire for all criteria
this.criteria.forEach((criterion) => {
criterion.subscribe();
})
}
handleConditionUpdated() {
// trigger an updated event so that consumers can react accordingly
this.evaluate();
this.emitEvent('conditionResultUpdated', {result: this.result});
}
getCriteria() {
return this.criteria;
}
@ -222,10 +220,6 @@ 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

@ -207,31 +207,31 @@ export default class ConditionManager extends EventEmitter {
handleConditionResult(resultObj) {
let conditionCollection = this.domainObject.configuration.conditionCollection;
// set current condition to default condition
let currentConditionIdentifier = conditionCollection[conditionCollection.length-1];
let currentConditionResult = {};
if (resultObj) {
let idAsString = this.openmct.objects.makeKeyString(resultObj.id);
let found = this.findConditionById(idAsString);
if (found) {
this.conditionResults[idAsString] = resultObj.data.result;
if (this.findConditionById(idAsString)) {
this.conditionResults[idAsString] = resultObj.data;
}
}
for (let i = 0, ii = conditionCollection.length - 1; i < ii; i++) {
for (let i = 0; i < conditionCollection.length - 1; i++) {
let conditionIdAsString = this.openmct.objects.makeKeyString(conditionCollection[i]);
if (this.conditionResults[conditionIdAsString]) {
if (this.conditionResults[conditionIdAsString] && this.conditionResults[conditionIdAsString].result) {
//first condition to be true wins
currentConditionIdentifier = conditionCollection[i];
currentConditionResult = this.conditionResults[conditionIdAsString];
break;
}
}
this.openmct.objects.get(currentConditionIdentifier).then((obj) => {
this.emit('conditionSetResultUpdated', {
id: this.domainObject.identifier,
output: obj.configuration.output,
conditionId: currentConditionIdentifier
})
this.emit('conditionSetResultUpdated',
Object.assign(currentConditionResult, {output: obj.configuration.output})
)
});
}

View File

@ -63,12 +63,10 @@ export default {
},
methods: {
updateCurrentOutput(currentConditionResult) {
if (this.openmct.objects.makeKeyString(currentConditionResult.id) === this.conditionSetIdentifier) {
this.currentConditionOutput = currentConditionResult.output;
}
this.currentConditionOutput = currentConditionResult.output;
},
provideTelemetry() {
this.stopProvidingTelemetry = this.openmct.telemetry.subscribe(this.domainObject, (output) => output);
this.stopProvidingTelemetry = this.openmct.telemetry.subscribe(this.domainObject, output => output);
}
}
};

View File

@ -38,6 +38,7 @@ export default class TelemetryCriterion extends EventEmitter {
this.openmct = openmct;
this.objectAPI = this.openmct.objects;
this.telemetryAPI = this.openmct.telemetry;
this.timeAPI = this.openmct.time;
this.id = telemetryDomainObjectDefinition.id;
this.telemetry = telemetryDomainObjectDefinition.telemetry;
this.operation = telemetryDomainObjectDefinition.operation;
@ -55,11 +56,15 @@ export default class TelemetryCriterion extends EventEmitter {
}
handleSubscription(data) {
let result = this.computeResult(data);
this.emitEvent('criterionResultUpdated', {
result: result,
error: null
})
const datum = {};
const timeSystemKey = this.timeAPI.timeSystem().key;
datum.result = this.computeResult(data);
if (data && data[timeSystemKey]) {
datum[timeSystemKey] = data[timeSystemKey]
}
this.emitEvent('criterionResultUpdated', datum);
}
findOperation(operation) {