lms.djangoapps.grades package

Contents

lms.djangoapps.grades package#

Subpackages#

Submodules#

lms.djangoapps.grades.api module#

Python APIs exposed by the grades app to other in-process apps.

lms.djangoapps.grades.api.graded_subsections_for_course_id(course_id)#

Return graded subsections for the course.

lms.djangoapps.grades.api.override_subsection_grade(user_id, course_key_or_id, usage_key_or_id, overrider=None, earned_all=None, earned_graded=None, feature='PROCTORING', comment=None)#

Creates a PersistentSubsectionGradeOverride corresponding to the given user, course, and usage_key. Will also create a PersistentSubsectionGrade for this (user, course, usage_key) if none currently exists.

Fires off a recalculate_subsection_grade async task to update the PersistentCourseGrade table. Will not override earned_all or earned_graded value if they are None. Both of these parameters have None as their default value.

lms.djangoapps.grades.api.should_override_grade_on_rejected_exam(course_key_or_id)#

Convenience function to return the state of the CourseWaffleFlag REJECTED_EXAM_OVERRIDES_GRADE

lms.djangoapps.grades.api.undo_override_subsection_grade(user_id, course_key_or_id, usage_key_or_id, feature='')#

Delete the override subsection grade row (the PersistentSubsectionGrade model must already exist)

Fires off a recalculate_subsection_grade async task to update the PersistentSubsectionGrade table. If the override does not exist, no error is raised, it just triggers the recalculation.

feature: if specified, the deletion will only occur if the

override to be deleted was created by the corresponding subsystem

lms.djangoapps.grades.apps module#

Grades Application Configuration

Signal handlers are connected here.

class lms.djangoapps.grades.apps.GradesConfig(app_name, app_module)#

Bases: AppConfig

Application Configuration for Grades.

name = 'lms.djangoapps.grades'#
plugin_app = {'settings_config': {'lms.djangoapp': {'common': {'relative_path': 'settings.common'}, 'production': {'relative_path': 'settings.production'}, 'test': {'relative_path': 'settings.test'}}}, 'url_config': {'lms.djangoapp': {'app_name': 'lms.djangoapps.grades', 'namespace': 'grades_api', 'regex': '^api/grades/', 'relative_path': 'rest_api.urls'}}}#
ready()#

Connect handlers to recalculate grades.

lms.djangoapps.grades.constants module#

Constants and Enums used by Grading.

class lms.djangoapps.grades.constants.GradeOverrideFeatureEnum#

Bases: object

grade_import = 'grade-import'#
gradebook = 'GRADEBOOK'#
proctoring = 'PROCTORING'#
class lms.djangoapps.grades.constants.ScoreDatabaseTableEnum#

Bases: object

The various database tables that store scores.

courseware_student_module = 'csm'#
overrides = 'overrides'#
submissions = 'submissions'#

lms.djangoapps.grades.context module#

Grading Context

lms.djangoapps.grades.context.graded_subsections_for_course(course_structure)#

Given a course block structure, yields the subsections of the course that are graded and visible to non-staff users. :param course_structure: A course structure object.

lms.djangoapps.grades.context.grading_context(course, course_structure)#

This returns a dictionary with keys necessary for quickly grading a student.

The grading context has two keys: all_graded_subsections_by_type - This contains all subsections that are

graded, keyed by subsection format (assignment type).

The values are arrays of dictionaries containing

“subsection_block” : The subsection block “scored_descendants” : An array of usage keys for blocks

that could possibly be in the subsection, for any student

all_graded_blocks - This contains a list of all blocks that can

affect grading a student. This is used to efficiently fetch all the xmodule state for a FieldDataCache without walking the block tree again.

lms.djangoapps.grades.context.grading_context_for_course(course)#

Same as grading_context, but takes in a course key.

lms.djangoapps.grades.course_data module#

Code used to get and cache the requested course-data

class lms.djangoapps.grades.course_data.CourseData(user, course=None, collected_block_structure=None, structure=None, course_key=None)#

Bases: object

Utility access layer to intelligently get and cache the requested course data as long as at least one property is provided upon initialization.

This is an in-memory object that maintains its own internal cache during its lifecycle.

property collected_structure#
property course#
property course_key#
property edited_on#
property effective_structure#

Get whichever course block structure is already loaded, if any.

This may give either the user-specific course structure or the generic structure, depending on which is cached at the moment. Because of that, this should only be used for queries related to the root block of the course, which will always exist in either structure.

For anything else, such as queries involving course sections or blocks, use either .structure or .collected_structure to explicitly state whether you want the user-specific version of the course or not.

full_string()#
property grading_policy_hash#
property location#
property structure#
property version#

lms.djangoapps.grades.course_grade module#

CourseGrade Class

class lms.djangoapps.grades.course_grade.CourseGrade(user, course_data, *args, **kwargs)#

Bases: CourseGradeBase

Course Grade class when grades are updated or read from storage.

attempted()#

Returns whether any of the subsections in this course have been attempted by the student.

update(visible_grades_only=False, has_staff_access=False)#

Updates the grade for the course. Also updates subsection grades if self.force_update_subsections is true, via the call to self.grader_result.

class lms.djangoapps.grades.course_grade.CourseGradeBase(user, course_data, percent=0.0, letter_grade=None, passed=False, force_update_subsections=False, last_updated=None)#

Bases: object

Base class for Course Grades.

property attempted#

Returns whether at least one problem was attempted by the user in the course.

chapter_grades()#

Returns a dictionary of dictionaries. The primary dictionary is keyed by the chapter’s usage_key. The secondary dictionary contains the chapter’s subsection grades, display name, and url name.

chapter_percentage(chapter_key)#

Returns the rounded aggregate weighted percentage for the given chapter. :raises KeyError if the chapter is not found.:

classmethod get_subsection_type_graders(course)#

Returns a dictionary mapping subsection types to their corresponding configured graders, per grading policy.

graded_subsections_by_format(visible_grades_only=False, has_staff_access=False)#

Returns grades for the subsections in the course in a dict keyed by subsection format types.

grader_result(visible_grades_only=False, has_staff_access=False)#

Returns the result from the course grader.

problem_scores()#

Returns a dict of problem scores keyed by their locations.

score_for_block(location)#

Calculate the aggregate weighted score for any location in the course. This method returns a tuple containing (earned_score, possible_score). If the location is of ‘problem’ type, this method will return the possible and earned scores for that problem. If the location refers to a composite block (a vertical or section ) the scores will be the sums of all scored problems that are children of the chosen location.

subsection_grade(subsection_key)#

Returns the subsection grade for the given subsection usage key.

Raises KeyError if the course structure does not contain the key.

If the course structure contains the key, this will always succeed (and return a grade) regardless of whether the user can access that section; it is up to the caller to ensure that the grade isn’t shown to users that shouldn’t be able to access it (e.g. a student shouldn’t see a grade for an unreleased subsection);

subsection_grades()#

Returns an ordered dictionary of subsection grades, keyed by subsection location.

property summary#

Returns the grade summary as calculated by the course’s grader. DEPRECATED: To be removed as part of TNL-5291.

update(visible_grades_only=False, has_staff_access=False)#

Recalculates the grade for the course, with the given parameters.

Also updates subsection grades if self.force_update_subsections is true.

Parameters:
  • visible_grades_only – Only considers grades the user can see (via show_correctness subsection field)

  • has_staff_access – Used to help determine which grades are visible (if visible_grades_only=True)

class lms.djangoapps.grades.course_grade.ZeroCourseGrade(user, course_data, percent=0.0, letter_grade=None, passed=False, force_update_subsections=False, last_updated=None)#

Bases: CourseGradeBase

Course Grade class for Zero-value grades when no problems were attempted in the course.

lms.djangoapps.grades.course_grade_factory module#

Course Grade Factory Class

class lms.djangoapps.grades.course_grade_factory.CourseGradeFactory#

Bases: object

Factory class to create Course Grade objects.

class GradeResult(student, course_grade, error)#

Bases: tuple

course_grade#

Alias for field number 1

error#

Alias for field number 2

student#

Alias for field number 0

iter(users, course=None, collected_block_structure=None, course_key=None, force_update=False)#

Given a course and an iterable of students (User), yield a GradeResult for every student enrolled in the course. GradeResult is a named tuple of:

(student, course_grade, err_msg)

If an error occurred, course_grade will be None and err_msg will be an exception message. If there was no error, err_msg is an empty string.

read(user, course=None, collected_block_structure=None, course_structure=None, course_key=None, create_if_needed=True)#

Returns the CourseGrade for the given user in the course. Reads the value from storage or creates an initial value of zero.

At least one of course, collected_block_structure, course_structure, or course_key should be provided.

update(user, course=None, collected_block_structure=None, course_structure=None, course_key=None, force_update_subsections=False)#

Computes, updates, and returns the CourseGrade for the given user in the course.

At least one of course, collected_block_structure, course_structure, or course_key should be provided.

lms.djangoapps.grades.events module#

Emits course grade events.

lms.djangoapps.grades.events.course_grade_calculated(course_grade)#

Emits an edx.grades.course.grade_calculated event with data from the passed course_grade.

lms.djangoapps.grades.events.course_grade_now_failed(user, course_id)#

Emits an edx.course.grade.now_failed and passing status updated events with data from the course and user failed now.

lms.djangoapps.grades.events.course_grade_now_passed(user, course_id)#

Emits an edx.course.grade.now_passed and passing status updated events with data from the course and user passed now.

lms.djangoapps.grades.events.course_grade_passed_first_time(user_id, course_id)#

Emits an event edx.course.grade.passed.first_time with data from the passed course_grade.

lms.djangoapps.grades.events.fire_segment_event_on_course_grade_passed_first_time(user_id, course_locator)#

Fire a segment event edx.course.grade.passed.first_time with the desired data.

  • Event should be only fired for learners enrolled in paid enrollment modes.

lms.djangoapps.grades.events.grade_updated(**kwargs)#

Emits the appropriate grade-related event after checking for which event-transaction is active.

Emits a problem.submitted event only if there is no current event transaction type, i.e. we have not reached this point in the code via an outer event type (such as problem.rescored or score_overridden).

lms.djangoapps.grades.events.subsection_grade_calculated(subsection_grade)#

Emits an edx.grades.subsection.grade_calculated event with data from the passed subsection_grade.

lms.djangoapps.grades.exceptions module#

Custom exceptions raised by grades.

exception lms.djangoapps.grades.exceptions.ScoreNotFoundError#

Bases: OSError

Subclass of IOError to indicate the staff has not yet graded the problem or the database has not yet committed the data we’re trying to find.

lms.djangoapps.grades.grade_utils module#

This module contains utility functions for grading.

lms.djangoapps.grades.grade_utils.are_grades_frozen(course_key)#

Returns whether grades are frozen for the given course.

lms.djangoapps.grades.models module#

Models used for robust grading.

Robust grading allows student scores to be saved per-subsection independent of any changes that may occur to the course after the score is achieved. We also persist students’ course-level grades, and update them whenever a student’s score or the course grading policy changes. As they are persisted, course grades are also immune to changes in course content.

class lms.djangoapps.grades.models.BlockRecord(locator, weight, raw_possible, graded)#

Bases: tuple

graded#

Alias for field number 3

locator#

Alias for field number 0

raw_possible#

Alias for field number 2

weight#

Alias for field number 1

class lms.djangoapps.grades.models.BlockRecordList(blocks, course_key, version=None)#

Bases: object

An immutable ordered list of BlockRecord objects.

classmethod from_json(blockrecord_json)#

Return a BlockRecordList from previously serialized json.

classmethod from_list(blocks, course_key)#

Return a BlockRecordList from the given list and course_key.

hash_value()#

Returns a hash value of the list of block records.

This currently hashes using sha1, and returns a base64 encoded version of the binary digest. In the future, different algorithms could be supported by adding a label indicated which algorithm was used, e.g., “sha256$j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ=”.

json_value()#

Return a JSON-serialized version of the list of block records, using a stable ordering.

class lms.djangoapps.grades.models.PersistentCourseGrade(*args, **kwargs)#

Bases: TimeStampedModel

A django model tracking persistent course grades.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

classmethod clear_prefetched_data(course_key)#

Clears prefetched grades for this course from the RequestCache.

course_edited_timestamp#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

course_id#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

course_version#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod delete_course_grade_for_learner(course_id, user_id)#

Clears course grade for a learner in a course :param course_id: The id of the course associated with the desired grade :param user_id: The user associated with the desired grade

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
grading_policy_hash#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

letter_grade#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
passed_timestamp#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

percent_grade#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod prefetch(course_id, users)#

Prefetches grades for the given users for the given course.

classmethod read(user_id, course_id)#

Reads a grade from database

Parameters:
  • user_id – The user associated with the desired grade

  • course_id – The id of the course associated with the desired grade

Raises PersistentCourseGrade.DoesNotExist if applicable

classmethod update_or_create(user_id, course_id, **kwargs)#

Creates a course grade in the database. Returns a PersistedCourseGrade object.

user_id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class lms.djangoapps.grades.models.PersistentSubsectionGrade(*args, **kwargs)#

Bases: TimeStampedModel

A django model tracking persistent grades at the subsection level.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

classmethod bulk_create_grades(grade_params_iter, user_id, course_key)#

Bulk creation of grades.

classmethod bulk_read_grades(user_id, course_key)#

Reads all grades for the given user and course.

Parameters:
  • user_id – The user associated with the desired grades

  • course_key – The course identifier for the desired grades

classmethod clear_prefetched_data(course_key)#

Clears prefetched grades for this course from the RequestCache.

course_id#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

course_version#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod delete_subsection_grades_for_learner(user_id, course_key)#

Clears Subsection grades and overrides for a learner in a course :param user_id: The user associated with the desired grade :param course_id: The id of the course associated with the desired grade

earned_all#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

earned_graded#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

first_attempted#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property full_usage_key#

Returns the “correct” usage key value with the run filled in.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
override#

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

possible_all#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

possible_graded#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod prefetch(course_key, users)#

Prefetches grades for the given users in the given course.

classmethod read_grade(user_id, usage_key)#

Reads a grade from database

Parameters:
  • user_id – The user associated with the desired grade

  • usage_key – The location of the subsection associated with the desired grade

Raises PersistentSubsectionGrade.DoesNotExist if applicable

subtree_edited_timestamp#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod update_or_create_grade(**params)#

Wrapper for objects.update_or_create.

usage_key#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

user_id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

visible_blocks#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

visible_blocks_id#
class lms.djangoapps.grades.models.PersistentSubsectionGradeOverride(*args, **kwargs)#

Bases: Model

A django model tracking persistent grades overrides at the subsection level.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

classmethod clear_prefetched_overrides_for_learner(user_id, course_key)#
created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

earned_all_override#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

earned_graded_override#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_history()#
get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<django.db.models.fields.DateTimeField: modified>, is_next=True, **kwargs)#
classmethod get_override(user_id, usage_key)#
get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<django.db.models.fields.DateTimeField: modified>, is_next=False, **kwargs)#
grade#

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

grade_id#
history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
override_reason#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

possible_all_override#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

possible_graded_override#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod prefetch(user_id, course_key)#
save_without_historical_record(*args, **kwargs)#

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

system#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod update_or_create_override(requesting_user, subsection_grade_model, feature=None, action=None, **override_data)#

Creates or updates an override object for the given PersistentSubsectionGrade. :param requesting_user: The user that is creating the override. :param subsection_grade_model: The PersistentSubsectionGrade object associated with this override. :param override_data: The parameters of score values used to create the override record.

class lms.djangoapps.grades.models.VisibleBlocks(*args, **kwargs)#

Bases: Model

A django model used to track the state of a set of visible blocks under a given subsection at the time they are used for grade calculation.

This state is represented using an array of BlockRecord, stored in the blocks_json field. A hash of this json array is used for lookup purposes.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

property blocks#

Returns the blocks_json data stored on this model as a list of BlockRecords in the order they were provided.

blocks_json#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod bulk_create(user_id, course_key, block_record_lists)#

Bulk creates VisibleBlocks for the given iterator of BlockRecordList objects and updates the VisibleBlocks cache for the block records’ course with the new VisibleBlocks. Returns the newly created visible blocks.

classmethod bulk_get_or_create(user_id, course_key, block_record_lists)#

Bulk creates VisibleBlocks for the given iterator of BlockRecordList objects for the given user and course_key, but only for those that aren’t already created.

classmethod bulk_read(user_id, course_key)#

Reads and returns all visible block records for the given user and course from the cache. The cache is initialized with the visible blocks for this user and course if no entry currently exists.

Parameters:

course_key – The course identifier for the desired records

classmethod cached_get_or_create(user_id, blocks)#

Given a user_id and a BlockRecordList object, attempts to fetch the related VisibleBlocks model from the request cache. This will create and save a new VisibleBlocks record if no record exists corresponding to the hash_value of blocks.

course_id#

DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!

A placeholder class that provides a way to set the attribute on the model.

hashed#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
persistentsubsectiongrade_set#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

lms.djangoapps.grades.models_api module#

Provides Python APIs exposed from Grades models.

lms.djangoapps.grades.models_api.clear_prefetched_course_and_subsection_grades(course_key)#
lms.djangoapps.grades.models_api.clear_prefetched_course_grades(course_key)#
lms.djangoapps.grades.models_api.clear_user_course_grades(user_id, course_key)#

Given a user_id and course_key, clears persistent grades for a learner in a course

lms.djangoapps.grades.models_api.get_recently_modified_grades(course_keys, start_date, end_date, users=None)#

Returns a QuerySet of PersistentCourseGrade objects filtered by the input parameters and ordered by modified date.

lms.djangoapps.grades.models_api.get_subsection_grade(user_id, course_key_or_id, usage_key_or_id)#

Find and return the earned subsection grade for user

lms.djangoapps.grades.models_api.get_subsection_grade_override(user_id, course_key_or_id, usage_key_or_id)#

Finds the subsection grade for user and returns the override for that grade if it exists

If override does not exist, returns None. If subsection grade does not exist, will raise an exception.

lms.djangoapps.grades.models_api.get_subsection_grades(user_id, course_key_or_id)#

Return dictionary of grades for user_id.

lms.djangoapps.grades.models_api.prefetch_course_and_subsection_grades(course_key, users)#
lms.djangoapps.grades.models_api.prefetch_course_grades(course_key, users)#
lms.djangoapps.grades.models_api.prefetch_grade_overrides_and_visible_blocks(user, course_key)#
lms.djangoapps.grades.models_api.update_or_create_override(grade, **kwargs)#

Update or creates a subsection override.

lms.djangoapps.grades.score_render module#

Score rendering when submission is evaluated for external grader and has been saved successfully

lms.djangoapps.grades.score_render.get_block_for_descriptor_without_access_check(user, block, student_data, course_key, course=None)#

Modified version of get_block_for_descriptor that skips access checks for system operations.

lms.djangoapps.grades.score_render.load_xblock_for_external_grader(user_id: str, course_key: CourseKey, usage_key: UsageKey, course=None)#

Load a single XBlock for external grading without user access checks.

lms.djangoapps.grades.scores module#

Functionality for problem scores.

lms.djangoapps.grades.scores.compute_percent(earned, possible)#

Returns the percentage of the given earned and possible values.

lms.djangoapps.grades.scores.get_score(submissions_scores, csm_scores, persisted_block, block)#

Returns the score for a problem, as a ProblemScore object. It is assumed that the provided storages have already been filtered for a single user in question and have user-specific values.

The score is retrieved from the provided storages in the following order of precedence. If no value for the block is found in a given storage, the next storage is checked.

submissions_scores (dict of {unicode(usage_key): (earned, possible)}):

A python dictionary of serialized UsageKeys to (earned, possible) tuples. These values, retrieved using the Submissions API by the caller (already filtered for the user and course), take precedence above all other score storages.

When the score is found in this storage, it implies the user’s score for the block was persisted via the submissions API. Typically, this API is used by ORA.

The returned score includes valid values for:

weighted_earned weighted_possible graded - retrieved from the persisted block, if found, else from

the latest block content.

Note: raw_earned and raw_possible are not required when submitting scores via the submissions API, so those values (along with the unused weight) are invalid and irrelevant.

csm_scores (ScoresClient):

The ScoresClient object (already filtered for the user and course), from which a courseware.models.StudentModule object can be retrieved for the block.

When the score is found from this storage, it implies the user’s score for the block was persisted in the Courseware Student Module. Typically, this storage is used for all CAPA problems, including scores calculated by external graders.

The returned score includes valid values for:

raw_earned, raw_possible - retrieved from CSM weighted_earned, weighted_possible - calculated from the raw scores and weight weight, graded - retrieved from the persisted block, if found,

else from the latest block content

persisted_block (.models.BlockRecord):

The block values as found in the grades persistence layer. These values are used only if not found from an earlier storage, and take precedence over values stored within the latest content-version of the block.

When the score is found from this storage, it implies the user has not yet attempted this problem, but the user’s grade _was_ persisted.

The returned score includes valid values for:
raw_earned - will equal 0.0 since the user’s score was not found from

earlier storages

raw_possible - retrieved from the persisted block weighted_earned, weighted_possible - calculated from the raw scores and weight weight, graded - retrieved from the persisted block

block (block_structure.BlockData):

Values from the latest content-version of the block are used only if they were not available from a prior storage.

When the score is found from this storage, it implies the user has not yet attempted this problem and the user’s grade was _not_ yet persisted.

The returned score includes valid values for:
raw_earned - will equal 0.0 since the user’s score was not found from

earlier storages

raw_possible - retrieved from the latest block content weighted_earned, weighted_possible - calculated from the raw scores and weight weight, graded - retrieved from the latest block content

lms.djangoapps.grades.scores.possibly_scored(usage_key)#

Returns whether the given block could impact grading (i.e. has_score or has_children).

lms.djangoapps.grades.scores.weighted_score(raw_earned, raw_possible, weight)#

Returns a tuple that represents the weighted (earned, possible) score. If weight is None or raw_possible is 0, returns the original values.

When weight is used, it defines the weighted_possible. This allows course authors to specify the exact maximum value for a problem when they provide a weight.

lms.djangoapps.grades.services module#

Grade service

class lms.djangoapps.grades.services.GradesService#

Bases: object

Course grade service

Provides various functions related to getting, setting, and overriding user grades.

get_subsection_grade(user_id, course_key_or_id, usage_key_or_id)#

Finds and returns the earned subsection grade for user

get_subsection_grade_override(user_id, course_key_or_id, usage_key_or_id)#

Finds the subsection grade for user and returns the override for that grade if it exists

If override does not exist, returns None. If subsection grade does not exist, will raise an exception.

override_subsection_grade(user_id, course_key_or_id, usage_key_or_id, earned_all=None, earned_graded=None, feature='PROCTORING', overrider=None, comment=None)#

Creates a PersistentSubsectionGradeOverride corresponding to the given user, course, and usage_key. Will also create a PersistentSubsectionGrade for this (user, course, usage_key) if none currently exists.

Fires off a recalculate_subsection_grade async task to update the PersistentCourseGrade table. Will not override earned_all or earned_graded value if they are None. Both of these parameters have None as their default value.

should_override_grade_on_rejected_exam(course_key_or_id)#

Convenience function to return the state of the CourseWaffleFlag REJECTED_EXAM_OVERRIDES_GRADE

undo_override_subsection_grade(user_id, course_key_or_id, usage_key_or_id, feature='PROCTORING')#

Delete the override subsection grade row (the PersistentSubsectionGrade model must already exist)

Fires off a recalculate_subsection_grade async task to update the PersistentSubsectionGrade table. If the override does not exist, no error is raised, it just triggers the recalculation.

lms.djangoapps.grades.subsection_grade module#

SubsectionGrade Class

class lms.djangoapps.grades.subsection_grade.CreateSubsectionGrade(subsection, course_structure, submissions_scores, csm_scores)#

Bases: NonZeroSubsectionGrade

Class for Subsection grades that are newly created or updated.

classmethod bulk_create_models(student, subsection_grades, course_key)#

Saves the subsection grade in a persisted model.

update_or_create_model(student, score_deleted=False, force_update_subsections=False)#

Saves or updates the subsection grade in a persisted model.

class lms.djangoapps.grades.subsection_grade.NonZeroSubsectionGrade(subsection, all_total, graded_total, override=None)#

Bases: SubsectionGradeBase

Abstract base class for Subsection Grades with possibly NonZero values.

property attempted_graded#

Returns whether the user had attempted a graded problem in this subsection.

property percent_graded#

Returns the percent score of the graded problems in this subsection.

class lms.djangoapps.grades.subsection_grade.ReadSubsectionGrade(subsection, model, factory)#

Bases: NonZeroSubsectionGrade

Class for Subsection grades that are read from the database.

problem_scores()#

Returns the scores of the problem blocks that compose this subsection. NOTE: The use of course_data.structure here is very intentional. It means we look through the user-specific subtree of this subsection, taking into account which problems are visible to the user.

class lms.djangoapps.grades.subsection_grade.SubsectionGradeBase(subsection)#

Bases: object

Abstract base class for Subsection Grades.

property attempted#

Returns whether any problem in this subsection was attempted by the student.

property attempted_graded#

Returns whether the user had attempted a graded problem in this subsection.

property percent_graded#

Returns the percent score of the graded problems in this subsection.

show_grades(has_staff_access)#

Returns whether subsection scores are currently available to users with or without staff access.

class lms.djangoapps.grades.subsection_grade.ZeroSubsectionGrade(subsection, course_data)#

Bases: SubsectionGradeBase

Class for Subsection Grades with Zero values.

property all_total#

Returns the total score (earned and possible) amongst all problems (graded and ungraded) in this subsection. NOTE: This will traverse this subsection’s subtree to determine problem scores. If self.course_data.structure is currently null, this means we will first fetch the user-specific course structure from the data store!

property attempted_graded#

Returns whether the user had attempted a graded problem in this subsection.

property graded_total#

Returns the total score (earned and possible) amongst all graded problems in this subsection. NOTE: This will traverse this subsection’s subtree to determine problem scores. If self.course_data.structure is currently null, this means we will first fetch the user-specific course structure from the data store!

property percent_graded#

Returns the percent score of the graded problems in this subsection.

problem_scores()#

Overrides the problem_scores member variable in order to return empty scores for all scorable problems in the course. NOTE: The use of course_data.structure here is very intentional. It means we look through the user-specific subtree of this subsection, taking into account which problems are visible to the user.

lms.djangoapps.grades.subsection_grade_factory module#

SubsectionGrade Factory Class

class lms.djangoapps.grades.subsection_grade_factory.SubsectionGradeFactory(student, course=None, course_structure=None, course_data=None)#

Bases: object

Factory for Subsection Grades.

bulk_create_unsaved()#

Bulk creates all the unsaved subsection_grades to this point.

create(subsection, read_only=False, force_calculate=False)#

Returns the SubsectionGrade object for the student and subsection.

If read_only is True, doesn’t save any updates to the grades. force_calculate - If true, will cause this function to return a CreateSubsectionGrade object if no cached grade currently exists.

update(subsection, only_if_higher=None, score_deleted=False, force_update_subsections=False, persist_grade=True)#

Updates the SubsectionGrade object for the student and subsection.

lms.djangoapps.grades.tasks module#

This module contains tasks for asynchronous execution of grade updates.

lms.djangoapps.grades.transformer module#

Grades Transformer

class lms.djangoapps.grades.transformer.GradesTransformer#

Bases: BlockStructureTransformer

The GradesTransformer collects grading information and stores it on the block structure.

No runtime transformations are performed.

The following values are stored as xblock_fields on their respective blocks in the block structure:

due: (datetime) when the problem is due. format: (string) what type of problem it is graded: (boolean) has_score: (boolean) weight: (numeric) show_correctness: (string) when to show grades (one of ‘always’, ‘past_due’, ‘never’)

Additionally, the following value is calculated and stored as a transformer_block_field for each block:

max_score: (numeric)

EXPLICIT_GRADED_FIELD_NAME = 'explicit_graded'#
FIELDS_TO_COLLECT = ['due', 'format', 'graded', 'has_score', 'weight', 'course_version', 'subtree_edited_on', 'show_correctness']#
READ_VERSION = 4#
WRITE_VERSION = 4#
classmethod collect(block_structure)#

Collects any information that’s necessary to execute this transformer’s transform method.

classmethod grading_policy_hash(course)#

Returns the grading policy hash for the given course.

classmethod name()#

Unique identifier for the transformer’s class. This must match the entry point name in the package configuration.

transform(block_structure, usage_context)#

Perform no transformations.

lms.djangoapps.grades.util_services module#

A light weight interface to grading helper functions

class lms.djangoapps.grades.util_services.GradesUtilService(**kwargs)#

Bases: object

An interface to be used by xblocks.

are_grades_frozen()#

Check if grades are frozen for given course key

Module contents#