gradelib
core
This is the core functionality of gradelib
.
Core Types
Functions
- gradelib.combine_gradebooks(gradebooks: Collection[Gradebook], restrict_to_students=None)
Create a new
Gradebook
by safely combining existing gradebooks.The gradebooks being combined must all have the same students, and an assignment name cannot appear in more than one gradebook. If either of these conditions are violated, a ValueError is raised.
The new gradebook’s grading groups are reset; there are no groups.
If the scales are the same in each gradebook, the new gradebook’s scale is set accordingly. If they are different, a
ValueError
is raised. The same is true for theoptions
attribute.- Parameters:
gradebooks (Collection[Gradebook]) – The gradebooks to combine.
restrict_to_students (Optional[Collection[Union[str, Student]]]) – If provided, each input gradebook will be restricted to the Students/PIDs given before attempting to combine them. This is a convenience option, and it simply calls
Gradebook.restrict_to_students()
on each of the inputs. Default: None
- Returns:
A gradebook combining all of the input gradebooks.
- Return type:
- Raises:
ValueError – If the PID indices of gradebooks do not match; if there is a duplicate assignment name; the options do not match; the scales do not match.
- gradelib.normalize(assignments: Collection[str]) dict[str, float]
Normalize assignment weights.
When given a collection, such as a list of assignment names or a dictionary mapping names to weights, the return value is a dictionary mapping assignment names to the same, normalized weight.
- Parameters:
assignments (Collection[str]) – The assignments to normalize.
- Returns:
An assignment weight dictionary in which each assignment is weighed equally.
- Return type:
dict[str, float]
Example
>>> normalize(['foo', 'bar', 'baz', 'quux']) {'foo': 0.25, 'bar': 0.25, 'baz': 0.25, 'quux': 0.25}
Useful when creating grading groups. For instance:
>>> gradebook.grading_groups = { ... 'homework': (normalize(gradebook.assignments.starting_with('home')), 0.5), ... 'labs': (normalize(gradebook.assignments.starting_with('lab')), 0.5) ... }