Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -575,12 +575,12 @@ def extract_graph_answers_from_as(text: str):
|
|
| 575 |
|
| 576 |
def extract_marks_from_grading(grading_text):
|
| 577 |
"""
|
| 578 |
-
Parse the grading markdown and extract marks per question
|
| 579 |
"""
|
| 580 |
print("🔎 Extracting awarded marks from grading output...")
|
| 581 |
grading_json = {"grading": []}
|
| 582 |
|
| 583 |
-
question_blocks = re.split(r"##\s*Question\s+", grading_text)
|
| 584 |
for block in question_blocks[1:]:
|
| 585 |
first_line = block.strip().splitlines()[0].strip() if block.strip().splitlines() else ""
|
| 586 |
q_id_match = re.match(r"([0-9]+(?:[a-zA-Z]|\([^)]+\)|(?:\.[a-zA-Z0-9]+))*)", first_line)
|
|
@@ -588,7 +588,20 @@ def extract_marks_from_grading(grading_text):
|
|
| 588 |
q_id = first_line.split()[0] if first_line else ""
|
| 589 |
else:
|
| 590 |
q_id = q_id_match.group(1).strip()
|
| 591 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
grading_json["grading"].append({
|
| 593 |
"question": q_id,
|
| 594 |
"marks_awarded": awarded
|
|
|
|
| 575 |
|
| 576 |
def extract_marks_from_grading(grading_text):
|
| 577 |
"""
|
| 578 |
+
Parse the grading markdown and extract marks per question from the Awarded column only.
|
| 579 |
"""
|
| 580 |
print("🔎 Extracting awarded marks from grading output...")
|
| 581 |
grading_json = {"grading": []}
|
| 582 |
|
| 583 |
+
question_blocks = re.split(r"###\s*Question\s+", grading_text)
|
| 584 |
for block in question_blocks[1:]:
|
| 585 |
first_line = block.strip().splitlines()[0].strip() if block.strip().splitlines() else ""
|
| 586 |
q_id_match = re.match(r"([0-9]+(?:[a-zA-Z]|\([^)]+\)|(?:\.[a-zA-Z0-9]+))*)", first_line)
|
|
|
|
| 588 |
q_id = first_line.split()[0] if first_line else ""
|
| 589 |
else:
|
| 590 |
q_id = q_id_match.group(1).strip()
|
| 591 |
+
|
| 592 |
+
# Extract marks only from the "Awarded" column (4th column in the table)
|
| 593 |
+
awarded = []
|
| 594 |
+
lines = block.split('\n')
|
| 595 |
+
for line in lines:
|
| 596 |
+
if '|' in line:
|
| 597 |
+
parts = [p.strip() for p in line.split('|')]
|
| 598 |
+
# Check if this is a data row (not header or separator) and has at least 5 columns
|
| 599 |
+
if len(parts) >= 5 and not parts[1].startswith('-'):
|
| 600 |
+
awarded_col = parts[4] # 4th column (index 4 because of leading empty from split)
|
| 601 |
+
# Extract mark codes from the awarded column
|
| 602 |
+
marks = re.findall(r"\b([MABCR]\d+|[MABCR]0)\b", awarded_col)
|
| 603 |
+
awarded.extend(marks)
|
| 604 |
+
|
| 605 |
grading_json["grading"].append({
|
| 606 |
"question": q_id,
|
| 607 |
"marks_awarded": awarded
|