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

View File

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

View File

@ -1,28 +1,13 @@
/**
* Returns true only if at least one of the results is true
**/
export const computeConditionForAny = (resultMap) => {
export const computeCondition = (resultMap, allMustBeTrue) => {
let result = false;
for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) {
result = resultMap[key];
if (result) {
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) {
if (allMustBeTrue && !result) {
//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.
break;
}
}