Beispiel #1
0
def generate_grade_report(homework,
                          grader,
                          report_dir,
                          overwrite=False,
                          logging_level=log.LOGLEVEL_ERROR):
    report_filename = report_dir + 'GR{}_hw-username.md'.format(
        str(homework.number))
    if sysio.exist_file(report_filename):
        if not overwrite:
            log.log_error('Report {} already exists'.format(report_filename),
                          logging_level)
            return
        else:
            log.log_warning(
                'Overwriting existing report {}'.format(report_filename),
                logging_level)

    report_file = open(report_filename, mode='w')
    title = '## HW {num:02d} Test Case Grade Report'.format(
        num=homework.number)
    md.write_header(report_file, title, GRHLEVEL_TITLE)
    homework.write_score_breakdown(report_file)
    grader_text = 'HW Graded by: {}'.format(grader.get_grader_info())
    md.write_header(report_file, grader_text, GRHLEVEL_OTHER)
    md.write_paragraph(report_file, GRFOOTER)
    report_file.close()
Beispiel #2
0
    def write_score_breakdown(self, report_file):
        report_stream = io.StringIO()
        for problem in self.problems:
            problem.write_score_breakdown(report_stream)
            points = problem.get_test_points()
            self.total_points += points
            self.total_max += problem.test_max
            self.problem_subtotal.append(str(round(points, 2)))

        md.write_header(report_stream, 'Other Deductions & Penalties:',
                        GRHLEVEL_PROBLEM)
        for deduct in self.other_deductions:
            self.total_other += deduct[0]
            self.total_points -= deduct[0]
            deduction_text = '(-{pt} points) {comment}'.format(
                pt=round(deduct[0], 2), comment=deduct[1])
            md.write_list(report_stream, deduction_text)
        if self.other_deductions:
            md.end_list(report_stream)

        self.total_points = max(self.total_points, 0)
        self._write_score_calculation(report_stream)

        summary_text = 'I have completely finished grading your'
        summary_text += ' HW {num:02d} test cases and you received'.format(
            num=self.number)
        summary_text += ' **{total}/{max} points**.'.format(
            total=round(self.total_points, 2), max=round(self.total_max, 2))
        breakdown_text = 'This is the score breakdown:'
        md.write_paragraph(report_file, summary_text)
        md.write_paragraph(report_file, breakdown_text)
        md.write_paragraph(report_file, report_stream.getvalue().strip())
        report_stream.close()
Beispiel #3
0
 def _write_score_calculation(self, report_file):
     md.write_header(report_file, 'Total Score:', GRHLEVEL_PROBLEM)
     calc = '({test}) - ({other}) = **{total:}/{max} points**'.format(
         test=' + '.join(self.problem_subtotal),
         other=self.total_other,
         total=round(self.total_points, 2),
         max=round(self.total_max, 2))
     md.write_list(report_file, calc)
     md.end_list(report_file)
Beispiel #4
0
    def write_score_breakdown(self, ostream):
        self.test_points = self.get_test_points()
        problem_title = 'Problem {num} ({name}) ({pt}/{total}):'.format(
            num=self.number,
            name=self.name,
            pt=round(self.test_points, 2),
            total=round(self.test_max, 2))
        md.write_header(ostream, problem_title, GRHLEVEL_PROBLEM)

        for deduct in self.test_deductions:
            deduction_text = '(-{pt} points) {comment}'.format(
                pt=round(deduct[0], 2), comment=deduct[1])
            md.write_list(ostream, deduction_text)
        if self.test_deductions:
            md.end_list(ostream)