From 1fb8afef905def6d8ac62d549c22559ce81d6886 Mon Sep 17 00:00:00 2001 From: RidhamShah Date: Fri, 29 Mar 2024 10:32:14 +0530 Subject: [PATCH] Solved multiple instance of experiments issue --- .../controllers/StratificationController.ts | 10 +++++----- .../src/api/services/StratificationService.ts | 2 +- .../stratification-factor-list.component.ts | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/backend/packages/Upgrade/src/api/controllers/StratificationController.ts b/backend/packages/Upgrade/src/api/controllers/StratificationController.ts index 964d75bf5d..1f5ea8fd2c 100644 --- a/backend/packages/Upgrade/src/api/controllers/StratificationController.ts +++ b/backend/packages/Upgrade/src/api/controllers/StratificationController.ts @@ -59,7 +59,7 @@ const upload = multer({ storage: storage }); @Authorized() @JsonController('/stratification') export class StratificationController { - constructor(public stratificatonService: StratificationService) {} + constructor(public stratificationService: StratificationService) {} /** * @swagger @@ -82,7 +82,7 @@ export class StratificationController { */ @Get() public async getAllStratification(@Req() request: AppRequest): Promise { - return this.stratificatonService.getAllStratification(request.logger); + return this.stratificationService.getAllStratification(request.logger); } /** @@ -121,7 +121,7 @@ export class StratificationController { return Promise.reject(new Error(SERVER_ERROR.MISSING_PARAMS + ' : stratification Factor should not be null.')); } - const csvData = await this.stratificatonService.getCSVDataByFactor(factor, request.logger); + const csvData = await this.stratificationService.getCSVDataByFactor(factor, request.logger); // return csv file with appropriate headers to request; res.setHeader('Content-Type', 'text/csv; charset=UTF-8'); @@ -160,7 +160,7 @@ export class StratificationController { @Post() @UseBefore(upload.single('file')) public insertStratification(@Req() request: AppRequest): Promise { - return this.stratificatonService.insertStratification(request.body[0].file, request.logger); + return this.stratificationService.insertStratification(request.body[0].file, request.logger); } /** @@ -197,6 +197,6 @@ export class StratificationController { if (!stratificationFactor) { return Promise.reject(new Error(SERVER_ERROR.MISSING_PARAMS + ' : stratification Factor should not be null.')); } - return this.stratificatonService.deleteStratification(stratificationFactor, request.logger); + return this.stratificationService.deleteStratification(stratificationFactor, request.logger); } } diff --git a/backend/packages/Upgrade/src/api/services/StratificationService.ts b/backend/packages/Upgrade/src/api/services/StratificationService.ts index a7d89cd83e..7137035042 100644 --- a/backend/packages/Upgrade/src/api/services/StratificationService.ts +++ b/backend/packages/Upgrade/src/api/services/StratificationService.ts @@ -22,7 +22,7 @@ export class StratificationService { ): FactorStrata[] { const formattedResults = results.reduce((formatted, result) => { const { factor, value, count, experimentIds } = result; - const expIds = experimentIds.filter((experimentId) => !!experimentId); + const expIds = new Set(experimentIds.filter((experimentId) => !!experimentId)); if (!formatted[factor]) { formatted[factor] = { factor, factorValue: {}, experimentIds: expIds }; } diff --git a/frontend/projects/upgrade/src/app/features/dashboard/experiment-users/components/stratification-factor-list/stratification-factor-list.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/experiment-users/components/stratification-factor-list/stratification-factor-list.component.ts index 39efe2ddf1..2c2e43d7a3 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/experiment-users/components/stratification-factor-list/stratification-factor-list.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/experiment-users/components/stratification-factor-list/stratification-factor-list.component.ts @@ -6,6 +6,8 @@ import { DeleteStratificationComponent } from './delete-stratification/delete-st import { StratificationFactor } from '../../../../../core/stratification-factors/store/stratification-factors.model'; import { Subscription } from 'rxjs'; import { StratificationFactorsService } from '../../../../../core/stratification-factors/stratification-factors.service'; +import { ExperimentService } from '../../../../../core/experiments/experiments.service'; +import { ExperimentNameVM } from '../../../../../core/experiments/store/experiments.model'; interface StratificationFactorsTableRow { factor: string; @@ -26,10 +28,18 @@ export class StratificationComponent implements OnInit { isLoading$ = this.stratificationFactorsService.isLoading$; stratificationFactorsForTable: StratificationFactorsTableRow[] = []; displayedColumns: string[] = ['factor', 'status', 'summary', 'actions']; + allExperimentsName: ExperimentNameVM[]; - constructor(private dialog: MatDialog, private stratificationFactorsService: StratificationFactorsService) {} + constructor( + private dialog: MatDialog, + private stratificationFactorsService: StratificationFactorsService, + private experimentService: ExperimentService + ) {} ngOnInit(): void { + this.experimentService.allExperimentNames$.subscribe((allExperimentNames) => { + this.allExperimentsName = allExperimentNames; + }); this.allStratificationFactorsSub = this.stratificationFactorsService.allStratificationFactors$.subscribe( (allStratificationFactors) => { this.allStratificationFactors = allStratificationFactors; @@ -54,11 +64,14 @@ export class StratificationComponent implements OnInit { factorSummary = totalUsers.toString() + ' ' + factorSummary + ' (' + tempSummary + ')'; + const experimentNamesToShow = stratificationFactor.experimentIds.map((experimentId) => { + return this.allExperimentsName.find((experiment) => experiment.id === experimentId)?.name; + }); return { factor: stratificationFactor.factor, summary: factorSummary, isUsed: this.checkStratificationFactorUsageStatus(stratificationFactor.experimentIds), - experimentIds: stratificationFactor.experimentIds, + experimentIds: experimentNamesToShow, }; } ); @@ -101,7 +114,7 @@ export class StratificationComponent implements OnInit { } getExperimentIdsTooltip(experimentIds: any[]): string { - return 'Experiment IDs: [' + experimentIds?.join(', ') + ']'; + return 'Experiments: [' + experimentIds?.join(', ') + ']'; } checkStratificationFactorUsageStatus(experimentIds: string[]) {