Skip to content

Commit

Permalink
MAT-7238: refactor how stratification worksheets are created and adde…
Browse files Browse the repository at this point in the history
…d to only create one worksheet per group stratification
  • Loading branch information
nmorasb committed May 23, 2024
1 parent 6b76ec9 commit 2b6d0cf
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions src/services/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
TestCaseExcelExportDto,
PopulationDto,
StratificationDto,
GroupedStratificationDto,
} from '@madie/madie-models';

@Injectable()
Expand All @@ -42,22 +41,36 @@ export class ExportService {
index += 1;
});

// collect all the distinct stratifications by stratification name
const stratNames = new Set<string>();
const stratNamesToGroup = {};
testCaseExcelExportDtos.forEach((testCaseExcelExportDto) => {
testCaseExcelExportDto.testCaseExecutionResults.forEach((result) => {
result.stratifications?.forEach((stratification) => {
const stratificationWorksheet = workbook.addWorksheet(
`${index} - ${stratification.stratName}`,
);
this.generateStratificationWorksheet(
stratificationWorksheet,
testCaseExcelExportDto,
stratification,
);
index += 1;
stratNames.add(stratification.stratName);
stratNamesToGroup[stratification.stratName] =
testCaseExcelExportDto.groupId;
});
});
});

// create a worksheet for each stratification
for (const stratName of stratNames) {
const groupId = stratNamesToGroup[stratName];
const stratificationWorksheet = workbook.addWorksheet(
`${index} - ${stratName}`,
);
const testCaseExcelExportDto = testCaseExcelExportDtos.find(
(dto) => dto.groupId === groupId,
);
this.generateStratificationWorksheet(
stratificationWorksheet,
stratName,
testCaseExcelExportDto,
);
index++;
}

// Return final workbook
return workbook.xlsx.writeBuffer() as Promise<Buffer>;
}
Expand Down Expand Up @@ -350,8 +363,8 @@ export class ExportService {

public generateStratificationWorksheet(
worksheet: ExcelJS.Worksheet,
stratName: string,
testCaseGroupDto: TestCaseExcelExportDto,
groupedStratificationDto: GroupedStratificationDto,
) {
let firstRow = [];
let headerRow = [];
Expand All @@ -366,6 +379,15 @@ export class ExportService {
const firstRowData = [];
const headerRowData = [];
const testCaseData = [];
const groupedStratificationDto = result.stratifications?.find(
(s) => s.stratName === stratName,
);
if (
undefined === groupedStratificationDto ||
null === groupedStratificationDto
) {
return;
}

const numValues: number =
groupedStratificationDto.stratificationDtos?.length;
Expand Down

0 comments on commit 2b6d0cf

Please sign in to comment.