Ejemplo n.º 1
0
    def __init__(self, course_id):
        """
        Initial version, we pass in a course ID and cast to a course key as an
        instance attribute. Later on, add `CourseLike` to abstract course identity
        so we can stop worrying about "Is it a string repretentation of a course or
        is it a CourseKey?"
        """
        self.course_key = as_course_key(course_id)

        # Improvement: Consider doing lazy evaluation
        self.site = get_site_for_course(self.course_id)
Ejemplo n.º 2
0
def bulk_calculate_course_progress_data(course_id, date_for=None):
    """Calculates the average progress for a set of course enrollments

    How it works
    1. collects progress percent for each course enrollment
        1.1. If up to date enrollment metrics record already exists, use that
    2. calculate and return the average of these enrollments

    TODO: Update to filter on active users

    Questions:
    - What makes a learner an active learner?

    """
    progress_percentages = []

    if not date_for:
        date_for = datetime.utcnow().replace(tzinfo=utc).date()

    site = get_site_for_course(course_id)
    if not site:
        raise UnlinkedCourseError(
            'No site found for course "{}"'.format(course_id))

    course_sm = get_student_modules_for_course_in_site(site=site,
                                                       course_id=course_id)
    for ce in course_enrollments_for_course(course_id):
        metrics = collect_metrics_for_enrollment(site=site,
                                                 course_enrollment=ce,
                                                 course_sm=course_sm,
                                                 date_for=date_for)
        if metrics:
            progress_percentages.append(metrics.progress_percent)
        else:
            # Log this for troubleshooting
            error_data = dict(
                msg=('Unable to create or retrieve enrollment metrics ' +
                     'for user {} and course {}'.format(
                         ce.user.username, str(ce.course_id))))
            log_error(error_data=error_data,
                      error_type=PipelineError.COURSE_DATA,
                      user=ce.user,
                      course_id=str(course_id))

    return dict(
        average_progress=calculate_average_progress(progress_percentages), )
Ejemplo n.º 3
0
def bulk_calculate_course_progress_data(course_id, date_for=None):
    """Calculates the average progress for a set of course enrollments

    How it works
    1. collects progress percent for each course enrollment
        1.1. If an up to date enrollment metrics record already exists, use that
    2. calculate and return the average of these enrollments

    TODO: Update to filter on active users

    Questions:
    - What makes a learner an active learner?

    """
    progress_percentages = []
    if not date_for:
        date_for = datetime.utcnow().replace(tzinfo=utc).date()

    site = get_site_for_course(course_id)
    if not site:
        raise UnlinkedCourseError(
            'No site found for course "{}"'.format(course_id))

    # We might be able to make this more efficient by finding only the learners
    # in the course with StudentModule (SM) records then get their course
    # enrollment (CE) records as we can ignore any learners without SM records
    # since that means they don't have any course progress
    for ce in course_enrollments_for_course(course_id):
        sm = student_modules_for_course_enrollment(
            site=site, course_enrollment=ce).order_by('-modified')
        if sm:
            metrics = collect_metrics_for_enrollment(site=site,
                                                     course_enrollment=ce,
                                                     date_for=date_for,
                                                     student_modules=sm)
            if metrics:
                progress_percentages.append(metrics.progress_percent)

    return dict(
        average_progress=calculate_average_progress(progress_percentages), )
Ejemplo n.º 4
0
 def assert_construction(self, course):
     assert course.course_key == self.course_overview.id
     assert course.course_id == str(self.course_overview.id)
     assert course.site == get_site_for_course(self.course_overview.id)