Ejemplo n.º 1
0
def get_progress_for_course(user, course_prefix):
    """ DEPRECATED: Use get_total_progress_for_course instead!
      Returns a progess dict for the overall percentage of the course complete and an array of track
      percentages (in the order they appear in app.yaml) for the given course-prefix. """
    track_progress = []
    course_tasks_completed = 0
    total_course_tasks = 0
    all_course_app_contexts = controllers.sites.get_all_courses()
    for course_app_context in all_course_app_contexts:
        url_path = course_app_context.slug
        if not url_path.startswith("/" + course_prefix + "-"):
            continue
        namespace_manager.set_namespace(course_app_context.namespace)
        student = Student.get_by_email(user.email())
        course = CourseModel12.load(course_app_context)
        tracker = progress.UnitLessonCompletionTracker(course)
        if student:
            lesson_breakdown = tracker.get_task_progress(student)
            track_tasks_completed = 0
            total_track_tasks = 0
            for unit_tasks_completed, total_unit_tasks in lesson_breakdown.values(
            ):
                track_tasks_completed += unit_tasks_completed
                total_track_tasks += total_unit_tasks
            track_progress.append(track_tasks_completed /
                                  float(total_track_tasks))
            course_tasks_completed += track_tasks_completed
            total_course_tasks += total_track_tasks
            logging.info(
                "Lesson progress in %s:  %d of %d tasks completed" %
                (url_path, track_tasks_completed / 2, total_track_tasks / 2))
        else:
            track_progress.append(0)
            total_track_tasks = tracker.get_task_total()
            total_course_tasks += total_track_tasks
            logging.info("Student not enrolled in %s, which has %d tasks" %
                         (url_path, total_track_tasks / 2))
    namespace_manager.set_namespace("")
    return {
        "course": course_tasks_completed / float(total_course_tasks),
        "tracks": track_progress
    }
Ejemplo n.º 2
0
 def __init__(self, course):
     self._course = course
     self.id_to_questions_dict = progress.UnitLessonCompletionTracker(
         course).get_id_to_questions_dict()
     self.id_to_assessments_dict = progress.UnitLessonCompletionTracker(
         course).get_id_to_assessments_dict()
Ejemplo n.º 3
0
 def __init__(self, course):
     self.progress_data = {}
     self._tracker = progress.UnitLessonCompletionTracker(course)
Ejemplo n.º 4
0
def get_total_progress_for_course(email,
                                  course_prefix,
                                  as_percent=True,
                                  get_total_tasks=False):
    """ Returns a progess dict for the overall percentage of the course complete and an array of track
      percentages, which is a dictionary of the total progress in the course and the progress of each
      unit, (in the order they appear in app.yaml) for the given course-prefix. 
      as_percent is used to specify if the unit's are expressed in percentage or as number of completed tasks
      with the 'get_total_tasks' flag each unit will have another entry called unitid-total that will be the number of total tasks in the unit """
    track_progress = []
    course_tasks_completed = 0
    total_course_tasks = 0
    all_course_app_contexts = controllers.sites.get_all_courses()
    for course_app_context in all_course_app_contexts:
        url_path = course_app_context.slug
        if not url_path.startswith("/" + course_prefix + "-"):
            continue
        namespace_manager.set_namespace(course_app_context.namespace)
        student = Student.get_by_email(email)
        course = CourseModel12.load(course_app_context)
        tracker = progress.UnitLessonCompletionTracker(course)
        if student:
            lesson_breakdown = tracker.get_task_progress_with_title(student)
            track_tasks_completed = 0
            total_track_tasks = 0
            units = {}
            for unit_title, unit in lesson_breakdown.items():
                track_tasks_completed += unit[0]
                total_track_tasks += unit[1]
                if as_percent:
                    units[unit_title] = unit[0] / float(unit[1])
                else:
                    units[unit_title] = unit[0] / 2
                if get_total_tasks:
                    units[unit_title + "-total"] = unit[1] / 2
            track_progress.append({
                'name':
                course_app_context.get_title(),
                'url':
                url_path,
                'track':
                track_tasks_completed / float(total_track_tasks),
                'units':
                units,
                'blurb':
                course_app_context.get_environ()['course']['blurb'].strip()
            })
            course_tasks_completed += track_tasks_completed
            total_course_tasks += total_track_tasks
            logging.info(
                "Lesson progress in %s:  %d of %d tasks completed" %
                (url_path, track_tasks_completed / 2, total_track_tasks / 2))
        else:
            track = {
                'name':
                course_app_context.get_title(),
                'track':
                0,
                'url':
                url_path,
                'units': {},
                'blurb':
                course_app_context.get_environ()['course']['blurb'].strip()
            }
            total_track_tasks = tracker.get_task_total()
            for unit in tracker.get_course_units():
                track['units'][unit.unit_id + ":" + unit.title] = 0
                if get_total_tasks:
                    unit_tasks = tracker.get_num_tasks_for_unit(unit)
                    track['units'][unit.unit_id + ":" + unit.title +
                                   "-total"] = unit_tasks
            total_course_tasks += total_track_tasks
            track_progress.append(track)
            logging.info("Student not enrolled in %s, which has %d tasks" %
                         (url_path, total_track_tasks / 2))
    namespace_manager.set_namespace("")
    if total_course_tasks == 0:
        logging.warn('WARNING: track %s has 0 total tasks' % url_path)
        total_course_tasks = 1
    return {
        "course": course_tasks_completed / float(total_course_tasks),
        "tracks": track_progress
    }