import asyncio import os import uuid from sqlmodel import Session, select, delete from datetime import datetime from database import engine, init_db import models import storage from pdf_parser import parse_pdf_to_questions async def seed_pdfs(): admin_id_str = "b0e17378-864d-439e-8806-708dc48a891b" with Session(engine) as session: admin = session.exec(select(models.User).limit(1)).first() admin_id = admin.id if admin else uuid.UUID(admin_id_str) # Delete previously seeded AI DPPs to prevent duplicates statement = select(models.Test).where(models.Test.title.like("AI DPP:%")) old_tests = session.exec(statement).all() for t in old_tests: session.delete(t) session.commit() # Realistic Mock Data mock_data = [ { "topic": "Rotational Dynamics", "subject": "Physics", "difficulty": "Hard", "questions": [ { "question_text": r"A solid sphere of mass $M$ and radius $R$ is rolling without slipping on a horizontal surface. Its center of mass is moving with velocity $v$. What is its total kinetic energy?", "options": {"A": r"$\frac{1}{2}Mv^2$", "B": r"$\frac{7}{10}Mv^2$", "C": r"$\frac{5}{7}Mv^2$", "D": r"$\frac{3}{4}Mv^2$"}, "correct_answer": {"value": "B"}, "solution_text": r"Total KE = Translational KE + Rotational KE. $KE_{tot} = \frac{1}{2}Mv^2 + \frac{1}{2}I\omega^2$. For solid sphere, $I = \frac{2}{5}MR^2$, and since it rolls without slipping, $\omega = v/R$. Thus, $KE_{tot} = \frac{1}{2}Mv^2 + \frac{1}{2}(\frac{2}{5}MR^2)(v/R)^2 = \frac{7}{10}Mv^2$." }, { "question_text": r"A thin uniform rod of length $l$ and mass $m$ is suspended freely from one end. It is pulled aside through an angle $\theta$ and released. What is the angular velocity when it passes through the lowest point?", "options": {"A": r"$\sqrt{\frac{3g}{l}(1-\cos\theta)}$", "B": r"$\sqrt{\frac{g}{l}(1-\cos\theta)}$", "C": r"$\sqrt{\frac{2g}{l}(1-\cos\theta)}$", "D": r"$\sqrt{\frac{6g}{l}(1-\cos\theta)}$"}, "correct_answer": {"value": "A"}, "solution_text": r"By conservation of energy: $mgh_{cm} = \frac{1}{2}I\omega^2$. $h_{cm} = \frac{l}{2}(1-\cos\theta)$. $I = \frac{ml^2}{3}$. Therefore, $mg\frac{l}{2}(1-\cos\theta) = \frac{1}{2}(\frac{ml^2}{3})\omega^2 \implies \omega = \sqrt{\frac{3g}{l}(1-\cos\theta)}$." } ] }, { "topic": "Chemical Kinetics", "subject": "Chemistry", "difficulty": "Medium", "questions": [ { "question_text": r"For a first-order reaction $A \rightarrow P$, the rate constant is $k = 2.303 \times 10^{-3} s^{-1}$. What is the half-life ($t_{1/2}$) of this reaction?", "options": {"A": r"$300 s$", "B": r"$301 s$", "C": r"$69.3 s$", "D": r"$0.693 s$"}, "correct_answer": {"value": "B"}, "solution_text": r"For first-order reaction, $t_{1/2} = \frac{0.693}{k}$. Substituting $k$, $t_{1/2} = \frac{0.693}{2.303 \times 10^{-3}} \approx 301 s$." }, { "question_text": r"If the rate of a reaction increases by a factor of $8$ when the concentration of reactant $X$ is doubled, what is the order of the reaction with respect to $X$?", "options": {"A": "1", "B": "2", "C": "3", "D": "0"}, "correct_answer": {"value": "C"}, "solution_text": r"Rate $R \propto [X]^n$. If $[X]$ is doubled, new rate $R' = 2^n \cdot R$. Given $R' = 8R$, so $2^n = 8 \implies n = 3$." } ] }, { "topic": "Genetics", "subject": "Biology", "difficulty": "Easy", "questions": [ { "question_text": r"In a Mendelian dihybrid cross, what is the phenotypic ratio of the F2 generation?", "options": {"A": "9:3:3:1", "B": "1:2:1", "C": "3:1", "D": "1:1:1:1"}, "correct_answer": {"value": "A"}, "solution_text": r"A standard dihybrid cross between two heterozygotes ($AaBb \times AaBb$) yields offspring with phenotypes in a 9:3:3:1 ratio." }, { "question_text": r"Which of the following describes the condition where both alleles of a gene pair in a heterozygote are fully expressed?", "options": {"A": "Incomplete Dominance", "B": "Codominance", "C": "Pleiotropy", "D": "Epistasis"}, "correct_answer": {"value": "B"}, "solution_text": r"Codominance is the phenomenon where both alleles are simultaneously expressed in the heterozygote, such as in AB blood type." } ] }, { "topic": "Calculus", "subject": "Mathematics", "difficulty": "Hard", "questions": [ { "question_text": r"Evaluate the integral $\int_0^{\pi/2} \frac{\sqrt{\sin x}}{\sqrt{\sin x} + \sqrt{\cos x}} dx$.", "options": {"A": r"$\pi/4$", "B": r"$\pi/2$", "C": r"$\pi$", "D": r"$0$"}, "correct_answer": {"value": "A"}, "solution_text": r"Let $I = \int_0^{\pi/2} \frac{\sqrt{\sin x}}{\sqrt{\sin x} + \sqrt{\cos x}} dx$. Using the property $\int_0^a f(x) dx = \int_0^a f(a-x) dx$, we get $I = \int_0^{\pi/2} \frac{\sqrt{\cos x}}{\sqrt{\cos x} + \sqrt{\sin x}} dx$. Adding both, $2I = \int_0^{\pi/2} 1 dx = \pi/2 \implies I = \pi/4$." }, { "question_text": r"Find the limit $\lim_{x \to 0} \frac{e^x - 1 - x}{x^2}$.", "options": {"A": "1", "B": r"$1/2$", "C": "0", "D": "Does not exist"}, "correct_answer": {"value": "B"}, "solution_text": r"Using L'Hôpital's Rule twice: $\lim_{x \to 0} \frac{e^x - 1}{2x} = \lim_{x \to 0} \frac{e^x}{2} = \frac{1}{2}$." } ] } ] for idx, mock in enumerate(mock_data): question_ids = [] for q_data in mock["questions"]: new_q = models.Question( subject=mock["subject"], topic=mock["topic"], subtopic="General", difficulty=mock["difficulty"], type=models.QuestionTypeEnum.MCQ_SINGLE, question_text=q_data["question_text"], options=q_data["options"], correct_answer=q_data["correct_answer"], solution_text=q_data["solution_text"], language=models.MediumEnum.ENGLISH, exam=models.ExamEnum.JEE_MAIN, created_by=admin_id ) session.add(new_q) session.flush() question_ids.append(str(new_q.id)) test_obj = models.Test( title=f"AI DPP: {mock['topic']}", type="DPS", exam_pattern=models.ExamEnum.JEE_MAIN, sections={ "Section 1": { "questions": question_ids, "time_limit": 60 } }, total_time=60, difficulty=mock["difficulty"], scheduled_date=datetime.utcnow(), is_active=True, created_by=admin_id ) session.add(test_obj) session.commit() print(f"Successfully created DPS Test: {test_obj.title} with {len(question_ids)} questions.") if __name__ == "__main__": asyncio.run(seed_pdfs())