Addresses comments - change function names, consolidate compute function

This commit is contained in:
Joshi 2020-01-28 16:27:30 -08:00
parent b3488c54cd
commit e419149378
3 changed files with 12 additions and 31 deletions

View File

@ -24,7 +24,7 @@ import * as EventEmitter from 'eventemitter3';
import uuid from 'uuid'; import uuid from 'uuid';
import TelemetryCriterion from "@/plugins/condition/criterion/TelemetryCriterion"; import TelemetryCriterion from "@/plugins/condition/criterion/TelemetryCriterion";
import { TRIGGER } from "@/plugins/condition/utils/constants"; import { TRIGGER } from "@/plugins/condition/utils/constants";
import {computeConditionForAll, computeConditionForAny} from "@/plugins/condition/utils/evaluator"; import {computeCondition} from "@/plugins/condition/utils/evaluator";
/* /*
* conditionDefinition = { * conditionDefinition = {
@ -228,11 +228,7 @@ export default class ConditionClass extends EventEmitter {
//TODO: implement as part of the evaluator class task. //TODO: implement as part of the evaluator class task.
evaluate() { evaluate() {
if (this.trigger === TRIGGER.ANY) { this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
this.result = computeConditionForAny(this.criteriaResults);
} else if (this.trigger === TRIGGER.ALL) {
this.result = computeConditionForAll(this.criteriaResults);
}
} }
emitEvent(eventName, data) { emitEvent(eventName, data) {

View File

@ -89,7 +89,7 @@
<span class="t-configuration"> <span class="t-configuration">
<span class="controls"> <span class="controls">
<select v-model="selectedTelemetryKey" <select v-model="selectedTelemetryKey"
@change="telemetryChange" @change="updateTelemetryMetaData"
> >
<option value="">- Select Telemetry -</option> <option value="">- Select Telemetry -</option>
<option v-for="telemetryOption in telemetry" <option v-for="telemetryOption in telemetry"
@ -113,7 +113,7 @@
</span> </span>
<span class="controls"> <span class="controls">
<select v-model="selectedOperationKey" <select v-model="selectedOperationKey"
@change="operationKeyChange" @change="setInputValueVisibility"
> >
<option value="">- Select Comparison -</option> <option value="">- Select Comparison -</option>
<option v-for="option in operations" <option v-for="option in operations"
@ -324,7 +324,7 @@ export default {
this.condition.definition.output = this.selectedOutputKey; this.condition.definition.output = this.selectedOutputKey;
} }
}, },
operationKeyChange(ev) { setInputValueVisibility(ev) {
if (this.selectedOperationKey !== 'isUndefined' && this.selectedOperationKey !== 'isDefined') { if (this.selectedOperationKey !== 'isUndefined' && this.selectedOperationKey !== 'isDefined') {
this.comparisonValueField = true; this.comparisonValueField = true;
} else { } else {
@ -332,7 +332,7 @@ export default {
} }
//find the criterion being updated and set the operation property //find the criterion being updated and set the operation property
}, },
telemetryChange() { updateTelemetryMetaData() {
this.selectedMetaDataKey = ''; this.selectedMetaDataKey = '';
this.updateConditionCriteria(); this.updateConditionCriteria();
this.updateTelemetry(); this.updateTelemetry();

View File

@ -1,28 +1,13 @@
/** export const computeCondition = (resultMap, allMustBeTrue) => {
* Returns true only if at least one of the results is true
**/
export const computeConditionForAny = (resultMap) => {
let result = false; let result = false;
for (let key in resultMap) { for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) { if (resultMap.hasOwnProperty(key)) {
result = resultMap[key]; result = resultMap[key];
if (result) { if (allMustBeTrue && !result) {
break; //If we want all conditions to be true, then even one negative result should break.
} break;
} } else if (!allMustBeTrue && result) {
} //If we want at least one condition to be true, then even one positive result should break.
return result;
};
/**
* Returns true only if all the results are true
**/
export const computeConditionForAll = (resultMap) => {
let result = false;
for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) {
result = resultMap[key];
if (!result) {
break; break;
} }
} }