File size: 1,709 Bytes
55feae3
0d3fcab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from docx import Document
from docx.shared import Pt
import json


def _add_text(doc, text, bold=False):
    p = doc.add_paragraph()
    run = p.add_run(text)
    run.bold = bold
    run.font.size = Pt(11)


def build_question_paper_docx(path, final_json, generator_raw, subject):
    doc = Document()
    doc.add_heading(f"Question Paper — {subject}", level=1)

    _add_text(doc, "Printable Version:", True)
    _add_text(doc, generator_raw[:8000])

    # Structured table
    questions = final_json.get("final_qp", {}).get("questions", [])
    if questions:
        table = doc.add_table(rows=1, cols=5)
        hdr = table.rows[0].cells
        hdr[0].text = "Q.No"
        hdr[1].text = "SubQ"
        hdr[2].text = "Question"
        hdr[3].text = "CO"
        hdr[4].text = "Bloom/Tags"

        for q in questions:
            row = table.add_row().cells
            row[0].text = str(q.get("question_no", ""))
            row[1].text = str(q.get("sub_no", ""))
            row[2].text = q.get("question_text", "")
            row[3].text = q.get("course_outcome", "")
            row[4].text = q.get("bloom_level", "") + " | " + q.get("tags", "")

    doc.save(path)


def build_answers_docx(path, final_json, subject):
    doc = Document()
    doc.add_heading(f"Answer Key — {subject}", level=1)

    answers = final_json.get("answers", {})
    for k, v in answers.items():
        _add_text(doc, f"{k}:", True)
        _add_text(doc, str(v))

    doc.save(path)


def build_obe_docx(path, final_json, subject):
    doc = Document()
    doc.add_heading(f"OBE Summary — {subject}", level=1)

    obe = final_json.get("obe", {})
    _add_text(doc, json.dumps(obe, indent=2))

    doc.save(path)