-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues.py
161 lines (142 loc) · 6.11 KB
/
issues.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
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
159
160
161
import glob
import json
import csv
import random
from pathlib import Path
from downloader import GitHubIssueDownloader
class Issues:
def __init__(
self,
download_path: str = ".",
filter_path: str = ".",
sample_path: str = ".",
auth: tuple = None,
) -> None:
self.filter_path = Path(filter_path)
self.download_path = Path(download_path)
self.sample_path = Path(sample_path)
self.downloader = GitHubIssueDownloader(download_path=download_path, auth=auth)
def download_issues(self):
self.downloader.download_issues()
def process_issues(self):
pytorch_issues_path = glob.glob(
f"{str(self.download_path)}/**/all_pytorch_issues.json", recursive=True
)
if pytorch_issues_path:
print("PyTorch issues found")
pytorch_issues = self._get_cached_issues(pytorch_issues_path[0])
print(f"Total PyTorch Issues: {len(pytorch_issues)}")
ptlf_pytorch_issues = list(
filter(lambda x: self._timeline_filter(x["timeline"]), pytorch_issues)
)
print(f"Filtered PT Issues: {len(ptlf_pytorch_issues)}")
self.pytorch_issues = self._issue_map(ptlf_pytorch_issues)
self._write_to_json(
self.filter_path, "filt_pytorch_issues.json", ptlf_pytorch_issues
)
self._write_issues_csv(
self.filter_path, "filt_pytorch_issues.csv", self.pytorch_issues
)
tf2onnx_issues_path = glob.glob(
f"{str(self.download_path)}/**/all_tf2onnx_issues.json", recursive=True
)
if tf2onnx_issues_path:
print("tf2onnx issues found")
tf2onnx_issues = self._get_cached_issues(tf2onnx_issues_path[0])
print(f"Total TF Issues: {len(tf2onnx_issues)}")
ptlf_tf2onnx_issues = list(
filter(lambda x: self._timeline_filter(x["timeline"]), tf2onnx_issues)
)
print(f"Filtered TF Issues: {len(ptlf_tf2onnx_issues)}")
self.tf2onnx_issues = self._issue_map(ptlf_tf2onnx_issues)
self._write_to_json(
self.filter_path, "filt_tf2onnx_issues.json", ptlf_tf2onnx_issues
)
self._write_issues_csv(
self.filter_path, "filt_tf2onnx_issues.csv", self.tf2onnx_issues
)
def evaluate_filter(self):
pytorch_issues_path = glob.glob(
f"{str(self.download_path)}/**/all_pytorch_issues.json", recursive=True
)
if pytorch_issues_path:
pytorch_issues = self._get_cached_issues(pytorch_issues_path[0])
sampled_issue = random.sample(pytorch_issues, 50)
sampledf_pytorch_issues = list(
filter(lambda x: self._timeline_filter(x["timeline"]), sampled_issue)
)
sampled_mapped_issue = self._issue_map(sampled_issue)
sampledf_mapped_issues = self._issue_map(sampledf_pytorch_issues)
self._write_issues_csv("sampled_pytorch_issues.csv", sampled_mapped_issue)
self._write_issues_csv(
"sampledf_pytorch_issues.csv", sampledf_mapped_issues
)
tf2onnx_issues_path = glob.glob(
f"{str(self.download_path)}/**/all_tf2onnx_issues.json", recursive=True
)
if tf2onnx_issues_path:
tf2onnx_issues = self._get_cached_issues(tf2onnx_issues_path[0])
sampled_issue = random.sample(tf2onnx_issues, 50)
sampledf_tf2onnx_issues = list(
filter(lambda x: self._timeline_filter(x["timeline"]), sampled_issue)
)
sampled_mapped_issue = self._issue_map(sampled_issue)
sampledf_mapped_issues = self._issue_map(sampledf_tf2onnx_issues)
self._write_issues_csv("sampled_tf2onnx_issues.csv", sampled_mapped_issue)
self._write_issues_csv(
"sampledf_tf2onnx_issues.csv", sampledf_mapped_issues
)
def sample_issues(self, n=100):
sampled_pytorch = self.sample(self.pytorch_issues, n)
self._write_issues_csv(self.sample_path, "pytorch_sampled.csv", sampled_pytorch)
sampled_tf2onnx = self.sample(self.tf2onnx_issues, n)
self._write_issues_csv(self.sample_path, "tf2onnx_sampled.csv", sampled_tf2onnx)
def sample(self, issues, n):
sampled_rows = random.sample(issues, n)
return sampled_rows
def _write_to_json(self, folder_path, path, issues):
path = Path(folder_path, path)
with open(path, "w") as f:
f.write(json.dumps(issues))
def _write_issues_csv(self, folder_path, path, issues):
path = Path(folder_path, path)
with open(path, "w") as f:
writer = csv.DictWriter(f, fieldnames=issues[0].keys())
writer.writeheader()
writer.writerows(issues)
def _get_cached_issues(self, path):
with open(path, "r") as f:
issues = json.load(f)
return issues
def _timeline_filter(self, timeline):
for timeline_event in timeline:
event = timeline_event["event"]
if event == "closed" and timeline_event["commit_id"]:
return True
if event == "referenced" and timeline_event["commit_id"]:
return True
if (
event == "cross-referenced"
and timeline_event["source"]["issue"]["repository"]["name"]
in ["pytorch", "tensorflow-onnx"]
and timeline_event["source"]["issue"]["state"] == "closed"
):
return True
if event == "connected":
return True
def _issue_map(self, issues):
mapped_issues = list(
map(
lambda x: {
"id": x[0],
"title": x[1]["title"],
"url": x[1]["html_url"],
},
enumerate(issues),
)
)
return mapped_issues
if __name__ == "__main__":
issues = Issues(download_path="./", filter_path="./")
issues.download_issues()
issues.process_issues()