From 89ae6ef8c705adddcad19ed1c15f02a4b2509c62 Mon Sep 17 00:00:00 2001 From: David Tsay Date: Fri, 28 Feb 2020 11:15:19 -0800 Subject: [PATCH] provide telemetry with timestamps --- src/plugins/condition/Condition.js | 26 +++++++------------ src/plugins/condition/ConditionManager.js | 20 +++++++------- .../condition/components/ConditionSet.vue | 6 ++--- .../condition/criterion/TelemetryCriterion.js | 15 +++++++---- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/plugins/condition/Condition.js b/src/plugins/condition/Condition.js index a102dff575..09723e47c6 100644 --- a/src/plugins/condition/Condition.js +++ b/src/plugins/condition/Condition.js @@ -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, diff --git a/src/plugins/condition/ConditionManager.js b/src/plugins/condition/ConditionManager.js index d86397d464..a6493230d8 100644 --- a/src/plugins/condition/ConditionManager.js +++ b/src/plugins/condition/ConditionManager.js @@ -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}) + ) }); } diff --git a/src/plugins/condition/components/ConditionSet.vue b/src/plugins/condition/components/ConditionSet.vue index 2cf3b25989..23a7ce01c4 100644 --- a/src/plugins/condition/components/ConditionSet.vue +++ b/src/plugins/condition/components/ConditionSet.vue @@ -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); } } }; diff --git a/src/plugins/condition/criterion/TelemetryCriterion.js b/src/plugins/condition/criterion/TelemetryCriterion.js index a5201fc711..d0f76a060e 100644 --- a/src/plugins/condition/criterion/TelemetryCriterion.js +++ b/src/plugins/condition/criterion/TelemetryCriterion.js @@ -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) {