-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_sample_exams.py
More file actions
executable file
·175 lines (150 loc) · 6.42 KB
/
create_sample_exams.py
File metadata and controls
executable file
·175 lines (150 loc) · 6.42 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python3
"""
Create sample exam PDFs for testing Professor Profiler.
This script generates synthetic exam questions in PDF format and places them
in the input/ folder, so you can test the system without needing real exam papers.
"""
try:
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.enums import TA_CENTER
REPORTLAB_AVAILABLE = True
except ImportError:
REPORTLAB_AVAILABLE = False
from pathlib import Path
# Import path utilities
import sys
sys.path.insert(0, str(Path(__file__).parent))
from profiler_agent.paths import get_input_path, ensure_directories
SAMPLE_EXAMS = {
"physics_2024_midterm.pdf": {
"title": "Physics 101 - Midterm Examination 2024",
"questions": [
("1. Define Newton's first law of motion and provide an example.", "Remember"),
("2. A 5kg object accelerates at 2m/s². Calculate the net force acting on it.", "Apply"),
("3. Compare and contrast potential energy and kinetic energy.", "Understand"),
("4. Analyze the motion of a pendulum and explain energy transformations.", "Analyze"),
("5. Design an experiment to measure the acceleration due to gravity.", "Create"),
("6. A car moves at constant velocity. What can you infer about the forces?", "Understand"),
("7. Evaluate the efficiency of different types of engines.", "Evaluate"),
("8. State the formula for gravitational force.", "Remember"),
("9. Apply conservation of momentum to a collision between two objects.", "Apply"),
("10. Explain why astronauts feel weightless in orbit.", "Understand"),
]
},
"physics_2023_final.pdf": {
"title": "Physics 101 - Final Examination 2023",
"questions": [
("1. List the three laws of thermodynamics.", "Remember"),
("2. Calculate the work done by a force of 10N moving an object 5m.", "Apply"),
("3. Explain the relationship between temperature and kinetic energy.", "Understand"),
("4. Analyze heat transfer in a closed system.", "Analyze"),
("5. Evaluate the environmental impact of different energy sources.", "Evaluate"),
("6. Design a solar heating system for a house.", "Create"),
("7. Define entropy in your own words.", "Understand"),
("8. What is the first law of thermodynamics?", "Remember"),
("9. Apply the ideal gas law to calculate pressure at different temperatures.", "Apply"),
("10. Compare conduction, convection, and radiation.", "Understand"),
]
},
"chemistry_2024_q1.pdf": {
"title": "Chemistry 201 - First Quarter Exam 2024",
"questions": [
("1. Write the electron configuration for oxygen.", "Remember"),
("2. Balance this equation: H₂ + O₂ → H₂O", "Apply"),
("3. Explain why noble gases are chemically inert.", "Understand"),
("4. Analyze the bonding in a water molecule.", "Analyze"),
("5. Evaluate the safety of different laboratory procedures.", "Evaluate"),
("6. Design a procedure to synthesize aspirin.", "Create"),
("7. Define electronegativity.", "Remember"),
("8. Calculate the molar mass of glucose (C₆H₁₂O₆).", "Apply"),
("9. Compare ionic and covalent bonding.", "Understand"),
("10. Analyze the pH of different household substances.", "Analyze"),
]
},
}
def create_sample_pdf(filename: str, exam_data: dict):
"""Create a sample exam PDF with the given questions."""
filepath = str(get_input_path(filename)) # Convert Path to string
# Create PDF document
doc = SimpleDocTemplate(
filepath,
pagesize=letter,
rightMargin=72,
leftMargin=72,
topMargin=72,
bottomMargin=18
)
# Container for the 'Flowable' objects
elements = []
# Define styles
styles = getSampleStyleSheet()
title_style = ParagraphStyle(
'CustomTitle',
parent=styles['Heading1'],
fontSize=16,
textColor='navy',
spaceAfter=30,
alignment=TA_CENTER
)
question_style = ParagraphStyle(
'Question',
parent=styles['BodyText'],
fontSize=11,
spaceAfter=12,
leftIndent=20
)
# Add title
title = Paragraph(exam_data["title"], title_style)
elements.append(title)
elements.append(Spacer(1, 0.2*inch))
# Add instructions
instructions = Paragraph(
"<b>Instructions:</b> Answer all questions. Show all work for calculation problems. "
"Total time: 90 minutes. Good luck!",
styles['Normal']
)
elements.append(instructions)
elements.append(Spacer(1, 0.3*inch))
# Add questions
for question_text, bloom_level in exam_data["questions"]:
question = Paragraph(question_text, question_style)
elements.append(question)
elements.append(Spacer(1, 0.15*inch))
# Add footer
elements.append(Spacer(1, 0.5*inch))
footer = Paragraph(
"<i>This is a sample exam generated for testing purposes. "
"Bloom's levels included for demonstration.</i>",
styles['Italic']
)
elements.append(footer)
# Build PDF
doc.build(elements)
print("✓ Created {filename}".format(filename=filename))
def main():
"""Generate all sample exam PDFs."""
print("Generating sample exam PDFs...\n")
# Check if reportlab is available
if not REPORTLAB_AVAILABLE:
print("ERROR: reportlab is required to generate sample PDFs")
print("Install it with: pip install reportlab")
return 1
# Ensure input directory exists
ensure_directories()
# Generate each exam
for filename, exam_data in SAMPLE_EXAMS.items():
try:
create_sample_pdf(filename, exam_data)
except Exception as e:
print("✗ Failed to create {filename}: {error}".format(
filename=filename, error=e))
print("\n✓ Successfully generated {count} sample exam PDFs".format(
count=len(SAMPLE_EXAMS)))
print("✓ Files saved to: {path}".format(path=get_input_path('')))
print("\nYou can now run: python demo.py")
return 0
if __name__ == "__main__":
exit(main())