83 lines
3.1 KiB
Python
83 lines
3.1 KiB
Python
import os
|
|
|
|
with open('backend/seed.py', 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
|
|
new_lines = []
|
|
skip = False
|
|
for i, line in enumerate(lines):
|
|
if 'jee_test_id = UUID' in line:
|
|
skip = True
|
|
new_lines.append(line)
|
|
new_lines.append(lines[i+1]) # neet_test_id
|
|
|
|
replacement = """
|
|
# --- MOCK TESTS from admin_uploads JSON files ---
|
|
print("Seeding Mock tests from admin_uploads...")
|
|
_script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
_docker_path = os.path.join(_script_dir, "admin_uploads")
|
|
_local_path = os.path.join(_script_dir, "..", "admin_uploads")
|
|
mock_json_dir = _docker_path if os.path.isdir(_docker_path) else _local_path
|
|
|
|
mock_json_files = sorted(glob.glob(os.path.join(mock_json_dir, "mock_*.json")))
|
|
|
|
for json_path in mock_json_files:
|
|
with open(json_path, "r", encoding="utf-8") as f:
|
|
raw_questions = json.load(f)
|
|
|
|
is_neet = "neet" in json_path.lower()
|
|
pattern = models.ExamEnum.NEET if is_neet else models.ExamEnum.JEE_MAIN
|
|
title = "NEET UG Full Mock Test (2025)" if is_neet else "JEE Advanced Paper 1 (2025)"
|
|
|
|
sections = {}
|
|
for raw_q in raw_questions:
|
|
subject = raw_q.get("subject", "General")
|
|
if subject not in sections:
|
|
sections[subject] = {"name": subject, "questions": [], "time_limit": 45 if is_neet else 60}
|
|
|
|
q = models.Question(
|
|
id=uuid4(),
|
|
subject=subject,
|
|
topic=raw_q.get("topic", "Mixed"),
|
|
subtopic=raw_q.get("subtopic", "Mixed"),
|
|
difficulty=raw_q.get("difficulty", "Medium"),
|
|
type=models.QuestionTypeEnum(raw_q.get("type", "MCQ_Single")),
|
|
question_text=raw_q.get("question_text", ""),
|
|
options=raw_q.get("options"),
|
|
correct_answer=raw_q.get("correct_answer"),
|
|
solution_text=raw_q.get("solution_text", ""),
|
|
language=models.MediumEnum.ENGLISH,
|
|
exam=pattern,
|
|
created_by=admin_id
|
|
)
|
|
session.add(q)
|
|
sections[subject]["questions"].append(str(q.id))
|
|
|
|
mock_test = models.Test(
|
|
id=neet_test_id if is_neet else jee_test_id,
|
|
title=title,
|
|
type="Mock",
|
|
exam_pattern=pattern,
|
|
sections=sections,
|
|
total_time=180,
|
|
difficulty="Mixed",
|
|
scheduled_date=datetime.utcnow(),
|
|
is_active=True,
|
|
created_by=admin_id
|
|
)
|
|
session.add(mock_test)
|
|
|
|
session.commit()
|
|
|
|
"""
|
|
new_lines.append(replacement)
|
|
|
|
elif '--- DPS (Daily Practice Sheets)' in line:
|
|
skip = False
|
|
|
|
if not skip:
|
|
new_lines.append(line)
|
|
|
|
with open('backend/seed.py', 'w', encoding='utf-8') as f:
|
|
f.writelines(new_lines)
|