Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-Rey committed Oct 5, 2023
2 parents 75eb3b3 + 1db584b commit 83f4442
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pabutools/analysis/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def category_proportionality(
app_total_cost += project.cost
for category in project.categories:
app_cost_per_category[category] += project.cost
if app_total_cost == 0:
raise ValueError(
"Category proportionality can only be computed for instances with at least one non-empty ballot."
)
for category in categories:
proportional_app_cost_per_category[category] += (
app_cost_per_category[category]
Expand Down
8 changes: 8 additions & 0 deletions pabutools/analysis/profileproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def median_ballot_length(instance: Instance, profile: AbstractProfile) -> int:
The median length of the ballots in the profile.
"""
if profile.num_ballots() == 0:
return 0
ballot_lengths = np.zeros(profile.num_ballots())
index = 0
for ballot in profile:
Expand Down Expand Up @@ -100,6 +102,8 @@ def median_ballot_cost(instance: Instance, profile: AbstractProfile) -> Number:
The median cost of the ballots in the profile.
"""
if profile.num_ballots() == 0:
return 0
ballot_costs = np.zeros(profile.num_ballots())
index = 0
for ballot in profile:
Expand Down Expand Up @@ -148,6 +152,8 @@ def median_approval_score(
The median approval score of projects.
"""
if len(instance) == 0:
return 0
return float(
np.median([frac(profile.approval_score(project)) for project in instance])
)
Expand Down Expand Up @@ -190,6 +196,8 @@ def median_total_score(instance: Instance, profile: AbstractCardinalProfile) ->
The median score assigned to a project.
"""
if len(instance) == 0:
return 0
return float(
np.median([frac(profile.total_score(project)) for project in instance])
)

0 comments on commit 83f4442

Please sign in to comment.