WIP receive criterion results and compute condition results

This commit is contained in:
David Tsay 2020-03-06 11:01:15 -08:00
parent 7f32d196e4
commit cf9336dae9
2 changed files with 24 additions and 12 deletions

View File

@ -59,6 +59,7 @@ export default class ConditionClass extends EventEmitter {
this.criteria = [];
this.criteriaResults = {};
this.result = undefined;
this.latestTimestamp = {};
if (conditionConfiguration.configuration.criteria) {
this.createCriteria(conditionConfiguration.configuration.criteria);
}
@ -203,21 +204,18 @@ export default class ConditionClass extends EventEmitter {
}
requestLADConditionResult() {
const criteriaResults = [];
this.criteria.forEach(criterion => {
criteriaResults.push(
criterion.requestLAD()
);
});
const criteriaResults = this.criteria.map(criterion =>
criterion.requestLAD()
);
return Promise.all(criteriaResults)
.then(results => {
results.forEach(result => {
this.updateCriteriaResults(result);
this.latestTimestamp = this.getLatestTimestamp(this.latestTimestamp, result)
});
return Object.assign({}, /*datum,*/ { result: this.result });
console.log(Object.assign({}, this.latestTimestamp, { result: this.result }));
return Object.assign({}, this.latestTimestamp, { result: this.result });
});
}
@ -253,6 +251,20 @@ export default class ConditionClass extends EventEmitter {
this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
}
getLatestTimestamp(current, compare) {
const timestamp = Object.assign({}, current);
this.openmct.time.getAllTimeSystems().forEach(timeSystem => {
if (!timestamp[timeSystem.key]
|| compare[timeSystem.key] > timestamp[timeSystem.key]
) {
timestamp[timeSystem.key] = compare[timeSystem.key];
}
});
return timestamp;
}
emitEvent(eventName, data) {
this.emit(eventName, {
id: this.id,

View File

@ -118,7 +118,7 @@ export default class TelemetryCriterion extends EventEmitter {
size: 1
}
);
return this.objectAPI.get(this.objectAPI.makeKeyString(this.telemetry))
.then((obj) => {
if (!obj || !this.metadata || !this.operation) {
@ -128,8 +128,8 @@ export default class TelemetryCriterion extends EventEmitter {
obj,
options
).then(results => {
const datum = results.length ? results[results.length - 1] : {};
return this.formatData(datum);
const latestDatum = results.length ? results[results.length - 1] : {};
return this.formatData(latestDatum);
});
});
}