-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcov_map.py
More file actions
70 lines (55 loc) · 1.66 KB
/
cov_map.py
File metadata and controls
70 lines (55 loc) · 1.66 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
#!/usr/bin/env python3
import json
import polars as pl
import plotly.express as px
COV_JSON_PATH = "cov.json"
OUTPUT_PATH = "treemap"
def load_file_level_cov(json_path):
with open(json_path, "r") as f:
raw = json.load(f)
rows = []
for file in raw["data"][0]["files"]:
path = file["filename"]
if "summary" not in file:
continue
summary = file["summary"]
total = summary["regions"]["count"]
covered = summary["regions"]["covered"]
if total == 0:
continue
name = path.split("/")[-1]
dir_ = path.split("/")[-2] if "/" in path else ""
rows.append(
{
"dir": dir_,
"file": name,
"Covered Percentage (%)": covered / total * 100,
"regions": total,
}
)
return pl.DataFrame(rows)
def plot_treemap(df: pl.DataFrame, output="treemap"):
fig = px.treemap(
df.to_dict(),
path=["dir", "file"],
values="regions",
color="Covered Percentage (%)",
color_continuous_scale="RdYlGn",
color_continuous_midpoint=50,
width=1000,
height=700,
)
fig.update_layout(
uniformtext=dict(minsize=12),
margin=dict(t=30, l=0, r=0, b=0),
coloraxis_colorbar_title="Coverage %",
)
fig.write_html(output + ".html")
fig.write_image(output + ".svg")
print(f"[+] Treemap saved to {output}")
if __name__ == "__main__":
df = load_file_level_cov(COV_JSON_PATH)
if df.is_empty():
print("[!] No file coverage data found in cov.json")
else:
plot_treemap(df, OUTPUT_PATH)