def generate_course_certificates(course_id, action_name): """ Generate course certificates while monitoring the progress in the admin in a TaskProgress object. """ # generate a test certificate test_certificate = create_test_certificate(course_id) # generate real certificate for students task_progress = TaskProgress(action_name, get_enrolled_students_count(course_id), time()) progress_status = { status.notpassing: 0, status.error: 0, status.downloadable: 0, 'test_certificate_filename': test_certificate.filename } task_progress.update_task_state(extra_meta=progress_status) for student_status in iter_generated_course_certificates(course_id): task_progress.attempted += 1 if student_status is None: task_progress.skipped += 1 else: task_progress.succeeded += 1 progress_status[student_status] += 1 task_progress.update_task_state(extra_meta=progress_status) return task_progress.update_task_state(extra_meta=progress_status)
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})