mirror of
https://github.com/nasa/openmct.git
synced 2024-12-30 01:48:51 +00:00
WIP continue to add support for LAD request
TODO conditionCollection needs to load before condition requests can be made
This commit is contained in:
parent
3e6509ce6f
commit
897d05276a
@ -189,25 +189,36 @@ export default class ConditionClass extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLADCriterionResult(eventData) {
|
updateCriteriaResults(eventData) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
handleCriterionResult(eventData) {
|
|
||||||
const id = eventData.id;
|
const id = eventData.id;
|
||||||
|
|
||||||
if (this.findCriterion(id)) {
|
if (this.findCriterion(id)) {
|
||||||
this.criteriaResults[id] = eventData.data.result;
|
this.criteriaResults[id] = eventData.data.result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleCriterionResult(eventData) {
|
||||||
|
this.updateCriteriaResults(eventData);
|
||||||
this.handleConditionUpdated(eventData.data);
|
this.handleConditionUpdated(eventData.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestLatest() {
|
requestLADConditionResult() {
|
||||||
const promises =
|
const criteriaResults = [];
|
||||||
|
|
||||||
Promise.all(promises)
|
this.criteria.forEach(criterion => {
|
||||||
.then()
|
criteriaResults.push(
|
||||||
|
criterion.requestLAD()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
Promise.all(criteriaResults)
|
||||||
|
.then(results => {
|
||||||
|
results.forEach(result => {
|
||||||
|
this.updateCriteriaResults(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Object.assign({}, /*datum,*/ { result: this.result });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe() {
|
subscribe() {
|
||||||
|
@ -32,24 +32,35 @@ 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.initialize();
|
this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load() {
|
||||||
|
return this.loaded;
|
||||||
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
this.conditionResults = {};
|
this.conditionResults = {};
|
||||||
|
let loading = [];
|
||||||
|
|
||||||
this.openmct.objects.get(this.domainObject.identifier).then((obj) => {
|
this.openmct.objects.get(this.domainObject.identifier).then((obj) => {
|
||||||
this.observeForChanges(obj);
|
this.observeForChanges(obj);
|
||||||
this.conditionCollection = [];
|
this.conditionCollection = [];
|
||||||
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) => {
|
||||||
this.openmct.objects.get(conditionConfigurationId).then((conditionConfiguration) => {
|
this.openmct.objects.get(conditionConfigurationId).then((conditionConfiguration) => {
|
||||||
this.initCondition(conditionConfiguration, index)
|
loading.push(
|
||||||
|
this.initCondition(conditionConfiguration, index)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.addCondition(true);
|
this.addCondition(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.loaded = Promise.all(loading)
|
||||||
|
.then(() => { return true; });
|
||||||
}
|
}
|
||||||
|
|
||||||
observeForChanges(domainObject) {
|
observeForChanges(domainObject) {
|
||||||
@ -98,6 +109,8 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
if (conditionConfiguration.isDefault) {
|
if (conditionConfiguration.isDefault) {
|
||||||
this.handleConditionResult();
|
this.handleConditionResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
createConditionDomainObject(isDefault, conditionConfiguration) {
|
createConditionDomainObject(isDefault, conditionConfiguration) {
|
||||||
@ -206,20 +219,12 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
this.persist();
|
this.persist();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleConditionResult(resultObj) {
|
getCurrentConditionId() {
|
||||||
let conditionCollection = this.domainObject.configuration.conditionCollection;
|
const conditionCollection = this.domainObject.configuration.conditionCollection;
|
||||||
let currentConditionIdentifier = conditionCollection[conditionCollection.length-1];
|
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++) {
|
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]) {
|
if (this.conditionResults[conditionIdAsString]) {
|
||||||
//first condition to be true wins
|
//first condition to be true wins
|
||||||
currentConditionIdentifier = conditionCollection[i];
|
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.openmct.objects.get(currentConditionIdentifier).then((obj) => {
|
||||||
this.emit('conditionSetResultUpdated',
|
this.emit('conditionSetResultUpdated',
|
||||||
Object.assign(
|
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() {
|
persist() {
|
||||||
|
@ -18,16 +18,14 @@ export default class ConditionSetTelemetryProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request(domainObject, options) {
|
request(domainObject, options) {
|
||||||
let conditionManager = new ConditionManager(domainObject, this.openmct);
|
const conditionManager = new ConditionManager(domainObject, this.openmct);
|
||||||
return conditionManager.requestLatest()
|
const output = conditionManager.requestLADConditionSetOutput();
|
||||||
.then(latestDatum => {
|
|
||||||
return latestDatum ? [latestDatum] : [];
|
return output;
|
||||||
});
|
|
||||||
// return Promise.resolve([]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(domainObject, callback) {
|
subscribe(domainObject, callback) {
|
||||||
let 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() {
|
||||||
|
@ -70,10 +70,6 @@ export default class TelemetryCriterion extends EventEmitter {
|
|||||||
return datum;
|
return datum;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRequest(data) {
|
|
||||||
this.emitEvent('criterionLADResultUpdated', this.formatData(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubscription(data) {
|
handleSubscription(data) {
|
||||||
this.emitEvent('criterionResultUpdated', this.formatData(data));
|
this.emitEvent('criterionResultUpdated', this.formatData(data));
|
||||||
}
|
}
|
||||||
@ -114,27 +110,26 @@ export default class TelemetryCriterion extends EventEmitter {
|
|||||||
return this.telemetryObject && this.metadata && this.operation;
|
return this.telemetryObject && this.metadata && this.operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
requestLatest(options) {
|
requestLAD(options) {
|
||||||
if (this.isValid()) {
|
if (!this.isValid()) {
|
||||||
options = Object.assign({},
|
return this.formatData({});
|
||||||
options,
|
|
||||||
{
|
|
||||||
strategy: 'latest',
|
|
||||||
size: 1
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.telemetryAPI.request(
|
|
||||||
this.telemetryObject,
|
|
||||||
options
|
|
||||||
).then(results => {
|
|
||||||
if(results && results.length) {
|
|
||||||
results[results.length - 1]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// default
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user