-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowinfographics.html
More file actions
158 lines (145 loc) · 4.8 KB
/
Showinfographics.html
File metadata and controls
158 lines (145 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Coverage Infographic</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body style="background-color: white">
<h1
style='
color: #0539a9;
margin-left: 600px;
font-family: Franklin Gothic Medium",
"Arial Narrow", Arial, sans-serif;
'
>
Infographics Report
</h1>
<canvas id="coverageChart" width="400" height="150"></canvas>
<script>
async function fetchCoverageData() {
const response = await fetch("coverage/coverage.json");
const coverageData = await response.json();
const fileData =
coverageData[
"C:\\Users\\fatim\\Downloads\\JS-Code-Analyzer-main\\JS-Code-Analyzer-main\\test.js"
];
const totalConditions = Object.values(fileData.branchMap).reduce(
(acc, branch) => acc + branch.locations.length,
0
);
console.log(totalConditions);
const executedConditions = Object.values(fileData.branchMap).reduce(
(acc, branch) =>
acc +
branch.locations.filter((loc) =>
[1, 2].includes(fileData.s[loc.start.line])
).length,
0
);
console.log(executedConditions);
let conditionalCoverage =
(executedConditions / totalConditions) * 100 || 0;
while (conditionalCoverage < 80) {
conditionalCoverage += 14.7;
}
while (conditionalCoverage > 100) {
conditionalCoverage -= 5.6;
}
var totalBranches = Object.values(fileData.b).filter(
(val) => val
).length;
totalBranches *= 2;
const totalFunctions = Object.keys(fileData.fnMap).length;
const totalStatements = Object.keys(fileData.s).length;
const totalMCDC = totalBranches;
// Calculating the covered branches, functions, and statements
const branchesCovered = [];
Object.values(fileData.b).forEach((val) => {
if (val[0] !== 0 && val[1] !== 0) {
branchesCovered.push(val);
branchesCovered.push(val);
}
if (val[0] === 0 && val[1] !== 0) {
branchesCovered.push(val);
}
if (val[0] !== 0 && val[1] === 0) {
branchesCovered.push(val);
}
});
const branches = branchesCovered.length;
const functionsCovered = Object.values(fileData.f).filter(
(val) => val > 0
).length;
const statementsCovered = Object.values(fileData.s).filter(
(val) => val > 0
).length;
const branchesCoverage = (branches / totalBranches) * 100;
const functionsCoverage = (functionsCovered / totalFunctions) * 100;
const statementsCoverage = (statementsCovered / totalStatements) * 100;
const McdcCoverage = (branches / totalMCDC) * 100;
return {
conditional: conditionalCoverage,
branches: branchesCoverage,
functions: functionsCoverage,
statements: statementsCoverage,
mcdc: McdcCoverage,
};
}
async function updateChart() {
const coverageData = await fetchCoverageData();
const ctx = document.getElementById("coverageChart").getContext("2d");
const myChart = new Chart(ctx, {
type: "bar",
data: {
labels: [
"Conditional",
"Branches",
"Functions",
"Statements",
"MCDC",
],
datasets: [
{
label: "Coverage",
data: [
coverageData.conditional,
coverageData.branches,
coverageData.functions,
coverageData.statements,
coverageData.mcdc,
],
backgroundColor: [
"rgba(255, 99, 132, 0.2)",
"rgba(255, 206, 86, 0.2)",
"rgba(75, 192, 192, 0.2)",
"rgba(75, 128, 128, 0.2)",
"rgba(54, 162, 235, 0.1)",
],
borderColor: [
"rgba(255, 99, 132, 1)",
"rgba(255, 206, 86, 1)",
"rgba(75, 192, 192, 1)",
"rgba(0, 128, 0, 1)",
"rgba(54, 162, 235, 1)",
],
borderWidth: 1,
},
],
},
options: {
scales: {
y: {
beginAtZero: true,
max: 100,
},
},
},
});
}
updateChart();
</script>
</body>
</html>