Add all and any options for telemetry

This commit is contained in:
Joshi 2020-03-26 16:44:44 -07:00
parent ec0291c54d
commit 502d29dd25
3 changed files with 95 additions and 58 deletions

View File

@ -25,6 +25,7 @@ import uuid from 'uuid';
import TelemetryCriterion from "./criterion/TelemetryCriterion"; import TelemetryCriterion from "./criterion/TelemetryCriterion";
import { TRIGGER } from "./utils/constants"; import { TRIGGER } from "./utils/constants";
import {computeCondition} from "./utils/evaluator"; import {computeCondition} from "./utils/evaluator";
import AllTelemetryCriterion from "@/plugins/condition/criterion/AllTelemetryCriterion";
/* /*
* conditionConfiguration = { * conditionConfiguration = {
@ -124,8 +125,13 @@ export default class ConditionClass extends EventEmitter {
* adds criterion to the condition. * adds criterion to the condition.
*/ */
addCriterion(criterionConfiguration) { addCriterion(criterionConfiguration) {
let criterion;
let criterionConfigurationWithId = this.generateCriterion(criterionConfiguration || null); let criterionConfigurationWithId = this.generateCriterion(criterionConfiguration || null);
let criterion = new TelemetryCriterion(criterionConfigurationWithId, this.openmct); if (criterionConfiguration.telemetry && (criterionConfiguration.telemetry === 'any' || criterionConfiguration.telemetry === 'all')) {
criterion = new AllTelemetryCriterion(criterionConfigurationWithId, this.openmct);
} else {
criterion = new TelemetryCriterion(criterionConfigurationWithId, this.openmct);
}
criterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj)); criterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
criterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj)); criterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj));
if (!this.criteria) { if (!this.criteria) {

View File

@ -9,6 +9,8 @@
@change="updateMetadataOptions" @change="updateMetadataOptions"
> >
<option value="">- Select Telemetry -</option> <option value="">- Select Telemetry -</option>
<option value="all">All Telemetry</option>
<option value="any">Any Telemetry</option>
<option v-for="telemetryOption in telemetry" <option v-for="telemetryOption in telemetry"
:key="telemetryOption.identifier.key" :key="telemetryOption.identifier.key"
:value="telemetryOption.identifier" :value="telemetryOption.identifier"
@ -109,7 +111,7 @@ export default {
data() { data() {
return { return {
telemetryMetadata: {}, telemetryMetadata: {},
telemetryMetadataOptions: {}, telemetryMetadataOptions: [],
operations: OPERATIONS, operations: OPERATIONS,
inputCount: 0, inputCount: 0,
rowLabel: '', rowLabel: '',
@ -132,7 +134,11 @@ export default {
return (this.index !== 0 ? operator : '') + 'when'; return (this.index !== 0 ? operator : '') + 'when';
}, },
filteredOps: function () { filteredOps: function () {
if (this.operationFormat === 'all') {
return this.operations;
} else {
return [...this.operations.filter(op => op.appliesTo.indexOf(this.operationFormat) !== -1)]; return [...this.operations.filter(op => op.appliesTo.indexOf(this.operationFormat) !== -1)];
}
}, },
setInputType: function () { setInputType: function () {
let type = ''; let type = '';
@ -154,8 +160,11 @@ export default {
}, },
methods: { methods: {
checkTelemetry() { checkTelemetry() {
if(this.criterion.telemetry && if(this.criterion.telemetry) {
!this.telemetry.find((telemetryObj) => this.openmct.objects.areIdsEqual(this.criterion.telemetry, telemetryObj.identifier))) { if (this.criterion.telemetry === 'any' && this.criterion.telemetry === 'all') {
this.updateMetadataOptions();
} else {
if (!this.telemetry.find((telemetryObj) => this.openmct.objects.areIdsEqual(this.criterion.telemetry, telemetryObj.identifier))) {
//telemetry being used was removed. So reset this criterion. //telemetry being used was removed. So reset this criterion.
this.criterion.telemetry = ''; this.criterion.telemetry = '';
this.criterion.metadata = ''; this.criterion.metadata = '';
@ -163,9 +172,14 @@ export default {
this.criterion.operation = ''; this.criterion.operation = '';
this.persist(); this.persist();
} }
}
}
}, },
getOperationFormat() { getOperationFormat() {
this.enumerations = []; this.enumerations = [];
if (this.criterion.telemetry && (this.criterion.telemetry === 'any' || this.criterion.telemetry === 'all')) {
this.operationFormat = 'all';
} else {
this.telemetryMetadata.valueMetadatas.forEach((value, index) => { this.telemetryMetadata.valueMetadatas.forEach((value, index) => {
if (value.key === this.criterion.metadata) { if (value.key === this.criterion.metadata) {
let valueMetadata = this.telemetryMetadataOptions[index]; let valueMetadata = this.telemetryMetadataOptions[index];
@ -183,25 +197,39 @@ export default {
} }
} }
}); });
}
}, },
updateMetadataOptions(ev) { updateMetadataOptions(ev) {
if (ev) { if (ev) {
this.clearDependentFields(ev.target) this.clearDependentFields(ev.target);
this.updateOperations(ev);
} }
if (this.criterion.telemetry) { if (this.criterion.telemetry) {
if (this.criterion.telemetry === 'any' || this.criterion.telemetry === 'all') {
let telemetryPromises = this.telemetry.map((telemetryObject) => this.openmct.objects.get(telemetryObject.identifier));
Promise.all(telemetryPromises).then(telemetryObjects => {
this.telemetryMetadataOptions = [];
telemetryObjects.forEach(telemetryObject => {
let telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject);
this.telemetryMetadataOptions = this.telemetryMetadataOptions.concat(telemetryMetadata.values());
this.updateOperations();
this.updateOperationInputVisibility();
});
});
} else {
this.openmct.objects.get(this.criterion.telemetry).then((telemetryObject) => { this.openmct.objects.get(this.criterion.telemetry).then((telemetryObject) => {
this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject); this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject);
this.telemetryMetadataOptions = this.telemetryMetadata.values(); this.telemetryMetadataOptions = this.telemetryMetadata.values();
this.updateOperations(ev); this.updateOperations();
this.updateOperationInputVisibility(); this.updateOperationInputVisibility();
this.$emit('setTelemetryName', telemetryObject.name)
}); });
}
} else { } else {
this.criterion.metadata = ''; this.criterion.metadata = '';
} }
}, },
updateOperations(ev) { updateOperations(ev) {
if (ev.target === this.$ref.telemetrySelect) { if (ev && (ev.target === this.$refs.telemetrySelect)) {
this.clearDependentFields(ev.target); this.clearDependentFields(ev.target);
this.persist(); this.persist();
} }
@ -221,10 +249,10 @@ export default {
} }
}, },
clearDependentFields(el) { clearDependentFields(el) {
if (el === this.$ref.telemetrySelect) { if (el === this.$refs.telemetrySelect) {
this.criterion.metadata = ''; this.criterion.metadata = '';
this.criterion.operation = ''; this.criterion.operation = '';
} else if (el === this.$ref.metadataSelect) { } else if (el === this.$refs.metadataSelect) {
this.criterion.operation = ''; this.criterion.operation = '';
} }
this.criterion.input = []; this.criterion.input = [];

View File

@ -50,10 +50,18 @@ export default class TelemetryCriterion extends EventEmitter {
this.telemetryDataCache = {}; this.telemetryDataCache = {};
} }
formatData(data, telemetryObjects) { updateTelemetry(telemetryObjects) {
this.telemetryDataCache[data.id] = this.computeResult(data); this.telemetryObjects = telemetryObjects;
}
telemetryObjects.forEach((telemetryObject) => { formatData(data, telemetryObjects) {
if (data) {
this.telemetryDataCache[data.id] = this.computeResult(data);
}
let keys = Object.keys(telemetryObjects);
keys.forEach((key) => {
let telemetryObject = telemetryObjects[key];
const id = this.openmct.objects.makeKeyString(telemetryObject.identifier); const id = this.openmct.objects.makeKeyString(telemetryObject.identifier);
if (this.telemetryDataCache[id] === undefined) { if (this.telemetryDataCache[id] === undefined) {
this.telemetryDataCache[id] = false; this.telemetryDataCache[id] = false;
@ -70,7 +78,6 @@ export default class TelemetryCriterion extends EventEmitter {
datum[timeSystem.key] = data[timeSystem.key] datum[timeSystem.key] = data[timeSystem.key]
}); });
} }
return datum; return datum;
} }
@ -137,25 +144,21 @@ export default class TelemetryCriterion extends EventEmitter {
return Promise.all(telemetryRequests) return Promise.all(telemetryRequests)
.then(telemetryRequestsResults => { .then(telemetryRequestsResults => {
telemetryRequestsResults.forEach(results => { telemetryRequestsResults.forEach((results, index) => {
const latestDatum = results.length ? results[results.length - 1] : {}; const latestDatum = results.length ? results[results.length - 1] : {};
if (index === telemetryRequestsResults.length-1) {
//when the last result is computed, we return the result
return { return {
id: this.id, id: this.id,
data: this.formatData(latestDatum, options.telemetryObjects) data: this.formatData(latestDatum, options.telemetryObjects)
}; };
} else {
if (latestDatum) {
this.telemetryDataCache[latestDatum.id] = this.computeResult(latestDatum);
}
}
}); });
}); });
// return this.telemetryAPI.request(
// this.telemetryObject,
// options
// ).then(results => {
// const latestDatum = results.length ? results[results.length - 1] : {};
// return {
// id: this.id,
// data: this.formatData(latestDatum)
// };
// });
} }
destroy() { destroy() {