mirror of
https://github.com/nasa/openmct.git
synced 2025-03-13 15:56:49 +00:00
Restore short-circuit evaluation, pass in current values
This commit is contained in:
parent
4b269fa50c
commit
1a1151ce3d
@ -71,21 +71,24 @@ export default class Condition extends EventEmitter {
|
||||
this.handleTelemetryStaleness = this.handleTelemetryStaleness.bind(this);
|
||||
}
|
||||
|
||||
updateResult(datum) {
|
||||
if (!datum || !datum.id) {
|
||||
updateResult(latestDataTable) {
|
||||
if (!latestDataTable) {
|
||||
console.log('no data received');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const hasNoTelemetry = this.hasNoTelemetry();
|
||||
|
||||
// if all the criteria in this condition have no telemetry, we want to force the condition result to evaluate
|
||||
if (this.hasNoTelemetry() || this.isTelemetryUsed(datum.id)) {
|
||||
//if (this.hasNoTelemetry() || this.isTelemetryUsed(latestDataTable.id)) {
|
||||
this.criteria.forEach((criterion) => {
|
||||
if (this.isAnyOrAllTelemetry(criterion)) {
|
||||
criterion.updateResult(datum, this.conditionManager.telemetryObjects);
|
||||
criterion.updateResult(latestDataTable, this.conditionManager.telemetryObjects);
|
||||
} else {
|
||||
if (criterion.usesTelemetry(datum.id)) {
|
||||
criterion.updateResult(datum);
|
||||
const relevantDatum = latestDataTable.get(criterion.telemetryObjectIdAsString);
|
||||
|
||||
if (relevantDatum !== undefined){
|
||||
criterion.updateResult(relevantDatum);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -94,7 +97,7 @@ export default class Condition extends EventEmitter {
|
||||
this.criteria.map((criterion) => criterion.result),
|
||||
this.trigger
|
||||
);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
isAnyOrAllTelemetry(criterion) {
|
||||
|
@ -27,6 +27,8 @@ import Condition from './Condition.js';
|
||||
import { getLatestTimestamp } from './utils/time.js';
|
||||
|
||||
export default class ConditionManager extends EventEmitter {
|
||||
#latestDataTable = new Map();
|
||||
|
||||
constructor(conditionSetDomainObject, openmct) {
|
||||
super();
|
||||
this.openmct = openmct;
|
||||
@ -410,19 +412,22 @@ export default class ConditionManager extends EventEmitter {
|
||||
|
||||
const normalizedDatum = this.createNormalizedDatum(datum, endpoint);
|
||||
const timeSystemKey = this.openmct.time.getTimeSystem().key;
|
||||
let timestamp = {};
|
||||
const currentTimestamp = normalizedDatum[timeSystemKey];
|
||||
const timestamp = {};
|
||||
|
||||
timestamp[timeSystemKey] = currentTimestamp;
|
||||
this.#latestDataTable.set(normalizedDatum.id, normalizedDatum);
|
||||
|
||||
if (this.shouldEvaluateNewTelemetry(currentTimestamp)) {
|
||||
this.updateConditionResults(normalizedDatum);
|
||||
this.updateConditionResults();
|
||||
this.updateCurrentCondition(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
updateConditionResults(normalizedDatum) {
|
||||
updateConditionResults() {
|
||||
//We want to stop when the first condition evaluates to true.
|
||||
this.conditions.some((condition) => {
|
||||
condition.updateResult(normalizedDatum);
|
||||
condition.updateResult(this.#latestDataTable);
|
||||
|
||||
return condition.result === true;
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user