Skip to content

Commit

Permalink
Update XLS report
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrunet committed Sep 25, 2023
1 parent 5efd841 commit 816cd31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class MultiScanData {
stringHash(item.ruleId + item.path.dom),
valueMap[item.value[0]][item.value[1]],
parseInt(rule_map.get(item.ruleId).toolkitLevel), // make number instead of text for spreadsheet
this.checkpoints_string(rule_checkpoints_map, item.ruleId),
this.checkpoints_string(rule_checkpoints_map, item.ruleId, item.reasonId),
this.wcag_string(rule_checkpoints_map, item.ruleId),
item.ruleId,
item.message.substring(0, 32767), //max ength for MS Excel 32767 characters
Expand All @@ -104,13 +104,17 @@ export default class MultiScanData {
return ret;
}

public static checkpoints_string(rule_checkpoints_map: any, rule_id: string) {
public static checkpoints_string(rule_checkpoints_map: any, rule_id: string, reasonId: string) {

let checkpoint_string = '';

let checkpoint_array = rule_checkpoints_map.get(rule_id);

for (let checkpoint of checkpoint_array) {
console.log(checkpoint);
let ruleInfo = checkpoint.rules.find((rule: any) => rule.id === rule_id);
console.log(ruleInfo);
if (ruleInfo.reasonCodes && !ruleInfo.reasonCodes.includes(reasonId)) continue;
if (checkpoint_string.length > 1) {
checkpoint_string = checkpoint_string + '; ';
}
Expand Down Expand Up @@ -175,25 +179,17 @@ export default class MultiScanData {
let checkpoint_map = new Map();

for (let checkpoint of checkpoints) {

let temp_checkpoint = {
name: checkpoint.name,
num: checkpoint.num,
summary: checkpoint.summary,
wcagLevel: checkpoint.wcagLevel
}

let rules = checkpoint.rules;

if (rules && rules.length > 0) {
for (let rule of rules) {

if (!checkpoint_map.get(rule.id)) {

checkpoint_map.set(rule.id, [temp_checkpoint]);
checkpoint_map.set(rule.id, [checkpoint]);
} else {
let checkpoint_array = checkpoint_map.get(rule.id);
checkpoint_array.push(temp_checkpoint);
checkpoint_array.push(checkpoint);
checkpoint_map.set(rule.id, checkpoint_array);
}
}
Expand Down
26 changes: 13 additions & 13 deletions common/module/src/report/ACReporterXLSX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
*****************************************************************************/

import { IConfigInternal, eRuleLevel } from "../config/IConfig";
import { Guideline, eToolkitLevel } from "../engine/IGuideline";
import { Checkpoint, Guideline, eToolkitLevel } from "../engine/IGuideline";
import { CompressedReport } from "../engine/IReport";
import { eRuleConfidence } from "../engine/IRule";
import { GenSummReturn, IReporter, ReporterManager } from "./ReporterManager";
import * as ExcelJS from "exceljs";

type PolicyInfo = {
tkLevels: eToolkitLevel[]
wcagLevels: string[]
cps: string[]
cps: Checkpoint[]
};

function dropDupes<T>(arr: T[]): T[] {
Expand Down Expand Up @@ -56,22 +55,18 @@ export class ACReporterXLSX implements IReporter {
for (const rule of cp.rules) {
policyInfo[rule.id] = policyInfo[rule.id] || {
tkLevels: [],
wcagLevels: [],
cps: []
}
policyInfo[rule.id].tkLevels.push(rule.toolkitLevel);
policyInfo[rule.id].wcagLevels.push(cp.wcagLevel);
policyInfo[rule.id].cps.push(`${cp.num}`);
policyInfo[rule.id].cps.push(cp);
}
}
}
for (const ruleId in policyInfo) {
policyInfo[ruleId].tkLevels = dropDupes(policyInfo[ruleId].tkLevels);
policyInfo[ruleId].cps = dropDupes(policyInfo[ruleId].cps);
policyInfo[ruleId].wcagLevels = dropDupes(policyInfo[ruleId].wcagLevels);
policyInfo[ruleId].tkLevels.sort();
policyInfo[ruleId].cps.sort();
policyInfo[ruleId].wcagLevels.sort();
}

// const buffer: any = await workbook.xlsx.writeBuffer();
Expand Down Expand Up @@ -486,7 +481,6 @@ export class ACReporterXLSX implements IReporter {
if (!(issue.ruleId in policyInfo)) {
policyInfo[issue.ruleId] = {
tkLevels: [],
wcagLevels: [],
cps: []
}
}
Expand Down Expand Up @@ -702,19 +696,25 @@ export class ACReporterXLSX implements IReporter {
if (!(item.ruleId in policyInfo)) {
policyInfo[item.ruleId] = {
tkLevels: [],
wcagLevels: [],
cps: []
}
}
let polInfo = policyInfo[item.ruleId];
let cps = polInfo.cps.filter(cp => {
let ruleInfo = cp.rules.find(ruleInfo => ruleInfo.id === item.ruleId && (!ruleInfo.reasonCodes || ruleInfo.reasonCodes.includes(""+item.reasonId)));
return !!ruleInfo;
})
let wcagLevels = dropDupes(cps.map(cp => cp.wcagLevel));
wcagLevels.sort();
let row = [
storedScan.pageTitle,
storedScan.engineReport.summary.URL,
storedScan.label,
this.stringHash(item.ruleId + item.path.dom),
`${valueMap[item.value[0]][item.value[1]]}${item.ignored ? ` (Archived)` : ``}`,
policyInfo[item.ruleId].tkLevels.join(", "),
policyInfo[item.ruleId].cps.join(", "),
policyInfo[item.ruleId].wcagLevels.join(", "),
polInfo.tkLevels.join(", "),
cps.join(", "),
wcagLevels.join(", "),
item.ruleId,
item.message.substring(0, 32767), //max ength for MS Excel 32767 characters
this.get_element(item.snippet),
Expand Down

0 comments on commit 816cd31

Please sign in to comment.