Skip to content

Commit 8edf4b7

Browse files
authored
Workload debug (#147)
* add file capture and debug prints * black * remove spurious import * add extra print * space * simplify * black
1 parent 60f02d1 commit 8edf4b7

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

workload/workload.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ class ProjectData:
4040
review_data: list Data filtered to contain a list of review tuples
4141
"""
4242

43-
def __init__(self, test: bool = False):
43+
def __init__(self, test: bool = False, capture: bool = False):
4444
self.data = {}
4545
self.review_data = []
4646

47-
self.fetch_project_data(test)
48-
self.filter_reviewers()
47+
self.fetch_project_data(test, capture)
48+
self.filter_reviewers(test)
4949

50-
def fetch_project_data(self, test: bool):
50+
def fetch_project_data(self, test: bool, capture: bool):
5151
"""
5252
Retrieve data from GitHub API or a from a test file.
5353
"""
@@ -66,20 +66,43 @@ def fetch_project_data(self, test: bool):
6666

6767
self.data = json.loads(output.stdout)
6868

69-
def filter_reviewers(self):
69+
if capture:
70+
file = Path(__file__).with_name("test.json")
71+
with open(file, "w") as f:
72+
json.dump(self.data, f)
73+
print(
74+
"Project data saved to test.json. Use --test to run with"
75+
" the captured data."
76+
)
77+
78+
def filter_reviewers(self, test: bool = False):
7079
"""
7180
Filter the data to create a list of review tuples
7281
"""
7382
all_reviews = self.data["items"]
7483
for review in all_reviews:
84+
cr = ""
85+
sr = ""
7586
if "code Review" in review:
87+
cr = review["code Review"]
7688
self.review_data.append((review["code Review"], review["repository"]))
7789

7890
if "sciTech Review" in review:
91+
sr = review["sciTech Review"]
7992
self.review_data.append(
8093
(review["sciTech Review"], review["repository"])
8194
)
8295

96+
if test and (cr or sr):
97+
print(
98+
"SciTech:",
99+
f"{sr: <18}",
100+
"Code:",
101+
f"{cr: <18}",
102+
f"{review['repository']: <50}",
103+
review["title"],
104+
)
105+
83106
def one_repo(self, repository: str) -> list:
84107
"""
85108
Filter the review data to just that of one repository
@@ -230,14 +253,19 @@ def parse_args():
230253
action="store_true",
231254
help="Use test input files.",
232255
)
256+
parser.add_argument(
257+
"--capture_project",
258+
action="store_true",
259+
help="Capture the current project status into the test file",
260+
)
233261

234262
return parser.parse_args()
235263

236264

237-
def main(total: bool, test: bool):
265+
def main(total: bool, test: bool, capture_project: bool):
238266

239267
# Extract data from github about the reviews and team members.
240-
data = ProjectData(test)
268+
data = ProjectData(test, capture_project)
241269

242270
other_team = Team(test=test)
243271
other_team.members = other_reviewers
@@ -271,4 +299,4 @@ def main(total: bool, test: bool):
271299

272300
if __name__ == "__main__":
273301
args = parse_args()
274-
main(args.total, args.test)
302+
main(args.total, args.test, args.capture_project)

0 commit comments

Comments
 (0)