Skip to content

Commit 490cc64

Browse files
committed
🎨 Ruff format
1 parent 8573ee0 commit 490cc64

File tree

7 files changed

+160
-105
lines changed

7 files changed

+160
-105
lines changed

scripts/allocate_funds.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,31 @@
77
from sdg_utils import get_all_issues, parse_issue, combine_projects_rounds
88
from project_selection import select_proposals_to_fund
99

10-
def allocate_funds(issues, budget, funding_limit, seed=None):
1110

12-
proposals = [(issue['project_name'], issue['amount_requested'], issue['funded_amount']) for issue in issues]
11+
def allocate_funds(issues, budget, funding_limit, seed=None):
12+
proposals = [
13+
(issue["project_name"], issue["amount_requested"], issue["funded_amount"])
14+
for issue in issues
15+
]
1316
funded = select_proposals_to_fund(budget, funding_limit, proposals, seed=seed)
14-
print('-' * 60)
17+
print("-" * 60)
1518
print("Funded projects:")
1619
for project in funded:
1720
print(f"- {project}")
18-
print('-' * 60)
21+
print("-" * 60)
1922
for issue in issues:
20-
if issue['project_name'] in funded:
23+
if issue["project_name"] in funded:
2124
command = f'gh issue edit {issue["issue_number"]} --add-label "funded"'
2225
output = subprocess.run(shlex.split(command), capture_output=True)
2326
if output.returncode != 0:
2427
raise ValueError(output.stderr)
2528

29+
2630
def main():
2731
parser = ArgumentParser(description="Check for SDG proposals from same project")
28-
parser.add_argument('round', type=int, help='round number to be extracted')
29-
parser.add_argument('--budget', type=int, help='total number of budget allowed')
30-
parser.add_argument('--funding_limit', type=int, default='10000', help='funding limit per year')
32+
parser.add_argument("round", type=int, help="round number to be extracted")
33+
parser.add_argument("--budget", type=int, help="total number of budget allowed")
34+
parser.add_argument("--funding_limit", type=int, default="10000", help="funding limit per year")
3135
arguments = parser.parse_args()
3236

3337
issues = get_all_issues()
@@ -36,15 +40,24 @@ def main():
3640
result = parse_issue(issue)
3741
if result:
3842
sdg_issues.append(result)
39-
sdg_issues_round = [sdg for sdg in sdg_issues if sdg['round_number'] == arguments.round and
40-
sdg['year'] == date.today().year and
41-
not sdg['awarded']]
42-
#Filter only this year and combine to calculate all they've been funded ask
43-
sdg_prev_rounds = [sdg_p for sdg_p in sdg_issues if sdg_p['round_number'] != arguments.round and sdg_p['year'] == date.today().year]
43+
sdg_issues_round = [
44+
sdg
45+
for sdg in sdg_issues
46+
if sdg["round_number"] == arguments.round
47+
and sdg["year"] == date.today().year
48+
and not sdg["awarded"]
49+
]
50+
# Filter only this year and combine to calculate all they've been funded ask
51+
sdg_prev_rounds = [
52+
sdg_p
53+
for sdg_p in sdg_issues
54+
if sdg_p["round_number"] != arguments.round and sdg_p["year"] == date.today().year
55+
]
4456
combine_projects_rounds(sdg_issues_round, sdg_prev_rounds)
4557
seed = int(time.time())
4658
print(f"Using seed: {seed}")
4759
allocate_funds(sdg_issues_round, arguments.budget, arguments.funding_limit, seed=seed)
4860

61+
4962
if __name__ == "__main__":
5063
main()

scripts/check_duplicates.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99

1010

1111
def find_duplicates(issues):
12-
13-
projects = [issue['project_name'] for issue in issues]
12+
projects = [issue["project_name"] for issue in issues]
1413
uniq_projects = set(projects)
1514

1615
if len(projects) != uniq_projects:
1716
for uproj in uniq_projects:
1817
if projects.count(uproj) > 1:
1918
# add a label to the issues
2019
for issue in issues:
21-
if issue['project_name'] == uproj:
20+
if issue["project_name"] == uproj:
2221
command = f'gh issue edit {issue["issue_number"]} --add-label "duplicate"'
2322
output = subprocess.run(shlex.split(command), capture_output=True)
2423
if output.returncode != 0:
@@ -27,7 +26,7 @@ def find_duplicates(issues):
2726

2827
def main():
2928
parser = ArgumentParser(description="Check for SDG proposals from same project")
30-
parser.add_argument('round', type=int, help='round number to be extracted')
29+
parser.add_argument("round", type=int, help="round number to be extracted")
3130
arguments = parser.parse_args()
3231

3332
issues = get_all_issues()
@@ -36,12 +35,14 @@ def main():
3635
result = parse_issue(issue)
3736
if result:
3837
sdg_issues.append(result)
39-
sdg_issues_round = [sdg for sdg in sdg_issues if sdg['round_number'] == arguments.round and
40-
sdg['year'] == date.today().year]
38+
sdg_issues_round = [
39+
sdg
40+
for sdg in sdg_issues
41+
if sdg["round_number"] == arguments.round and sdg["year"] == date.today().year
42+
]
4143
print(json.dumps(sdg_issues_round, indent=2))
4244
find_duplicates(sdg_issues_round)
4345

46+
4447
if __name__ == "__main__":
4548
main()
46-
47-

scripts/distribute_proposals.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77

88
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
99

10+
1011
def extract_pwc(reviewers):
1112
return list(set(sum(filter(lambda x: x, list(reviewers.values())), [])))
1213

14+
1315
def produce_conflicts_dict(reviewers, projects_with_confict):
14-
return {proj: list(filter(lambda x: proj in reviewers[x], {k:v for k,v in reviewers.items() if v})) for proj in projects_with_confict}
16+
return {
17+
proj: list(
18+
filter(lambda x: proj in reviewers[x], {k: v for k, v in reviewers.items() if v})
19+
)
20+
for proj in projects_with_confict
21+
}
1522

16-
def distribute_proposals(proposals, seed, reviews_per_proposal):
1723

18-
with open(os.path.join(CURRENT_DIR, 'reviewers_list.yaml'), 'r') as f:
24+
def distribute_proposals(proposals, seed, reviews_per_proposal):
25+
with open(os.path.join(CURRENT_DIR, "reviewers_list.yaml"), "r") as f:
1926
reviewers_coi = yaml.safe_load(f.read())
2027

2128
random.seed(seed)
@@ -33,7 +40,6 @@ def who_is_reviewing(proposal):
3340
def has_conflict(reviewer, proposal):
3441
return proposal in conflicts and reviewer in conflicts[proposal]
3542

36-
3743
# Sometimes this will fail because of a pathological random order of review
3844
# assignments. If it's run often enough, it should eventually succeed.
3945

@@ -51,19 +57,18 @@ def has_conflict(reviewer, proposal):
5157
if (
5258
has_conflict(reviewer, proposal)
5359
or
54-
( # This really might be more trouble than it's worth.
55-
(
56-
# If a reviewer has at least two more assignments than the
57-
# other reviwer(s) with the least number of assignments.
58-
len(assignments[reviewer]) - min(len(assignments[r]) for r in reviewers) > 1
59-
)
60-
# and
61-
# (
62-
# # If we're getting low on non-conflicted reviewers,
63-
# # don't worry about skewed review allocations.
64-
# len(reviewers_left) - len(working_reviewers) >= (REVIEWS_PER_PROPOSAL - 1)
65-
# )
60+
# This really might be more trouble than it's worth.
61+
(
62+
# If a reviewer has at least two more assignments than the
63+
# other reviwer(s) with the least number of assignments.
64+
len(assignments[reviewer]) - min(len(assignments[r]) for r in reviewers) > 1
6665
)
66+
# and
67+
# (
68+
# # If we're getting low on non-conflicted reviewers,
69+
# # don't worry about skewed review allocations.
70+
# len(reviewers_left) - len(working_reviewers) >= (REVIEWS_PER_PROPOSAL - 1)
71+
# )
6772
):
6873
working_reviewers.remove(reviewer)
6974

@@ -83,13 +88,12 @@ def has_conflict(reviewer, proposal):
8388
# Sometimes 1-2 reviewers are under-assigned. Can re-run
8489
# until a good split is achieved, or rebalance manually,
8590
# or leave as-is.
86-
print([f'{r}: {len(assignments[r])}' for r in reviewers])
91+
print([f"{r}: {len(assignments[r])}" for r in reviewers])
8792

8893
# Who has been assigned to each proposal?
8994
for p in proposals:
9095
print(f"{p}: {who_is_reviewing(p)}")
9196

92-
9397
# Which proposals was each person assigned?
9498
for r in assignments:
9599
print(r)

scripts/extract_sdg_issues.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@
1111
from sdg_utils import get_all_issues, parse_issue, combine_projects_rounds, update_board
1212

1313

14-
1514
def assign_reviewers(issues, round, reviewers):
16-
1715
seed = int(f"{date.today().year}{round}")
18-
assignments = distribute_proposals([issue['project_name'] for issue in issues], seed, reviewers)
16+
assignments = distribute_proposals([issue["project_name"] for issue in issues], seed, reviewers)
1917
for issue in issues:
2018
for person, projects in assignments.items():
21-
if issue['project_name'] in projects:
22-
issue['reviewers'].append(person)
19+
if issue["project_name"] in projects:
20+
issue["reviewers"].append(person)
2321

2422

2523
def main():
2624
parser = ArgumentParser(description="Runs script to extract SDG issues")
27-
parser.add_argument('round', type=int, help='round number to be extracted')
28-
parser.add_argument('--reviewers', type=int, default=3, help='number of reviewers per proposal')
25+
parser.add_argument("round", type=int, help="round number to be extracted")
26+
parser.add_argument("--reviewers", type=int, default=3, help="number of reviewers per proposal")
2927
arguments = parser.parse_args()
3028

3129
issues = get_all_issues()
@@ -36,17 +34,25 @@ def main():
3634
sdg_issues.append(result)
3735
print(json.dumps(sdg_issues, indent=2))
3836

39-
sdg_issues_round = [sdg for sdg in sdg_issues if sdg['round_number'] == arguments.round and
40-
sdg['year'] == date.today().year and
41-
not sdg['awarded']]
42-
#Filter only this year and combine to calculate all they've been funded ask
43-
sdg_prev_rounds = [sdg_p for sdg_p in sdg_issues if sdg_p['round_number'] != arguments.round and sdg_p['year'] == date.today().year]
37+
sdg_issues_round = [
38+
sdg
39+
for sdg in sdg_issues
40+
if sdg["round_number"] == arguments.round
41+
and sdg["year"] == date.today().year
42+
and not sdg["awarded"]
43+
]
44+
# Filter only this year and combine to calculate all they've been funded ask
45+
sdg_prev_rounds = [
46+
sdg_p
47+
for sdg_p in sdg_issues
48+
if sdg_p["round_number"] != arguments.round and sdg_p["year"] == date.today().year
49+
]
4450
print("only this round")
4551
combine_projects_rounds(sdg_issues_round, sdg_prev_rounds)
4652
assign_reviewers(sdg_issues_round, arguments.round, arguments.reviewers)
4753
print(json.dumps(sdg_issues_round, indent=2))
4854
update_board(sdg_issues_round, arguments.round)
4955

56+
5057
if __name__ == "__main__":
5158
main()
52-

scripts/project_selection.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,11 @@ def select_proposals_to_fund(budget, funding_limit, proposals, seed=None):
6767
print(
6868
f"Allocated: ${round(budget - budget_remaining, 2)} (${round(abs(budget_remaining), 2)} {'over' if budget_remaining < 0 else 'under'} budget)"
6969
)
70-
print(
71-
f"{len(funded)} proposals funded out of {len(proposals)} total proposals in the drawing"
72-
)
70+
print(f"{len(funded)} proposals funded out of {len(proposals)} total proposals in the drawing")
7371
print()
7472
print("Funded the following projects")
7573

7674
for p in funded:
77-
print(
78-
f'Fund "{p[0]}" for ${p[1]} bringing its project\'s annual total to ${p[1] + p[2]}.'
79-
)
75+
print(f'Fund "{p[0]}" for ${p[1]} bringing its project\'s annual total to ${p[1] + p[2]}.')
8076

8177
return [f[0] for f in funded]

0 commit comments

Comments
 (0)