Grading Groups#

class gradelib.GradingGroup(assignment_weights: Mapping[str, float], group_weight: float, cap_total_score_at_100_percent: bool = False)#

Represents a logical group of assignments and their weights.

assignment_weights#

A dictionary mapping assignment names (strings) to their weight within the group (as a float between 0 and 1, or as an instance of ExtraCredit). The weights of regular (non-extra credit) assignments should add to one.

Type:

Mapping[str, float | ExtraCredit]

group_weight#

The weight of the group in the overall grade calculation. This should be a float between 0 and 1, or an instance of ExtraCredit.

Type:

float | ExtraCredit

cap_total_score_at_100_percent#

If True, the total score for the group is capped at 100%. Default: False.

Type:

bool

Raises:

ValueError – If the assignment weights are not between 0 and 1, they do not add to one, or if the group weight is not between 0 and 1.

property assignments: Assignments#

The assignments in the group.

property extra_credit_assignment_weights: dict[str, float]#

Returns a dictionary of the extra credit assignment weights.

property regular_assignment_weights: dict[str, float]#

Returns a dictionary of the regular (non-extra credit) assignment weights.

validate()#

Validate the grading group.

Makes sure that:

  • The assignment weights are between 0 and 1.

  • The regular assignment weights sum to one.

  • The group weight is between 0 and 1.

  • The group contains at least one non-extra credit assignment.

Raises a ValueError if any of these conditions are not met.

classmethod with_equal_weights(assignments: Collection[str], group_weight: float, cap_total_score_at_100_percent: bool = False) GradingGroup#

Create a grading group in which each assignment is given equal weight.

Parameters:
  • assignments (Collection[str]) – The assignments to include in the group.

  • group_weight (float) – The overall weight of the group.

  • cap_total_score_at_100_percent (bool) – If True, the total score for the group is capped at 100%. Default: False.

Return type:

GradingGroup

Example

>>> group = GradingGroup.with_equal_weights(['foo', 'bar', 'baz', 'quux'], 0.5)
>>> group.assignment_weights
{'foo': 0.25, 'bar': 0.25, 'baz': 0.25, 'quux': 0.25}
with_extra_credit_assignments(extra_credit: Mapping[str, float]) GradingGroup#

Add extra credit assignments to the grading group.

This creates a new grading group with the same assignments as the original group, but with extra credit assignments added.

Parameters:

extra_credit (Mapping[str, float]) – A dictionary mapping assignment names to their weight within the group (as a float between 0 and 1).

Return type:

GradingGroup

classmethod with_proportional_weights(gb: Gradebook, assignments: Collection[str], group_weight: float, cap_total_score_at_100_percent: bool = False) GradingGroup#

Create a grading group in which each assignment is weighed proportionally.

An assignment’s weight within the group is proportional to the number of points possible for that assignment.

Parameters:
  • gb (Gradebook) – The gradebook containing the assignments.

  • assignments (Collection[str]) – The assignments to include in the group.

  • group_weight (float) – The overall weight of the group.

Return type:

GradingGroup

Example

>>> group = GradingGroup.with_proportional_weights(
...     gradebook, ['homework 01', 'homework 02'], 0.5
... )
>>> group.assignment_weights
{'homework 01': 0.25, 'homework 02': 0.75}
class gradelib.ExtraCredit(percentage: float)#

Represents extra credit in a grading group.

Parameters:

percentage (float) – The percentage of extra credit to give. For example, if this is 0.1, then the group will be worth 10% (on top of the normal 100%).