request LAD for conditions provides telemetry

This commit is contained in:
David Tsay 2020-03-06 17:33:21 -08:00
parent cf9336dae9
commit 4a5e106709
5 changed files with 50 additions and 50 deletions

View File

@ -204,9 +204,8 @@ export default class ConditionClass extends EventEmitter {
} }
requestLADConditionResult() { requestLADConditionResult() {
const criteriaResults = this.criteria.map(criterion => const criteriaResults = this.criteria
criterion.requestLAD() .map(criterion => criterion.requestLAD());
);
return Promise.all(criteriaResults) return Promise.all(criteriaResults)
.then(results => { .then(results => {
@ -214,8 +213,12 @@ export default class ConditionClass extends EventEmitter {
this.updateCriteriaResults(result); this.updateCriteriaResults(result);
this.latestTimestamp = this.getLatestTimestamp(this.latestTimestamp, result) this.latestTimestamp = this.getLatestTimestamp(this.latestTimestamp, result)
}); });
console.log(Object.assign({}, this.latestTimestamp, { result: this.result })); this.evaluate();
return Object.assign({}, this.latestTimestamp, { result: this.result });
return {
id: this.id,
data: Object.assign({}, this.latestTimestamp, { result: this.result })
}
}); });
} }

View File

@ -32,8 +32,9 @@ export default class ConditionManager extends EventEmitter {
this.timeAPI = this.openmct.time; this.timeAPI = this.openmct.time;
this.latestTimestamp = {}; this.latestTimestamp = {};
this.instantiate = this.openmct.$injector.get('instantiate'); this.instantiate = this.openmct.$injector.get('instantiate');
this.loaded = undefined;
this.conditionCollection = []; this.conditionCollection = [];
this.composition = this.openmct.composition.get(domainObject);
this.loaded = this.composition.load();
this.initialize(); this.initialize();
} }
@ -45,7 +46,7 @@ export default class ConditionManager extends EventEmitter {
this.conditionResults = {}; this.conditionResults = {};
this.openmct.objects.get(this.domainObject.identifier) this.openmct.objects.get(this.domainObject.identifier)
.then((obj) => { .then((obj) => {
this.observeForChanges(obj); this.observeForChanges(obj);
if (this.domainObject.configuration.conditionCollection.length) { if (this.domainObject.configuration.conditionCollection.length) {
this.domainObject.configuration.conditionCollection.forEach((conditionConfigurationId, index) => { this.domainObject.configuration.conditionCollection.forEach((conditionConfigurationId, index) => {
@ -225,7 +226,6 @@ export default class ConditionManager extends EventEmitter {
break; break;
} }
} }
return currentConditionIdentifier; return currentConditionIdentifier;
} }
@ -247,7 +247,6 @@ export default class ConditionManager extends EventEmitter {
this.updateConditionResults(resultObj); this.updateConditionResults(resultObj);
const currentConditionIdentifier = this.getCurrentConditionId(); const currentConditionIdentifier = this.getCurrentConditionId();
this.openmct.objects.get(currentConditionIdentifier).then((obj) => { this.openmct.objects.get(currentConditionIdentifier).then((obj) => {
this.emit('conditionSetResultUpdated', this.emit('conditionSetResultUpdated',
Object.assign( Object.assign(
@ -277,41 +276,36 @@ export default class ConditionManager extends EventEmitter {
return Promise.resolve([]); return Promise.resolve([]);
} }
const conditionResults = []; return this.load().then(() => {
if (this.conditionCollection && this.conditionCollection.length === 1) {
return Promise([]);
}
this.domainObject.configuration.conditionCollection.forEach((conditionId, index) => { let ladConditionResults = [];
this.openmct.objects.get(conditionId)
.then(conditionConfiguration => {
let condition = new Condition(conditionConfiguration, this.openmct);
if (index !== undefined) {
this.conditionCollection.splice(index + 1, 0, condition);
} else {
this.conditionCollection.unshift(condition);
}
conditionResults.push( // do not request LAD for default collection, which is always last
condition.requestLADConditionResult() for (let i = 0; i < this.conditionCollection.length - 1; i++) {
); ladConditionResults.push(this.conditionCollection[i].requestLADConditionResult());
}
return Promise.all(ladConditionResults)
.then((results) => {
results.forEach(resultObj => { this.updateConditionResults(resultObj); });
const currentConditionIdentifier = this.getCurrentConditionId();
return this.openmct.objects.get(currentConditionIdentifier)
.then(obj => {
// uncomment to see output of lad request (before subscriptions kick in)
// console.log(obj.configuration.output);
return Object.assign(
{
output: obj.configuration.output,
id: this.domainObject.identifier,
conditionId: currentConditionIdentifier
},
this.latestTimestamp
);
});
}); });
}); });
return Promise.all(conditionResults)
.then((results) => {
results.forEach(resultObj => { this.updateConditionResults(resultObj); });
const currentConditionIdentifier = this.getCurrentConditionId();
this.openmct.objects.get(currentConditionIdentifier).then((obj) => {
return Object.assign(
{
output: obj.configuration.output,
id: this.domainObject.identifier,
conditionId: currentConditionIdentifier
},
this.latestTimestamp
);
});
});
} }
persist() { persist() {

View File

@ -20,16 +20,17 @@ export default class ConditionSetTelemetryProvider {
request(domainObject, options) { request(domainObject, options) {
const conditionManager = new ConditionManager(domainObject, this.openmct); const conditionManager = new ConditionManager(domainObject, this.openmct);
return conditionManager.requestLADConditionSetOutput(); return conditionManager.requestLADConditionSetOutput()
.then(latestOutput => { return latestOutput ? [latestOutput] : []; });
} }
subscribe(domainObject, callback) { subscribe(domainObject, callback) {
// const conditionManager = new ConditionManager(domainObject, this.openmct); const conditionManager = new ConditionManager(domainObject, this.openmct);
// conditionManager.on('conditionSetResultUpdated', callback); conditionManager.on('conditionSetResultUpdated', callback);
// return function unsubscribe() { return function unsubscribe() {
// conditionManager.off('conditionSetResultUpdated'); conditionManager.off('conditionSetResultUpdated');
// conditionManager.destroy(); conditionManager.destroy();
// } }
} }
} }

View File

@ -77,7 +77,7 @@ export default {
this.openmct.telemetry this.openmct.telemetry
.request(this.domainObject) .request(this.domainObject)
.then(output => { .then(output => {
this.updateCurrentOutput(output); this.updateCurrentOutput(output[0]);
}); });
this.stopProvidingTelemetry = this.openmct.telemetry this.stopProvidingTelemetry = this.openmct.telemetry
.subscribe(this.domainObject, output => { this.updateCurrentOutput(output); }); .subscribe(this.domainObject, output => { this.updateCurrentOutput(output); });

View File

@ -66,7 +66,6 @@ export default class TelemetryCriterion extends EventEmitter {
datum[timeSystem.key] = data[timeSystem.key] datum[timeSystem.key] = data[timeSystem.key]
}); });
} }
return datum; return datum;
} }
@ -129,7 +128,10 @@ export default class TelemetryCriterion extends EventEmitter {
options options
).then(results => { ).then(results => {
const latestDatum = results.length ? results[results.length - 1] : {}; const latestDatum = results.length ? results[results.length - 1] : {};
return this.formatData(latestDatum); return {
id: this.id,
data: this.formatData(latestDatum)
};
}); });
}); });
} }