-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathisolated_nodes_statistics.py
99 lines (85 loc) · 3.14 KB
/
isolated_nodes_statistics.py
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
from dataclasses import dataclass
from prettytable import PrettyTable
from tqdm import tqdm
from .helpers import all_structures, num_structures, to_json, fetch_path
from click import command, option
@dataclass
class OverallStatistics:
open: int
merged: int
closed: int
total: int
@dataclass
class PRStatistics(OverallStatistics):
open: int
merged: int
closed: int
total: int
@dataclass
class IssueStatistics(OverallStatistics):
open: int
merged: int
closed: int
total: int
@command()
@option("--print", "print_total", default=False, is_flag=True)
def main(print_total: bool):
pr_statistics = PRStatistics(0, 0, 0, 0)
issue_statistics = IssueStatistics(0, 0, 0, 0)
# pull isolated nodes from data/structure_*, then grab node data from data/graph_*
pathlist = all_structures()
for path in tqdm(pathlist, total=num_structures(), leave=False):
isolated_nodes = []
path_str = str(path)
structure_json = to_json(path_str)
isolated_nodes = structure_json["1"]["isolated"]
isolated_nodes = [nested[0] for nested in isolated_nodes]
graph_json = to_json(fetch_path(path_str))
for isolated_node in isolated_nodes:
graph_node = next(filter(lambda g_node: g_node["id"] == isolated_node, graph_json["nodes"]))
to_modify = None
if graph_node["type"] == "pull_request":
to_modify = pr_statistics
else:
to_modify = issue_statistics
to_modify.total += 1
if graph_node["status"] == "open":
to_modify.open += 1
elif graph_node["status"] == "merged":
to_modify.merged += 1
else:
to_modify.closed += 1
table = PrettyTable()
table.field_names = ["Node Type", "Open", "Merged", "Closed", "Total"]
table.add_row(
[
"PR",
f"{pr_statistics.open/pr_statistics.total:.2%}",
f"{pr_statistics.merged/pr_statistics.total:.2%}",
f"{pr_statistics.closed/pr_statistics.total:.2%}",
f"{pr_statistics.total/(pr_statistics.total + issue_statistics.total):.2%}",
]
)
table.add_row(
[
"Issue",
f"{issue_statistics.open/issue_statistics.total:.2%}",
"—",
f"{issue_statistics.closed/issue_statistics.total:.2%}",
f"{issue_statistics.total/(pr_statistics.total + issue_statistics.total):.2%}",
]
)
table.add_row(
[
"Total",
f"{(pr_statistics.open + issue_statistics.open)/(pr_statistics.total + issue_statistics.total):.2%}",
f"{(pr_statistics.merged)/(pr_statistics.total + issue_statistics.total):.2%}",
f"{(pr_statistics.closed + issue_statistics.closed)/(pr_statistics.total + issue_statistics.total):.2%}",
f"{(pr_statistics.total + issue_statistics.total)/(pr_statistics.total + issue_statistics.total):.2%}",
],
)
print(table)
if print_total:
print(str(pr_statistics.total + issue_statistics.total) + " isolated components")
if __name__ == "__main__":
main()