Exemple #1
0
def generate(request, course_id, problem_id):
    """ Submit 'generate_answers_distribution_report' task to celery.

    Args:
         course_id (str): The course id as string.
         problem_id (str): The problem id as string.

    Return:
         Redirect to Report Manager dashboard.
    """
    store = modulestore()
    course_key = get_course_key(course_id)
    problem = fetch_problem(store, course_key, problem_id)

    running_report_name = build_answers_distribution_report_name(problem)

    input_args = {'problem_id' : problem_id,
                  'running_report_name' : running_report_name}

    try:
        submit_generate_answers_distribution_report(request, course_key, input_args)
        return redirect('course-dashboard:reports-manager:dashboard', course_id)
    except AlreadyRunningError:
        messages.warning(request, _("A report on answers distribution is already running"))
        return redirect('course-dashboard:reports-manager:dashboard', course_id)
Exemple #2
0
def generate_answers_distribution_report(_entry_id, course_descriptor, _task_input, action_name):
    """ Main task to generate answers distribution as csv.

    Csv structure will be as follow:
       'id', 'gender', 'year_of_birth', 'level_of_education', q1,      , q2
        15,     f    ,    1989        ,    m                , choice 1 , choice 2

    Args:
         _entry_id (str): Instructor task id (not used).
         course_descriptor (CourseDescriptor)
         _task_input (dict): Task input paprameters.
             E.g. : {'problem_id' : '42',
                     'running_report_name' : u"fun_course_quizz-04-05-153143.csv"}
         action_name (str) : Instructor task action name (not used).

    Returns:
         The progress state of the task (TaskProgress)
    """
    task_progress = TaskProgress(action_name, 1, time())
    task_progress.update_task_state()

    store = modulestore()
    problem = fetch_problem(store, course_descriptor, _task_input['problem_id'])
    problem_size = get_problem_size(problem)
    header_row = create_header_row(problem_size)
    data_rows = fetch_student_answers(problem, problem_size)
    ancestors_row = fetch_ancestors_names(store, problem.location)
    path = get_path(_task_input['running_report_name'], problem.location)
    write_csv(header_row, data_rows, ancestors_row, path)
    return task_progress.update_task_state({'succeeded': 1})
Exemple #3
0
def generate_answers_distribution_report(_entry_id, course_descriptor,
                                         _task_input, action_name):
    """ Main task to generate answers distribution as csv.

    Csv structure will be as follow:
       'id', 'gender', 'year_of_birth', 'level_of_education', q1,      , q2
        15,     f    ,    1989        ,    m                , choice 1 , choice 2

    Args:
         _entry_id (str): Instructor task id (not used).
         course_descriptor (CourseDescriptor)
         _task_input (dict): Task input paprameters.
             E.g. : {'problem_id' : '42',
                     'running_report_name' : u"fun_course_quizz-04-05-153143.csv"}
         action_name (str) : Instructor task action name (not used).

    Returns:
         The progress state of the task (TaskProgress)
    """
    task_progress = TaskProgress(action_name, 1, time())
    task_progress.update_task_state()

    store = modulestore()
    problem = fetch_problem(store, course_descriptor,
                            _task_input['problem_id'])
    problem_size = get_problem_size(problem)
    header_row = create_header_row(problem_size)
    data_rows = fetch_student_answers(problem, problem_size)
    ancestors_row = fetch_ancestors_names(store, problem.location)
    path = get_path(_task_input['running_report_name'], problem.location)
    write_csv(header_row, data_rows, ancestors_row, path)
    return task_progress.update_task_state({'succeeded': 1})
Exemple #4
0
def generate(request, course_id, problem_id):
    """ Submit 'generate_answers_distribution_report' task to celery.

    Args:
         course_id (str): The course id as string.
         problem_id (str): The problem id as string.

    Return:
         Redirect to Report Manager dashboard.
    """
    store = modulestore()
    course_key = get_course_key(course_id)
    problem = fetch_problem(store, course_key, problem_id)

    running_report_name = build_answers_distribution_report_name(problem)

    input_args = {
        'problem_id': problem_id,
        'running_report_name': running_report_name
    }

    try:
        submit_generate_answers_distribution_report(request, course_key,
                                                    input_args)
        return redirect('course-dashboard:reports-manager:dashboard',
                        course_id)
    except AlreadyRunningError:
        messages.warning(
            request, _("A report on answers distribution is already running"))
        return redirect('course-dashboard:reports-manager:dashboard',
                        course_id)
Exemple #5
0
 def test_fetch_problem_with_id(self):
     problem_id = 'problem1'
     ItemFactory(parent=self.course,
                 category='problem',
                 display_name=problem_id)
     problem = utils.fetch_problem(self.store,
                                   self.course.id,
                                   problem_id=problem_id)
     self.assertTrue(problem, isinstance(problem, CapaDescriptor))
Exemple #6
0
def get_stats(request, course_id, problem_id):
    """ et stats for a single problem (LoncapaProblem).

    The problem id is passed has a GET paramater with 'problem_id' key.

    Args:
         course_id (str): The course id as string.
     """
    start_time = time.time()
    store = modulestore()
    course_key = CourseKey.from_string(course_id)

    problem = utils.fetch_problem(store, course_key, problem_id)
    problem_monitor = ProblemMonitor(problem)
    problem_monitor.get_student_answers()
    tracker.emit("course_dashboard.problem_stats.views.get_stats",
                 {'task-time' : time.time() - start_time})

    return HttpResponse(problem_monitor.get_html())
Exemple #7
0
def get_stats(request, course_id, problem_id):
    """ et stats for a single problem (LoncapaProblem).

    The problem id is passed has a GET paramater with 'problem_id' key.

    Args:
         course_id (str): The course id as string.
     """
    start_time = time.time()
    store = modulestore()
    course_key = CourseKey.from_string(course_id)

    try:
        problem = utils.fetch_problem(store, course_key, problem_id)
    except ItemNotFoundError:
        raise Http404()
    problem_monitor = ProblemMonitor(problem)
    problem_monitor.get_student_answers()
    tracker.emit("course_dashboard.problem_stats.views.get_stats",
                 {'task-time': time.time() - start_time})

    return HttpResponse(problem_monitor.get_html())
Exemple #8
0
 def test_fetch_problem_with_id(self):
     problem_id = 'problem1'
     ItemFactory(parent=self.course, category='problem', display_name=problem_id)
     problem = utils.fetch_problem(self.store, self.course.id, problem_id=problem_id)
     self.assertTrue(problem, isinstance(problem, CapaDescriptor))