WIP continue to add support for LAD request

TODO conditionCollection needs to load before condition requests can be made
This commit is contained in:
David Tsay 2020-03-05 16:42:31 -08:00
parent 3e6509ce6f
commit 897d05276a
4 changed files with 116 additions and 53 deletions

View File

@ -189,25 +189,36 @@ export default class ConditionClass extends EventEmitter {
}
}
handleLADCriterionResult(eventData) {
}
handleCriterionResult(eventData) {
updateCriteriaResults(eventData) {
const id = eventData.id;
if (this.findCriterion(id)) {
this.criteriaResults[id] = eventData.data.result;
}
}
handleCriterionResult(eventData) {
this.updateCriteriaResults(eventData);
this.handleConditionUpdated(eventData.data);
}
requestLatest() {
const promises =
requestLADConditionResult() {
const criteriaResults = [];
Promise.all(promises)
.then()
this.criteria.forEach(criterion => {
criteriaResults.push(
criterion.requestLAD()
);
});
Promise.all(criteriaResults)
.then(results => {
results.forEach(result => {
this.updateCriteriaResults(result);
});
return Object.assign({}, /*datum,*/ { result: this.result });
});
}
subscribe() {

View File

@ -32,24 +32,35 @@ export default class ConditionManager extends EventEmitter {
this.timeAPI = this.openmct.time;
this.latestTimestamp = {};
this.instantiate = this.openmct.$injector.get('instantiate');
this.loaded = undefined;
this.initialize();
}
load() {
return this.loaded;
}
initialize() {
this.conditionResults = {};
let loading = [];
this.openmct.objects.get(this.domainObject.identifier).then((obj) => {
this.observeForChanges(obj);
this.conditionCollection = [];
if (this.domainObject.configuration.conditionCollection.length) {
this.domainObject.configuration.conditionCollection.forEach((conditionConfigurationId, index) => {
this.openmct.objects.get(conditionConfigurationId).then((conditionConfiguration) => {
this.initCondition(conditionConfiguration, index)
loading.push(
this.initCondition(conditionConfiguration, index)
);
});
});
} else {
this.addCondition(true);
}
});
this.loaded = Promise.all(loading)
.then(() => { return true; });
}
observeForChanges(domainObject) {
@ -98,6 +109,8 @@ export default class ConditionManager extends EventEmitter {
if (conditionConfiguration.isDefault) {
this.handleConditionResult();
}
return Promise.resolve(true);
}
createConditionDomainObject(isDefault, conditionConfiguration) {
@ -206,20 +219,12 @@ export default class ConditionManager extends EventEmitter {
this.persist();
}
handleConditionResult(resultObj) {
let conditionCollection = this.domainObject.configuration.conditionCollection;
getCurrentConditionId() {
const conditionCollection = this.domainObject.configuration.conditionCollection;
let currentConditionIdentifier = conditionCollection[conditionCollection.length-1];
if (resultObj) {
let idAsString = this.openmct.objects.makeKeyString(resultObj.id);
if (this.findConditionById(idAsString)) {
this.conditionResults[idAsString] = resultObj.data.result;
}
this.updateTimestamp(resultObj.data);
}
for (let i = 0; i < conditionCollection.length - 1; i++) {
let conditionIdAsString = this.openmct.objects.makeKeyString(conditionCollection[i]);
const conditionIdAsString = this.openmct.objects.makeKeyString(conditionCollection[i]);
if (this.conditionResults[conditionIdAsString]) {
//first condition to be true wins
currentConditionIdentifier = conditionCollection[i];
@ -227,6 +232,30 @@ export default class ConditionManager extends EventEmitter {
}
}
return currentConditionIdentifier;
}
updateConditionResults(resultObj) {
console.log(this.conditionCollection);
if (!resultObj) {
return;
}
let idAsString = this.openmct.objects.makeKeyString(resultObj.id);
if (this.findConditionById(idAsString)) {
this.conditionResults[idAsString] = resultObj.data.result;
}
this.updateTimestamp(resultObj.data);
}
handleConditionResult(resultObj) {
this.updateConditionResults(resultObj);
const currentConditionIdentifier = this.getCurrentConditionId();
this.openmct.objects.get(currentConditionIdentifier).then((obj) => {
this.emit('conditionSetResultUpdated',
Object.assign(
@ -251,8 +280,38 @@ export default class ConditionManager extends EventEmitter {
});
}
requestLatest() {
requestLADConditionSetOutput() {
const conditionResults = [];
this.load()
.then(() => {
this.conditionCollection.forEach(conditionId => {
this.openmct.objects.get(conditionId)
.then(condition => {
conditionResults.push(
condition.requestLADConditionResult()
);
});
});
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() {

View File

@ -18,16 +18,14 @@ export default class ConditionSetTelemetryProvider {
}
request(domainObject, options) {
let conditionManager = new ConditionManager(domainObject, this.openmct);
return conditionManager.requestLatest()
.then(latestDatum => {
return latestDatum ? [latestDatum] : [];
});
// return Promise.resolve([]);
const conditionManager = new ConditionManager(domainObject, this.openmct);
const output = conditionManager.requestLADConditionSetOutput();
return output;
}
subscribe(domainObject, callback) {
let conditionManager = new ConditionManager(domainObject, this.openmct);
const conditionManager = new ConditionManager(domainObject, this.openmct);
conditionManager.on('conditionSetResultUpdated', callback);
return function unsubscribe() {

View File

@ -70,10 +70,6 @@ export default class TelemetryCriterion extends EventEmitter {
return datum;
}
handleRequest(data) {
this.emitEvent('criterionLADResultUpdated', this.formatData(data));
}
handleSubscription(data) {
this.emitEvent('criterionResultUpdated', this.formatData(data));
}
@ -114,27 +110,26 @@ export default class TelemetryCriterion extends EventEmitter {
return this.telemetryObject && this.metadata && this.operation;
}
requestLatest(options) {
if (this.isValid()) {
options = Object.assign({},
options,
{
strategy: 'latest',
size: 1
}
);
this.telemetryAPI.request(
this.telemetryObject,
options
).then(results => {
if(results && results.length) {
results[results.length - 1]
}
})
} else {
// default
requestLAD(options) {
if (!this.isValid()) {
return this.formatData({});
}
options = Object.assign({},
options,
{
strategy: 'latest',
size: 1
}
);
this.telemetryAPI.request(
this.telemetryObject,
options
).then(results => {
const datum = results.length ? results[results.length - 1] : {};
return this.formatData(datum);
});
}
/**