lms.djangoapps.instructor_analytics package#

Subpackages#

Submodules#

lms.djangoapps.instructor_analytics.basic module#

Student and course analytics.

Serve miscellaneous course and student data

lms.djangoapps.instructor_analytics.basic.coupon_codes_features(features, coupons_list, course_id)#

Return list of Coupon Codes as dictionaries.

coupon_codes_features would return [

{‘course_id’: ‘edX/Open_DemoX/edx_demo_course,, ‘discount’: ‘213’ ….. } {‘course_id’: ‘edX/Open_DemoX/edx_demo_course,, ‘discount’: ‘234’ ….. }

]

lms.djangoapps.instructor_analytics.basic.course_registration_features(features, registration_codes, csv_type)#

Return list of Course Registration Codes as dictionaries.

course_registration_features would return [

{‘code’: ‘code1’, ‘course_id’: ‘edX/Open_DemoX/edx_demo_course, ….. } {‘code’: ‘code2’, ‘course_id’: ‘edX/Open_DemoX/edx_demo_course, ….. }

]

lms.djangoapps.instructor_analytics.basic.dump_grading_context(course)#

Render information about course grading context (e.g. which problems are graded in what assignments) Useful for debugging grading_policy.json and policy.json

Returns HTML string

lms.djangoapps.instructor_analytics.basic.enrolled_students_features(course_key, features)#

Return list of student features as dictionaries.

enrolled_students_features(course_key, [‘username’, ‘first_name’]) would return [

{‘username’: ‘username1’, ‘first_name’: ‘firstname1’} {‘username’: ‘username2’, ‘first_name’: ‘firstname2’} {‘username’: ‘username3’, ‘first_name’: ‘firstname3’}

]

lms.djangoapps.instructor_analytics.basic.get_available_features(course_key)#

Return all available features including custom student attributes for a course.

This function dynamically builds the available features list by combining standard features with any custom attributes configured for the course organization.

Parameters:

course_key – CourseKey object for the course

Returns:

Combined tuple of all available features (standard + custom)

Return type:

tuple

lms.djangoapps.instructor_analytics.basic.get_enrollments_for_course(exam_attempts)#

Returns all enrollments from a list of attempts. user_id is passed from proctoring.

lms.djangoapps.instructor_analytics.basic.get_proctored_exam_results(course_key, features)#

Return info about proctored exam results in a course as a dict.

lms.djangoapps.instructor_analytics.basic.get_response_state(response)#

Returns state of a particular response as string.

This method also does necessary encoding for displaying unicode data correctly.

lms.djangoapps.instructor_analytics.basic.get_student_features_with_custom(course_key)#

Allow site operators to include custom fields in student profile exports.

This function enables platforms with extended User models to include additional fields in CSV exports by configuring site settings and adding properties to the User model.

Basic example of adding age from user profile: ```python def get_age(self):

if hasattr(self, ‘profile’) and self.profile.year_of_birth:

return datetime.datetime.now().year - self.profile.year_of_birth

return None

User.age = property(get_age) ```

Example with extended User model (One-To-One relationship): ```python def get_student_number(self):

try:

return self.userextendedmodel.student_number

except UserExtendedModel.DoesNotExist:

return None

def get_employment_status(self):
try:

return self.userextendedmodel.employment_status

except UserExtendedModel.DoesNotExist:

return None

User.student_number = property(get_student_number) User.employment_status = property(get_employment_status) ```

Site configuration required for these new 3 extra fields: ```json {

“additional_student_profile_attributes”: [

“age”, “student_number”, “employment_status”

], “course_org_filter”: [“your-org”]

}#

Important notes: - Custom attributes are automatically added to the standard student features - If the extended model is guaranteed to exist, the try/except can be omitted - Properties must be added to the User model before this function is called

param course_key:

CourseKey object for the course

returns:

Combined tuple of standard STUDENT_FEATURES and custom attributes

rtype:

tuple

lms.djangoapps.instructor_analytics.basic.issued_certificates(course_key, features)#

Return list of issued certificates as dictionaries against the given course key.

issued_certificates(course_key, features) would return [

{course_id: ‘abc’, ‘total_issued_certificate’: ‘5’, ‘mode’: ‘honor’} {course_id: ‘abc’, ‘total_issued_certificate’: ‘10’, ‘mode’: ‘verified’} {course_id: ‘abc’, ‘total_issued_certificate’: ‘15’, ‘mode’: ‘Professional Education’}

]

lms.djangoapps.instructor_analytics.basic.list_inactive_enrolled_students(course_key, features)#

Return info about students who are enrolled in a course but have not activated their account.

list_enrolled_inactive_students(course_key, [‘email’]) would return [

{‘email’: ‘email1’} {‘email’: ‘email2’} {‘email’: ‘email3’}

]

lms.djangoapps.instructor_analytics.basic.list_may_enroll(course_key, features)#

Return info about students who may enroll in a course as a dict.

list_may_enroll(course_key, [‘email’]) would return [

{‘email’: ‘email1’} {‘email’: ‘email2’} {‘email’: ‘email3’}

]

Note that result does not include students who may enroll and have already done so.

lms.djangoapps.instructor_analytics.basic.list_problem_responses(course_key, problem_location, limit_responses=None)#

Return responses to a given problem as a dict.

list_problem_responses(course_key, problem_location)

would return [

{‘username’: u’user1’, ‘state’: u’…’}, {‘username’: u’user2’, ‘state’: u’…’}, {‘username’: u’user3’, ‘state’: u’…’},

]

where state represents a student’s response to the problem identified by problem_location.

lms.djangoapps.instructor_analytics.basic.transform_capa_state(state)#

Transforms the CAPA problem state.

lms.djangoapps.instructor_analytics.basic.transform_ora_state(state)#

ORA problem state transformer transforms the problem states.

Some state variables values are json dumped strings which needs to be loaded into a python object.

lms.djangoapps.instructor_analytics.csvs module#

Student and course analytics.

Format and create csv responses

lms.djangoapps.instructor_analytics.csvs.create_csv_response(filename, header, datarows)#

Create an HttpResponse with an attached .csv file

header e.g. [‘Name’, ‘Email’] datarows e.g. [[‘Jim’, ‘jim@edy.org’], [‘Jake’, ‘jake@edy.org’], …]

The data in header and datarows must be either Unicode strings, or ASCII-only bytestrings.

lms.djangoapps.instructor_analytics.csvs.format_dictlist(dictlist, features)#

Convert a list of dictionaries to be compatible with create_csv_response

dictlist is a list of dictionaries

all dictionaries should have keys from features

features is a list of features

example code: dictlist = [

{

‘label1’: ‘value-1,1’, ‘label2’: ‘value-1,2’, ‘label3’: ‘value-1,3’, ‘label4’: ‘value-1,4’,

}, {

‘label1’: ‘value-2,1’, ‘label2’: ‘value-2,2’, ‘label3’: ‘value-2,3’, ‘label4’: ‘value-2,4’,

}

]

header, datarows = format_dictlist(dictlist, [‘label1’, ‘label4’])

# results in header = [‘label1’, ‘label4’] datarows = [[‘value-1,1’, ‘value-1,4’],

[‘value-2,1’, ‘value-2,4’]]

}

lms.djangoapps.instructor_analytics.csvs.format_instances(instances, features)#

Convert a list of instances into a header list and datarows list.

header is just features e.g. [‘username’, ‘email’] datarows is a list of lists, each sublist representing a row in a table

e.g. [[‘username1’, ‘email1@email.com’], [‘username2’, ‘email2@email.com’]] for instances of length 2.

instances is a list of instances, e.g. list of User’s features is a list of features

a feature is a string for which getattr(obj, feature) is valid

Returns header and datarows, formatted for input in create_csv_response

lms.djangoapps.instructor_analytics.distributions module#

Profile Distributions

Aggregate sums for values of fields in students profiles.

For example: The distribution in a course for gender might look like: ‘gender’: {

‘type’: ‘EASY_CHOICE’, ‘data’: {

‘no_data’: 1234, ‘m’: 5678, ‘o’: 2134, ‘f’: 5678

}, ‘display_names’: {

‘no_data’: ‘No Data’, ‘m’: ‘Male’, ‘o’: ‘Other’, ‘f’: ‘Female’

}

class lms.djangoapps.instructor_analytics.distributions.ProfileDistribution(feature)#

Bases: object

Container for profile distribution data

feature is the name of the distribution feature feature_display_name is the display name of feature data is a dictionary of the distribution type is either ‘EASY_CHOICE’ or ‘OPEN_CHOICE’ choices_display_names is a dict if the distribution is an ‘EASY_CHOICE’

exception ValidationError#

Bases: ValueError

Error thrown if validation fails.

validate()#

Validate this profile distribution.

Throws ProfileDistribution.ValidationError

lms.djangoapps.instructor_analytics.distributions.profile_distribution(course_id, feature)#

Retrieve distribution of students over a given feature. feature is one of AVAILABLE_PROFILE_FEATURES.

Returns a ProfileDistribution instance.

NOTE: no_data will appear as a key instead of None/null to adhere to the json spec. data types are EASY_CHOICE or OPEN_CHOICE

Module contents#