예제 #1
0
def upload_csv_to_report_store(rows,
                               csv_name,
                               course_id,
                               timestamp,
                               config_name='GRADES_DOWNLOAD',
                               parent_dir=''):
    """
    Upload data as a CSV using ReportStore.

    Arguments:
        rows: CSV data in the following format (first column may be a
            header):
            [
                [row1_colum1, row1_colum2, ...],
                ...
            ]
        csv_name: Name of the resulting CSV
        course_id: ID of the course
        parent_dor: Name of the directory where the CSV file will be stored

    Returns:
        report_name: string - Name of the generated report
    """
    report_store = ReportStore.from_config(config_name)
    report_name = "{course_prefix}_{csv_name}_{timestamp_str}.csv".format(
        course_prefix=course_filename_prefix_generator(course_id),
        csv_name=csv_name,
        timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M"))

    report_store.store_rows(course_id, report_name, rows, parent_dir)
    tracker_emit(csv_name)
    return report_name
예제 #2
0
    def test_custom_separator(self, course_key):
        """
        Test filename prefix is generated with a custom separator.

        The filename should be build up from the course locator separated by a custom separator.
        """
        assert course_filename_prefix_generator(course_key,
                                                separator='-') == 'foo-bar-baz'
예제 #3
0
    def test_locators(self, course_key):
        """
        Test filename prefix genaration from multiple course key formats.

        Test that the filename prefix is generated from a CCX course locator or a course key. If the
        filename is generated for a CCX course but the related 'ENABLE_COURSE_FILENAME_CCX_SUFFIX'
        feature is not turned on, the generated filename shouldn't contain the CCX course ID.
        """
        assert course_filename_prefix_generator(course_key) == 'foo_bar_baz'
예제 #4
0
    def test_custom_separator_including_ccx_id(self, course_key,
                                               expected_filename):
        """
        Test filename prefix is generated with a custom separator.

        The filename should be build up from the course locator separated by a custom separator
        including the CCX ID if the related 'ENABLE_COURSE_FILENAME_CCX_SUFFIX' is turned on.
        """
        assert course_filename_prefix_generator(
            course_key, separator='-') == expected_filename
예제 #5
0
def upload_zip_to_report_store(file, zip_name, course_id, timestamp, config_name='GRADES_DOWNLOAD'):
    """
    Upload given file buffer as a zip file using ReportStore.
    """
    report_store = ReportStore.from_config(config_name)

    report_name = "{course_prefix}_{zip_name}_{timestamp_str}.zip".format(
        course_prefix=course_filename_prefix_generator(course_id),
        zip_name=zip_name,
        timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M")
    )

    report_store.store(course_id, report_name, file)
    tracker_emit(zip_name)
    return report_name
예제 #6
0
def generate(_xmodule_instance_args, _entry_id, course_id, task_input, action_name):
    """
    For a given `course_id`, generate a CSV file containing
    all student answers to a given problem, and store using a `ReportStore`.
    """
    start_time = time()
    start_date = datetime.now(UTC)
    num_reports = 1
    task_progress = TaskProgress(action_name, num_reports, start_time)
    current_step = {'step': 'XblockCompletion - Calculating students answers to problem'}
    task_progress.update_task_state(extra_meta=current_step)
    
    data = task_input.get('data')
    filter_types = ['problem']
    students = XblockCompletionView().get_all_enrolled_users(data['course'])
    course_structure = get_data_course(data['course'])

    report_store = ReportStore.from_config('GRADES_DOWNLOAD')
    csv_name = 'Reporte_de_Preguntas'
    if data['format']:
        csv_name = 'Reporte_de_Preguntas_Resumen'

    report_name = u"{course_prefix}_{csv_name}_{timestamp_str}.csv".format(
        course_prefix=course_filename_prefix_generator(course_id),
        csv_name=csv_name,
        timestamp_str=start_date.strftime("%Y-%m-%d-%H%M")
    )
    output_buffer = ContentFile('')
    if six.PY2:
        output_buffer.write(codecs.BOM_UTF8)
    csvwriter = csv.writer(output_buffer)

    student_states = XblockCompletionView().get_all_states(data['course'], filter_types)
    csvwriter = XblockCompletionView()._build_student_data(data, students, course_structure, student_states, filter_types, csvwriter)

    current_step = {'step': 'XblockCompletion - Uploading CSV'}
    task_progress.update_task_state(extra_meta=current_step)

    output_buffer.seek(0)
    report_store.store(course_id, report_name, output_buffer)
    current_step = {
        'step': 'XblockCompletion - CSV uploaded',
        'report_name': report_name,
    }

    return task_progress.update_task_state(extra_meta=current_step)
예제 #7
0
 def test_custom_separator(self, course_key):
     self.assertEqual(course_filename_prefix_generator(course_key, separator='-'), u'foo-bar-baz')
예제 #8
0
 def test_locators(self, course_key):
     self.assertEqual(course_filename_prefix_generator(course_key), u'foo_bar_baz')
예제 #9
0
 def test_custom_separator(self, course_key):
     assert course_filename_prefix_generator(course_key,
                                             separator='-') == 'foo-bar-baz'
예제 #10
0
 def test_locators(self, course_key):
     assert course_filename_prefix_generator(course_key) == 'foo_bar_baz'
예제 #11
0
    def generate_report_instructor_tab_temporary(self, report_grade,
                                                 course_key, is_resumen,
                                                 assig_type, headers):
        """
            Generate Excel File with assignament grade in observations column
        """
        report_store = ReportStore.from_config('GRADES_DOWNLOAD')
        output = BytesIO()
        xlsx_name = 'notas_estudiantes'
        workbook = xlsxwriter.Workbook(output)

        worksheet = workbook.add_worksheet()
        # Add a bold format to use to highlight cells.
        bold = workbook.add_format({'bold': True})
        # Write some data headers.
        worksheet.write('A1', 'RUT', bold)
        worksheet.write('B1', 'Observaciones', bold)
        worksheet.write(0, 0, 'RUT', bold)
        worksheet.write(0, 1, 'Username', bold)
        worksheet.write(0, 2, 'Observaciones', bold)
        worksheet.write(0, 3, 'Nota', bold)
        worksheet.set_column('A:A', 11)  # Column A width set to 11.
        worksheet.set_column('B:B', 15)  # Column B width set to 15.
        worksheet.set_column('C:C', 27)  # Column C width set to 27.
        cell_format = workbook.add_format()
        cell_format.set_text_wrap()
        if report_grade is None:
            xlsx_name = 'Error_notas_estudiantes'
        else:
            percents = self._get_assignment_types(course_key)
            row = 1
            for data in report_grade:
                worksheet.write(row, 0, data[0])
                worksheet.write(row, 1, data[1])
                obs = data[2]
                if obs != '':
                    obs = obs + '\n'
                height = 15
                j = 1
                for h in headers:
                    if h != 'Prom':
                        obs += 'P{} {}% {}: {}%\n'.format(
                            j, percents[h]['weight'] * 100, h, data[3][h])
                        height += 15
                    j += 1
                worksheet.write(row, 2, obs, cell_format)
                worksheet.write(row, 3, data[3]['Prom'])
                worksheet.set_row(row, height)
                row += 1

        workbook.close()
        start_date = datetime.now(UTC)
        report_name = u"{course_prefix}_{xlsx_name}_{timestamp_str}.xlsx".format(
            course_prefix=course_filename_prefix_generator(course_key),
            xlsx_name=xlsx_name,
            timestamp_str=start_date.strftime("%Y-%m-%d-%H%M%S"))
        # Get the output bytes for creating a django file
        output = output.getvalue()
        # Generate the data file
        data_file = ContentFile(output)
        report_store.store(course_key, report_name, data_file)
예제 #12
0
    def generate_report_instructor_tab(self, report_grade, course_key,
                                       is_resumen, assig_type, headers):
        """
            Generate Excel File
        """
        report_store = ReportStore.from_config('GRADES_DOWNLOAD')
        output = BytesIO()
        xlsx_name = 'notas_estudiantes'
        workbook = xlsxwriter.Workbook(output)

        worksheet = workbook.add_worksheet()
        # Add a bold format to use to highlight cells.
        bold = workbook.add_format({'bold': True})
        # Write some data headers.
        worksheet.write('A1', 'RUT', bold)
        worksheet.write('B1', 'Observaciones', bold)
        worksheet.write(0, 0, 'RUT', bold)
        worksheet.write(0, 1, 'Username', bold)
        worksheet.write(0, 2, 'Observaciones', bold)
        if report_grade is None:
            xlsx_name = 'Error_notas_estudiantes'
        else:
            if is_resumen:
                i = 3
                if assig_type == 'gradeucursos_total':
                    percents = self._get_assignment_types(course_key)
                    for h in headers:
                        if h == 'Prom':
                            worksheet.write(0, i, '{}'.format(h), bold)
                        else:
                            worksheet.write(
                                0, i, 'P{} {}% {}'.format(
                                    i - 2, percents[h]['weight'] * 100, h),
                                bold)
                        i += 1
                else:
                    for h in headers:
                        if h == 'Prom':
                            worksheet.write(0, i, '{}'.format(h), bold)
                        else:
                            worksheet.write(0, i, 'P{} {}'.format(i - 2, h),
                                            bold)
                        i += 1
            else:
                worksheet.write(0, 3, 'Nota', bold)
            worksheet.set_column('A:A', 11)  # Column A width set to 11.
            worksheet.set_column('B:B', 15)  # Column B width set to 15.
            worksheet.set_column('C:C', 27)  # Column C width set to 27.
            row = 1
            for data in report_grade:
                worksheet.write(row, 0, data[0])
                worksheet.write(row, 1, data[1])
                worksheet.write(row, 2, data[2])
                i = 3
                for grade in headers:
                    worksheet.write(row, i, data[3][grade])
                    i += 1
                row += 1

        workbook.close()
        start_date = datetime.now(UTC)
        report_name = u"{course_prefix}_{xlsx_name}_{timestamp_str}.xlsx".format(
            course_prefix=course_filename_prefix_generator(course_key),
            xlsx_name=xlsx_name,
            timestamp_str=start_date.strftime("%Y-%m-%d-%H%M%S"))
        # Get the output bytes for creating a django file
        output = output.getvalue()
        # Generate the data file
        data_file = ContentFile(output)
        report_store.store(course_key, report_name, data_file)