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);
|
this.handleTelemetryStaleness = this.handleTelemetryStaleness.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateResult(datum) {
|
updateResult(latestDataTable) {
|
||||||
if (!datum || !datum.id) {
|
if (!latestDataTable) {
|
||||||
console.log('no data received');
|
console.log('no data received');
|
||||||
|
|
||||||
return;
|
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 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) => {
|
this.criteria.forEach((criterion) => {
|
||||||
if (this.isAnyOrAllTelemetry(criterion)) {
|
if (this.isAnyOrAllTelemetry(criterion)) {
|
||||||
criterion.updateResult(datum, this.conditionManager.telemetryObjects);
|
criterion.updateResult(latestDataTable, this.conditionManager.telemetryObjects);
|
||||||
} else {
|
} else {
|
||||||
if (criterion.usesTelemetry(datum.id)) {
|
const relevantDatum = latestDataTable.get(criterion.telemetryObjectIdAsString);
|
||||||
criterion.updateResult(datum);
|
|
||||||
|
if (relevantDatum !== undefined){
|
||||||
|
criterion.updateResult(relevantDatum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -94,7 +97,7 @@ export default class Condition extends EventEmitter {
|
|||||||
this.criteria.map((criterion) => criterion.result),
|
this.criteria.map((criterion) => criterion.result),
|
||||||
this.trigger
|
this.trigger
|
||||||
);
|
);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
isAnyOrAllTelemetry(criterion) {
|
isAnyOrAllTelemetry(criterion) {
|
||||||
|
@ -27,6 +27,8 @@ import Condition from './Condition.js';
|
|||||||
import { getLatestTimestamp } from './utils/time.js';
|
import { getLatestTimestamp } from './utils/time.js';
|
||||||
|
|
||||||
export default class ConditionManager extends EventEmitter {
|
export default class ConditionManager extends EventEmitter {
|
||||||
|
#latestDataTable = new Map();
|
||||||
|
|
||||||
constructor(conditionSetDomainObject, openmct) {
|
constructor(conditionSetDomainObject, openmct) {
|
||||||
super();
|
super();
|
||||||
this.openmct = openmct;
|
this.openmct = openmct;
|
||||||
@ -410,19 +412,22 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
|
|
||||||
const normalizedDatum = this.createNormalizedDatum(datum, endpoint);
|
const normalizedDatum = this.createNormalizedDatum(datum, endpoint);
|
||||||
const timeSystemKey = this.openmct.time.getTimeSystem().key;
|
const timeSystemKey = this.openmct.time.getTimeSystem().key;
|
||||||
let timestamp = {};
|
|
||||||
const currentTimestamp = normalizedDatum[timeSystemKey];
|
const currentTimestamp = normalizedDatum[timeSystemKey];
|
||||||
|
const timestamp = {};
|
||||||
|
|
||||||
timestamp[timeSystemKey] = currentTimestamp;
|
timestamp[timeSystemKey] = currentTimestamp;
|
||||||
|
this.#latestDataTable.set(normalizedDatum.id, normalizedDatum);
|
||||||
|
|
||||||
if (this.shouldEvaluateNewTelemetry(currentTimestamp)) {
|
if (this.shouldEvaluateNewTelemetry(currentTimestamp)) {
|
||||||
this.updateConditionResults(normalizedDatum);
|
this.updateConditionResults();
|
||||||
this.updateCurrentCondition(timestamp);
|
this.updateCurrentCondition(timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateConditionResults(normalizedDatum) {
|
updateConditionResults() {
|
||||||
//We want to stop when the first condition evaluates to true.
|
//We want to stop when the first condition evaluates to true.
|
||||||
this.conditions.some((condition) => {
|
this.conditions.some((condition) => {
|
||||||
condition.updateResult(normalizedDatum);
|
condition.updateResult(this.#latestDataTable);
|
||||||
|
|
||||||
return condition.result === true;
|
return condition.result === true;
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user