Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/allocate_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():
parser = ArgumentParser(description="Check for SDG proposals from same project")
parser.add_argument("round", type=int, help="round number to be extracted")
parser.add_argument("--budget", type=int, help="total number of budget allowed")
parser.add_argument("--funding_limit", type=int, default="10000", help="funding limit per year")
parser.add_argument("--funding_limit", type=int, default=10000, help="funding limit per year")
arguments = parser.parse_args()

issues = get_all_issues()
Expand Down
17 changes: 10 additions & 7 deletions scripts/project_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def select_proposals_to_fund(budget, funding_limit, proposals, seed=None):
raise ValueError("Proposal names are not unique")

funded = []
budget_remaining = budget
temp_budget_remaining = budget + 0
while budget_remaining > 0 and len(funded) < len(proposals):
current_budget = budget # Use a single variable for tracking the budget

while current_budget > 0 and len(funded) < len(proposals):
total_weight = sum(weights)
if total_weight == 0:
# When all the proposals have been evaluated and there's still budget
Expand All @@ -48,10 +48,13 @@ def select_proposals_to_fund(budget, funding_limit, proposals, seed=None):
weights[i] = 0
proposal = proposals[i]
proposal_budget = proposal[1]
temp_budget_remaining -= proposal_budget
if temp_budget_remaining > -proposal_budget / 2:

# This condition allows for some overspending, as per existing tests.
# It funds the proposal if the remaining budget covers it, or if the overspend
# is less than half the proposal's budget.
if current_budget - proposal_budget > -proposal_budget / 2:
funded.append(proposal)
budget_remaining = temp_budget_remaining
current_budget -= proposal_budget

print("Inputs:")
print(f"Budget: ${budget}")
Expand All @@ -65,7 +68,7 @@ def select_proposals_to_fund(budget, funding_limit, proposals, seed=None):
print()
print("Random Outputs:")
print(
f"Allocated: ${round(budget - budget_remaining, 2)} (${round(abs(budget_remaining), 2)} {'over' if budget_remaining < 0 else 'under'} budget)"
f"Allocated: ${round(budget - current_budget, 2)} (${round(abs(current_budget), 2)} {'over' if current_budget < 0 else 'under'} budget)"
)
print(f"{len(funded)} proposals funded out of {len(proposals)} total proposals in the drawing")
print()
Expand Down
26 changes: 17 additions & 9 deletions scripts/sdg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def parse_issue(issue):
return None

year, round_number = label_info.groups()
labels = [label["name"] for label in issue["labels"]]

# Create a set of lowercased labels for efficient lookup
lower_labels = {label["name"].lower() for label in issue["labels"]}

body = issue["body"]
project_match = re.search(r"(?i)Project\s*[\n\r]+(.+?)(?=\n\S|$)", body, re.DOTALL)
Expand All @@ -61,16 +63,22 @@ def parse_issue(issue):
project_name = url.group(1)

amount_match = re.search(r"(?i)Amount requested\s*(\(USD\))?\s*[\n\r]+(.+?)(?=\n\S|$)", body, re.DOTALL)
amount_requested = 0 # Initialize to 0
funded_amount = 0
try:
amount_requested = int(re.sub(r"[^\d]", "", amount_match.group(2)))
except ValueError:
amount_requested = 0
if "funded" in [l.lower() for l in labels] and amount_match:

if amount_match: # Check if match exists before accessing groups
try:
amount_requested = int(re.sub(r"[^\d]", "", amount_match.group(2)))
except ValueError:
# If conversion to int fails, amount_requested remains 0
pass

# Determine funded_amount based on the 'funded' label and the (potentially 0) amount_requested
if "funded" in lower_labels:
funded_amount = amount_requested

return {
"awarded": "award" in [l.lower() for l in labels],
"awarded": "award" in lower_labels,
"year": int(year),
"round_number": int(round_number),
"funded_amount": funded_amount,
Expand Down Expand Up @@ -232,7 +240,8 @@ def update_board(issues_round, round):
id
}}
}}
}}'
}}
'
"""

for issue in issues_round:
Expand Down Expand Up @@ -266,4 +275,3 @@ def update_board(issues_round, round):
)
if output.returncode != 0:
raise ValueError(output.stderr)