From e209c47a3ae1ea2044e947a5e5613ed6a14699d6 Mon Sep 17 00:00:00 2001 From: Yagnik Date: Mon, 18 Mar 2024 09:43:32 +0530 Subject: [PATCH 1/5] Persist code changes in condition table which aren't related to factor table update --- .../experiment-design-stepper.service.ts | 34 ++++++++++++++++++- .../conditions-table.component.ts | 15 +++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/frontend/projects/upgrade/src/app/core/experiment-design-stepper/experiment-design-stepper.service.ts b/frontend/projects/upgrade/src/app/core/experiment-design-stepper/experiment-design-stepper.service.ts index 94b46535ea..1adb70f9e7 100644 --- a/frontend/projects/upgrade/src/app/core/experiment-design-stepper/experiment-design-stepper.service.ts +++ b/frontend/projects/upgrade/src/app/core/experiment-design-stepper/experiment-design-stepper.service.ts @@ -377,6 +377,38 @@ export class ExperimentDesignStepperService { return tableData; } + editFactorialConditionTableData( + designData: ExperimentFactorialDesignData, + oldTableData: FactorialConditionTableRowData[] + ): FactorialConditionTableRowData[] { + const tableData: FactorialConditionTableRowData[] = []; + const requiredFactorialTableData = this.factorDataToConditions(designData.factors); + + requiredFactorialTableData.map((conditionData) => { + const conditionLevelsData = this.filterLevelsData(conditionData); + const conditionstring = this.createConditionString(conditionData); + const condition = oldTableData.filter((conditionData) => { + return conditionData.condition === conditionstring; + }); + + if (condition.length) { + tableData.push({ ...condition[0], id: uuidv4() }); + } else { + const tableRow: FactorialConditionTableRowData = { + id: uuidv4(), // TODO: maybe not the right place? + levels: conditionLevelsData, + condition: conditionstring, + payload: conditionstring, + weight: '0.0', + include: true, + }; + tableData.push(tableRow); + } + }); + + return tableData; + } + factorDataToConditions(factorsData: ExperimentFactorData[], levelsCombinationData: FactorLevelData[] = []) { // return if no data in factors if (factorsData.length === 0) { @@ -485,7 +517,7 @@ export class ExperimentDesignStepperService { let conditionIndex = 1; tableData.forEach((factorialConditionTableRow) => { factorialConditionsRequestObject.push({ - id: factorialConditionTableRow.id, + id: factorialConditionTableRow.id || uuidv4(), name: factorialConditionTableRow.condition, conditionCode: factorialConditionTableRow.condition, assignmentWeight: parseFloat(factorialConditionTableRow.weight), diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts index 39d5fd2b45..38264f0f03 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts @@ -105,7 +105,7 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { } else { // if new exp and form initialized and you move back and forth // if edit exp and form already initialized - this.handleInitializeNewNewTableData(designData); // <---- be careful doing this! if you see bugs, it may be because this is not the intended place for this function + this.handleUpdateDesignDataTableChanges(designData); // <---- be careful doing this! if you see bugs, it may be because this is not the intended place for this function // this.handleUpdateDesignDataTableChanges(designData); } } @@ -125,9 +125,14 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { this.initializeForm(newTableData); } - // handleUpdateDesignDataTableChanges(designData: ExperimentFactorialDesignData) { - // // TODO: intelligently handle updates to design data without triggering complete table re-creation - // } + handleUpdateDesignDataTableChanges(designData: ExperimentFactorialDesignData) { + // TODO: intelligently handle updates to design data without triggering complete table re-creation + const newTableData = this.experimentDesignStepperService.editFactorialConditionTableData( + designData, + this.factorialConditionTableForm.value.factorialConditions + ); + this.initializeForm(newTableData); + } initializeForm(tableData: FactorialConditionTableRowData[]) { this.createFormControls(tableData); @@ -198,7 +203,7 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { this.equalWeightFlag = !this.equalWeightFlag; if (this.equalWeightFlag) { - const newTableData = this.applyEqualWeights(); + const newTableData = this.applyEqualWeights(this.factorialConditionTableForm.value.factorialConditions); this.experimentDesignStepperService.updateFactorialConditionTableData(newTableData); } } From fdb81aa6ca7e1fc42ac1e298d8198feb2428e6d6 Mon Sep 17 00:00:00 2001 From: Yagnik Date: Mon, 18 Mar 2024 09:49:40 +0530 Subject: [PATCH 2/5] Code clean up --- .../conditions-table/conditions-table.component.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts index 38264f0f03..a0017a9107 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts @@ -105,8 +105,7 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { } else { // if new exp and form initialized and you move back and forth // if edit exp and form already initialized - this.handleUpdateDesignDataTableChanges(designData); // <---- be careful doing this! if you see bugs, it may be because this is not the intended place for this function - // this.handleUpdateDesignDataTableChanges(designData); + this.handleUpdateDesignDataTableChanges(designData); } } @@ -126,7 +125,6 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { } handleUpdateDesignDataTableChanges(designData: ExperimentFactorialDesignData) { - // TODO: intelligently handle updates to design data without triggering complete table re-creation const newTableData = this.experimentDesignStepperService.editFactorialConditionTableData( designData, this.factorialConditionTableForm.value.factorialConditions From 8a9fd62fd707656d0df80ffea214de9d03e9f7bc Mon Sep 17 00:00:00 2001 From: Yagnik Date: Tue, 19 Mar 2024 14:52:18 +0530 Subject: [PATCH 3/5] resolved issue of condition values not persisting while creating new experiment --- .../conditions-table.component.html | 4 +-- .../conditions-table.component.ts | 33 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.html b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.html index b9be5a051e..7115679be2 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.html +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.html @@ -152,8 +152,8 @@ >
- {{ conditionweightSumError }} - {{ conditionnegativeweightError }} + {{ conditionWeightSumError }} + {{ conditionNegativeWeightError }}
diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts index a0017a9107..5d90adf922 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts @@ -35,8 +35,8 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { useEllipsis = false; // Condition Errors - conditionweightSumError: string = null; - conditionnegativeweightError: string = null; + conditionWeightSumError: string = null; + conditionNegativeWeightError: string = null; constructor( private experimentDesignStepperService: ExperimentDesignStepperService, @@ -98,9 +98,10 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { } handleDesignDataChanges(designData: ExperimentFactorialDesignData) { - if (this.experimentInfo?.partitions.length && !this.formInitialized && !this.isAnyRowRemoved) { + const isDesignDataValid = this.checkDesignDataValidity(designData); + if (this.experimentInfo?.partitions.length && !this.isAnyRowRemoved && !this.formInitialized) { this.handleInitializeExistingTableData(); - } else if (!this.experimentInfo && this.formInitialized && !this.isAnyRowRemoved) { + } else if (!this.experimentInfo && !this.isAnyRowRemoved && (!this.formInitialized || !isDesignDataValid)) { this.handleInitializeNewNewTableData(designData); } else { // if new exp and form initialized and you move back and forth @@ -127,11 +128,23 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { handleUpdateDesignDataTableChanges(designData: ExperimentFactorialDesignData) { const newTableData = this.experimentDesignStepperService.editFactorialConditionTableData( designData, - this.factorialConditionTableForm.value.factorialConditions + this.tableData$.value ); this.initializeForm(newTableData); } + checkDesignDataValidity(designData: ExperimentFactorialDesignData) { + let isDesignDataValid = true; + if (designData.factors.length > 1) { + designData.factors.forEach((factor) => { + if (!factor.levels[0].name) { + isDesignDataValid = false; + } + }); + } + return isDesignDataValid; + } + initializeForm(tableData: FactorialConditionTableRowData[]) { this.createFormControls(tableData); const newTableData = this.applyEqualWeights(tableData); @@ -174,18 +187,18 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { factorialConditions.forEach((condition) => (sumOfAssignmentWeights += parseFloat(condition.weight))); // checking if sum is not equal to 100 if (Math.round(sumOfAssignmentWeights) !== 100.0) { - this.conditionweightSumError = weightSumNot100ErrorMsg; + this.conditionWeightSumError = weightSumNot100ErrorMsg; } else { - this.conditionweightSumError = null; + this.conditionWeightSumError = null; } } validateWeightsNotNegative(factorialConditions: FactorialConditionTableRowData[]) { - this.conditionnegativeweightError = null; - const negativeweightErrorMsg = this.translate.instant('home.new-experiment.design.assignment-weight-negative.text'); + this.conditionNegativeWeightError = null; + const negativeWeightErrorMsg = this.translate.instant('home.new-experiment.design.assignment-weight-negative.text'); // handling sum of decimal values for assignment weights: factorialConditions.forEach((condition) => - parseFloat(condition.weight) < 0 ? (this.conditionnegativeweightError = negativeweightErrorMsg) : null + parseFloat(condition.weight) < 0 ? (this.conditionNegativeWeightError = negativeWeightErrorMsg) : null ); } From f8111cafb4142457f27c142024db037665e2f2fe Mon Sep 17 00:00:00 2001 From: Yagnik Date: Wed, 20 Mar 2024 10:04:05 +0530 Subject: [PATCH 4/5] resolved review comment to remove isAnyRowRemoved --- .../conditions-table/conditions-table.component.ts | 5 ++--- .../factorial-experiment-design.component.html | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts index 5d90adf922..6926a07104 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/conditions-table/conditions-table.component.ts @@ -17,7 +17,6 @@ import { ExperimentVM } from '../../../../../../core/experiments/store/experimen }) export class ConditionsTableComponent implements OnInit, OnDestroy { @Input() experimentInfo: ExperimentVM; - @Input() isAnyRowRemoved: boolean; @Input() isExperimentEditable: boolean; subscriptions: Subscription; @@ -99,9 +98,9 @@ export class ConditionsTableComponent implements OnInit, OnDestroy { handleDesignDataChanges(designData: ExperimentFactorialDesignData) { const isDesignDataValid = this.checkDesignDataValidity(designData); - if (this.experimentInfo?.partitions.length && !this.isAnyRowRemoved && !this.formInitialized) { + if (this.experimentInfo?.partitions.length && (!this.formInitialized || !isDesignDataValid)) { this.handleInitializeExistingTableData(); - } else if (!this.experimentInfo && !this.isAnyRowRemoved && (!this.formInitialized || !isDesignDataValid)) { + } else if (!this.experimentInfo && (!this.formInitialized || !isDesignDataValid)) { this.handleInitializeNewNewTableData(designData); } else { // if new exp and form initialized and you move back and forth diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.html b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.html index 5d23edf2f8..60fde75126 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.html +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.html @@ -772,7 +772,6 @@

From 508ee060d1b466d2729dd248342b4eba985b2694 Mon Sep 17 00:00:00 2001 From: Yagnik Date: Wed, 20 Mar 2024 19:44:32 +0530 Subject: [PATCH 5/5] resolved review comment to remove isAnyRowRemoved in factorial design stepper comp --- .../factorial-experiment-design.component.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.ts index f91b81a89a..5349dadda1 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/factorial-experiment-design/factorial-experiment-design.component.ts @@ -97,7 +97,6 @@ export class FactorialExperimentDesignComponent implements OnInit, OnChanges, On conditionTableDataUpToDate = true; isExperimentEditable = true; - isAnyRowRemoved = false; // common lock variable for all tables: isFormLockedForEdit$ = this.experimentDesignStepperService.isFormLockedForEdit$; @@ -370,7 +369,6 @@ export class FactorialExperimentDesignComponent implements OnInit, OnChanges, On removeFactor(groupIndex: number) { this.factor.removeAt(groupIndex); this.handleConditionsButtonClick(); - this.isAnyRowRemoved = true; this.experimentDesignStepperService.experimentStepperDataChanged(); this.experimentDesignStepperService.clearFactorialFactorTableEditModeDetails(); this.updateView('factorTable'); @@ -382,7 +380,6 @@ export class FactorialExperimentDesignComponent implements OnInit, OnChanges, On removeLevel(factorIndex: number, levelIndex: number) { this.getFactorialLevelsAt(factorIndex).removeAt(levelIndex); this.handleConditionsButtonClick(); - this.isAnyRowRemoved = true; this.experimentDesignStepperService.experimentStepperDataChanged(); this.experimentDesignStepperService.clearFactorialLevelTableEditModeDetails(); this.updateView('levelTable'); @@ -777,7 +774,6 @@ export class FactorialExperimentDesignComponent implements OnInit, OnChanges, On if (eventType == NewExperimentDialogEvents.SAVE_DATA) { this.experimentDesignStepperService.experimentStepperDataReset(); - this.isAnyRowRemoved = false; this.factorialExperimentDesignForm.markAsPristine(); } }