devilry.utils.groups_groupedby_relatedstudent_and_assignment

Provides an easy-to-use API for generating overviews over the results of all students in a period. Collects students that are not related as well as related.

Example

Create CSV with the grades of all students on the period, including those ignored because they are not related:

grouper = GroupsGroupedByRelatedStudentAndAssignment(myperiod)

header = ['USER','IGNORED']
for assignment in grouper.iter_assignments():
    header.append(assignment.short_name)
print ';'.join(header)

def print_aggregated_relstudentinfo(aggregated_relstudentinfo, ignored):
    user = aggregated_relstudentinfo.user
    row = [user.username, ignored]
    for grouplist in aggregated_relstudentinfo.iter_groups_by_assignment():
        # NOTE: There can be more than one group if the same student is in more than one
        #       group on an assignment - we select the "best" feedback.
        feedback = grouplist.get_feedback_with_most_points()
        if feedback:
            row.append(feedback.grade)
        else:
            row.append('NO-FEEDBACK')
    print ';'.join(row)

# Print all related students
for aggregated_relstudentinfo in grouper.iter_relatedstudents_with_results():
    print_aggregated_relstudentinfo(aggregated_relstudentinfo, 'NO')

# Last we print the ignored students (non-related students that are in a group)
for aggregated_relstudentinfo in grouper.iter_students_with_feedback_that_is_candidate_but_not_in_related():
    print_aggregated_relstudentinfo(aggregated_relstudentinfo, 'YES')

API

class devilry.utils.groups_groupedby_relatedstudent_and_assignment.GroupList

Bases: list

Represents a list of devilry.apps.core.models.AssignmentGroup objects, with utility functions for commonly needed actions. The list is ment to hold groups where the same student in candidate on a single assignment, and the utilities is ment to make it easier to work with the added complexity of supporting the same user in multiple groups on a single assignment.

get_feedback_with_most_points()

Get the devilry.apps.core.models.StaticFeedback with the most points in the list.

get_best_gradestring()

Uses get_feedback_with_most_points() to get the feedback with most points, and returns the grade-attribute of that feedaback.

Returns:The grade or None.
class devilry.utils.groups_groupedby_relatedstudent_and_assignment.AggreatedRelatedStudentInfo(user, assignments, relatedstudent=None)

Bases: object

Used by GroupsGroupedByRelatedStudentAndAssignment to stores all results for a single student on a period.

user = None

The Django user object for the student.

assignments = None

Dict of assignments where the key is the assignment-id, and the value is a GroupList.

relatedstudent = None

The devilry.apps.core.models.RelatedStudent for users that are related students. This is only available for the objects returned by GroupsGroupedByRelatedStudentAndAssignment.iter_relatedstudents_with_results(), and not for the objects returned by the ignored students iterators.

iter_groups_by_assignment()

Returns an iterator over all GroupList objects for this student. Shortcut for self.assignments.itervalues().

add_group(group)

Used by GroupsGroupedByRelatedStudentAndAssignment to add groups.

prettyprint()

Prettyprint for debugging.

class devilry.utils.groups_groupedby_relatedstudent_and_assignment.GroupsGroupedByRelatedStudentAndAssignment(period)

Bases: object

Provides an easy-to-use API for overviews over the results of all students in a period.

Parameters:period – A devilry.apps.core.models.Period object.
get_assignment_queryset()

Get the queryset used to fetch all assignments on the period. Override for custom ordering or if you need to optimize the query for your usecase (select_related, prefetch_related, etc.)

get_relatedstudents_queryset()

Get the queryset used to fetch all relatedstudents on the period. Override if you need to optimize the query for your usecase (select_related, prefetch_related, etc.)

get_groups_queryset()

Get the queryset used to fetch all groups on the period. Override if you need to optimize the query for your usecase (select_related, prefetch_related, etc.)

iter_assignments()

Iterate over all the assignments, yielding Assignment-objects. The objects are iterated in the order returned by get_assignment_queryset().

iter_relatedstudents_with_results()

Iterate over all relatedstudents, yielding a dict with the following attributes for each related student:

user
The Django user-object for the student.
assignments
An OrderedDict, ordered the same as iter_assignments(), where the key is the assignment-id, and the value is a list of AssignmentGroup-objects where the user is candidate. The list may have 0 or more groups, 0 if the user is not in any group on the assignment, and more than 1 if the user is in more than one group on the assignment.

Iterate over the students that is candidate on one or more groups, but not registered as related students.

This iterator includes everything yielded by both:

Same as iter_students_that_is_candidate_but_not_in_related(), but it does not include the students that have no feedback.

Iterate over everything returned by iter_students_that_is_candidate_but_not_in_related() except for the students returned by iter_students_with_feedback_that_is_candidate_but_not_in_related()

serialize()

Serialize all the collected data as plain python objects.