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})
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_certificate(_xmodule_instance_args, _entry_id, course_id, _task_input, action_name): """ Generate a certificate for graduated students """ course = modulestore().get_course(course_id, depth=2) course_key = get_course_key(str(course_id)) course_display_name = unicode(course.display_name).encode('utf-8') university = University.objects.get(code=course.location.org) certificate_base_filename = "attestation_suivi_" + (course_id.to_deprecated_string().replace('/', '_')) + '_' start_time = time() start_date = datetime.now(UTC) status_interval = 1 enrolled_students = get_enrolled_students(course_id) teachers = get_teachers_list_from_course(course_id.to_deprecated_string()) task_progress = TaskProgress(action_name, enrolled_students.count(), start_time) # generate a test certificate test_certificate = create_test_certificate(course, course_key, university) all_status = {status.notpassing: 0, status.error: 0, status.downloadable: 0, 'test_certificate_filename' : test_certificate.filename} for count, student in enumerate(enrolled_students): task_progress.attempted += 1 if task_progress.attempted % status_interval == 0: task_progress.update_task_state(extra_meta=all_status) if certificate_status_for_student(student, course_id)['status'] != status.downloadable: if university.certificate_logo: logo_path = os.path.join(university.certificate_logo.url, university.certificate_logo.path) else: logo_path = None student_status = generate_fun_certificate(student, course_id, course_display_name, course, teachers, university.name, logo_path, certificate_base_filename, False, False, False) if student_status: all_status[student_status] += 1 task_progress.succeeded += 1 else: task_progress.failed += 1 else: all_status[status.downloadable] += 1 return task_progress.update_task_state(extra_meta=all_status)