Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 20 additions & 28 deletions grade_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,22 @@ def generate_summary(model, chapter_title, grades_dict, raise_on_error=False):
}


def format_grade_report(q_idx, q, student_ans, grade, section_title):
report_markdown = f"### Q{q_idx + 1} ({section_title})\n"
report_markdown += f"**Question**: {q['q']}\n\n"
report_markdown += f"**Your Answer**:\n> {student_ans}\n\n"
report_markdown += f"**Model Answer (Rubric)**:\n> {q['modelAnswer']}\n\n"

score_stars = "β˜…" * grade["score"] + "β˜†" * (5 - grade["score"])
report_markdown += f"**Grade**: `{score_stars}` ({grade['score']}/5)\n\n"
report_markdown += f"**Strengths**: {grade['strengths']}\n\n"
report_markdown += f"**Weaknesses**: {grade['weaknesses']}\n\n"
report_markdown += (
f"**Tutor Feedback & Core Concepts**:\n{grade['feedback']}\n\n"
)
report_markdown += "---\n\n"
return report_markdown

def main():
args = parse_args()

Expand Down Expand Up @@ -707,19 +723,8 @@ def main():
total_graded_questions += 1
total_score_sum += grade["score"]

report_markdown += f"### Q{q_idx + 1} ({q.get('section', 'General')})\n"
report_markdown += f"**Question**: {q['q']}\n\n"
report_markdown += f"**Your Answer**:\n> {student_ans}\n\n"
report_markdown += f"**Model Answer (Rubric)**:\n> {q['modelAnswer']}\n\n"

score_stars = "β˜…" * grade["score"] + "β˜†" * (5 - grade["score"])
report_markdown += f"**Grade**: `{score_stars}` ({grade['score']}/5)\n\n"
report_markdown += f"**Strengths**: {grade['strengths']}\n\n"
report_markdown += f"**Weaknesses**: {grade['weaknesses']}\n\n"
report_markdown += (
f"**Tutor Feedback & Core Concepts**:\n{grade['feedback']}\n\n"
)
report_markdown += "---\n\n"
section_title = q.get('section', 'General')
report_markdown += format_grade_report(q_idx, q, student_ans, grade, section_title)

if ch_graded_count > 0:
graded_chapters_count += 1
Expand Down Expand Up @@ -764,21 +769,8 @@ def main():
total_graded_questions += 1
total_score_sum += grade["score"]

report_markdown += (
f"### Q{q_idx + 1} (Ch {q.get('chapterNum')} - {q.get('section')})\n"
)
report_markdown += f"**Question**: {q['q']}\n\n"
report_markdown += f"**Your Answer**:\n> {student_ans}\n\n"
report_markdown += f"**Model Answer (Rubric)**:\n> {q['modelAnswer']}\n\n"

score_stars = "β˜…" * grade["score"] + "β˜†" * (5 - grade["score"])
report_markdown += f"**Grade**: `{score_stars}` ({grade['score']}/5)\n\n"
report_markdown += f"**Strengths**: {grade['strengths']}\n\n"
report_markdown += f"**Weaknesses**: {grade['weaknesses']}\n\n"
report_markdown += (
f"**Tutor Feedback & Core Concepts**:\n{grade['feedback']}\n\n"
)
report_markdown += "---\n\n"
section_title = f"Ch {q.get('chapterNum')} - {q.get('section')}"
report_markdown += format_grade_report(q_idx, q, student_ans, grade, section_title)

# Write Report Summary
summary_markdown = "# DDIA AI Evaluation Summary\n\n"
Expand Down
34 changes: 33 additions & 1 deletion tests/test_grade_responses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
import pytest

from grade_responses import _extract_field
from grade_responses import _extract_field, format_grade_report


def test_format_grade_report():
"""Test that the helper function formats the markdown report correctly."""
q_idx = 0
q = {
"q": "What is the difference between a process and a thread?",
"modelAnswer": "A process is an instance of a program in execution, while a thread is a unit of execution within a process.",
}
student_ans = "Process is program, thread is inside process."
grade = {
"score": 4,
"strengths": "Good understanding of basics.",
"weaknesses": "Could be more detailed.",
"feedback": "Review the concepts of memory sharing.",
}
section_title = "Operating Systems"

expected_output = (
"### Q1 (Operating Systems)\n"
"**Question**: What is the difference between a process and a thread?\n\n"
"**Your Answer**:\n> Process is program, thread is inside process.\n\n"
"**Model Answer (Rubric)**:\n> A process is an instance of a program in execution, while a thread is a unit of execution within a process.\n\n"
"**Grade**: `β˜…β˜…β˜…β˜…β˜†` (4/5)\n\n"
"**Strengths**: Good understanding of basics.\n\n"
"**Weaknesses**: Could be more detailed.\n\n"
"**Tutor Feedback & Core Concepts**:\nReview the concepts of memory sharing.\n\n"
"---\n\n"
)

result = format_grade_report(q_idx, q, student_ans, grade, section_title)
assert result == expected_output


@pytest.mark.parametrize(
Expand Down
Loading