Skip to content

Commit

Permalink
Merge pull request #1403 from CarnegieLearningWeb/bug/fix-1396-used-t…
Browse files Browse the repository at this point in the history
…ooltip

Solved multiple instance of experiments issue
  • Loading branch information
RidhamShah authored Apr 9, 2024
2 parents 894138f + 8c3ea1c commit 5585f66
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const upload = multer({ storage: storage });
@Authorized()
@JsonController('/stratification')
export class StratificationController {
constructor(public stratificatonService: StratificationService) {}
constructor(public stratificationService: StratificationService) {}

/**
* @swagger
Expand All @@ -82,7 +82,7 @@ export class StratificationController {
*/
@Get()
public async getAllStratification(@Req() request: AppRequest): Promise<FactorStrata[]> {
return this.stratificatonService.getAllStratification(request.logger);
return this.stratificationService.getAllStratification(request.logger);
}

/**
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -160,7 +160,7 @@ export class StratificationController {
@Post()
@UseBefore(upload.single('file'))
public insertStratification(@Req() request: AppRequest): Promise<UserStratificationFactor[]> {
return this.stratificatonService.insertStratification(request.body[0].file, request.logger);
return this.stratificationService.insertStratification(request.body[0].file, request.logger);
}

/**
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
};
}
);
Expand Down Expand Up @@ -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[]) {
Expand Down

0 comments on commit 5585f66

Please sign in to comment.