1818 },
1919 {
2020 "cell_type" : " code" ,
21- "execution_count" : 1 ,
21+ "execution_count" : null ,
2222 "metadata" : {},
23- "outputs" : [
24- {
25- "name" : " stderr" ,
26- "output_type" : " stream" ,
27- "text" : [
28- " [2024-12-20 11:10:20,120][INFO]: Connecting [email protected] :3306\n " ,
29- " [2024-12-20 11:10:20,259][INFO]: Connected [email protected] :3306\n " 30- ]
31- }
32- ],
33- "source" : [
34- " import datajoint as dj\n " ,
35- " \n " ,
36- " dj.config[\" database.host\" ] = \" 127.0.0.1\"\n " ,
37- " schema = dj.Schema(\" university\" )"
38- ]
23+ "outputs" : [],
24+ "source" : " import datajoint as dj\n\n # Clean up any existing schema from previous runs\n schema = dj.Schema(\" tutorial_university\" , create_tables=False)\n schema.drop()\n\n # Create fresh schema\n schema = dj.Schema(\" tutorial_university\" )"
3925 },
4026 {
4127 "cell_type" : " markdown" ,
236222 },
237223 {
238224 "cell_type" : " code" ,
239- "execution_count" : 8 ,
225+ "execution_count" : null ,
240226 "metadata" : {},
241227 "outputs" : [],
242- "source" : [
243- " Student.insert(dict(k, student_id=i) for i, k in zip(range(100, 300), yield_students()))\n " ,
244- " \n " ,
245- " Department.insert(\n " ,
246- " dict(\n " ,
247- " dept=dept,\n " ,
248- " dept_name=name,\n " ,
249- " dept_address=fake.address(),\n " ,
250- " dept_phone=fake.phone_number()[:20],\n " ,
251- " )\n " ,
252- " for dept, name in [\n " ,
253- " [\" CS\" , \" Computer Science\" ],\n " ,
254- " [\" BIOL\" , \" Life Sciences\" ],\n " ,
255- " [\" PHYS\" , \" Physics\" ],\n " ,
256- " [\" MATH\" , \" Mathematics\" ],\n " ,
257- " ]\n " ,
258- " )\n " ,
259- " \n " ,
260- " StudentMajor.insert(\n " ,
261- " {**s, **d, \" declare_date\" : fake.date_between(start_date=datetime.date(1999, 1, 1))}\n " ,
262- " for s, d in zip(Student.fetch(\" KEY\" ), random.choices(Department.fetch(\" KEY\" ), k=len(Student())))\n " ,
263- " if random.random() < 0.75\n " ,
264- " )\n " ,
265- " \n " ,
266- " # from https://www.utah.edu/\n " ,
267- " Course.insert(\n " ,
268- " [\n " ,
269- " [\" BIOL\" , 1006, \" World of Dinosaurs\" , 3],\n " ,
270- " [\" BIOL\" , 1010, \" Biology in the 21st Century\" , 3],\n " ,
271- " [\" BIOL\" , 1030, \" Human Biology\" , 3],\n " ,
272- " [\" BIOL\" , 1210, \" Principles of Biology\" , 4],\n " ,
273- " [\" BIOL\" , 2010, \" Evolution & Diversity of Life\" , 3],\n " ,
274- " [\" BIOL\" , 2020, \" Principles of Cell Biology\" , 3],\n " ,
275- " [\" BIOL\" , 2021, \" Principles of Cell Science\" , 4],\n " ,
276- " [\" BIOL\" , 2030, \" Principles of Genetics\" , 3],\n " ,
277- " [\" BIOL\" , 2210, \" Human Genetics\" , 3],\n " ,
278- " [\" BIOL\" , 2325, \" Human Anatomy\" , 4],\n " ,
279- " [\" BIOL\" , 2330, \" Plants & Society\" , 3],\n " ,
280- " [\" BIOL\" , 2355, \" Field Botany\" , 2],\n " ,
281- " [\" BIOL\" , 2420, \" Human Physiology\" , 4],\n " ,
282- " [\" PHYS\" , 2040, \" Classcal Theoretical Physics II\" , 4],\n " ,
283- " [\" PHYS\" , 2060, \" Quantum Mechanics\" , 3],\n " ,
284- " [\" PHYS\" , 2100, \" General Relativity and Cosmology\" , 3],\n " ,
285- " [\" PHYS\" , 2140, \" Statistical Mechanics\" , 4],\n " ,
286- " [\" PHYS\" , 2210, \" Physics for Scientists and Engineers I\" , 4],\n " ,
287- " [\" PHYS\" , 2220, \" Physics for Scientists and Engineers II\" , 4],\n " ,
288- " [\" PHYS\" , 3210, \" Physics for Scientists I (Honors)\" , 4],\n " ,
289- " [\" PHYS\" , 3220, \" Physics for Scientists II (Honors)\" , 4],\n " ,
290- " [\" MATH\" , 1250, \" Calculus for AP Students I\" , 4],\n " ,
291- " [\" MATH\" , 1260, \" Calculus for AP Students II\" , 4],\n " ,
292- " [\" MATH\" , 1210, \" Calculus I\" , 4],\n " ,
293- " [\" MATH\" , 1220, \" Calculus II\" , 4],\n " ,
294- " [\" MATH\" , 2210, \" Calculus III\" , 3],\n " ,
295- " [\" MATH\" , 2270, \" Linear Algebra\" , 4],\n " ,
296- " [\" MATH\" , 2280, \" Introduction to Differential Equations\" , 4],\n " ,
297- " [\" MATH\" , 3210, \" Foundations of Analysis I\" , 4],\n " ,
298- " [\" MATH\" , 3220, \" Foundations of Analysis II\" , 4],\n " ,
299- " [\" CS\" , 1030, \" Foundations of Computer Science\" , 3],\n " ,
300- " [\" CS\" , 1410, \" Introduction to Object-Oriented Programming\" , 4],\n " ,
301- " [\" CS\" , 2420, \" Introduction to Algorithms & Data Structures\" , 4],\n " ,
302- " [\" CS\" , 2100, \" Discrete Structures\" , 3],\n " ,
303- " [\" CS\" , 3500, \" Software Practice\" , 4],\n " ,
304- " [\" CS\" , 3505, \" Software Practice II\" , 3],\n " ,
305- " [\" CS\" , 3810, \" Computer Organization\" , 4],\n " ,
306- " [\" CS\" , 4400, \" Computer Systems\" , 4],\n " ,
307- " [\" CS\" , 4150, \" Algorithms\" , 3],\n " ,
308- " [\" CS\" , 3100, \" Models of Computation\" , 3],\n " ,
309- " [\" CS\" , 3200, \" Introduction to Scientific Computing\" , 3],\n " ,
310- " [\" CS\" , 4000, \" Senior Capstone Project - Design Phase\" , 3],\n " ,
311- " [\" CS\" , 4500, \" Senior Capstone Project\" , 3],\n " ,
312- " [\" CS\" , 4940, \" Undergraduate Research\" , 3],\n " ,
313- " [\" CS\" , 4970, \" Computer Science Bachelors Thesis\" , 3],\n " ,
314- " ]\n " ,
315- " )\n " ,
316- " \n " ,
317- " Term.insert(dict(term_year=year, term=term) for year in range(1999, 2019) for term in [\" Spring\" , \" Summer\" , \" Fall\" ])\n " ,
318- " \n " ,
319- " Term().fetch(order_by=(\" term_year DESC\" , \" term DESC\" ), as_dict=True, limit=1)[0]\n " ,
320- " \n " ,
321- " CurrentTerm().insert1({**Term().fetch(order_by=(\" term_year DESC\" , \" term DESC\" ), as_dict=True, limit=1)[0]})\n " ,
322- " \n " ,
323- " \n " ,
324- " def make_section(prob):\n " ,
325- " for c in (Course * Term).proj():\n " ,
326- " for sec in \" abcd\" :\n " ,
327- " if random.random() < prob:\n " ,
328- " break\n " ,
329- " yield {\n " ,
330- " **c,\n " ,
331- " \" section\" : sec,\n " ,
332- " \" auditorium\" : random.choice(\" ABCDEF\" ) + str(random.randint(1, 100)),\n " ,
333- " }\n " ,
334- " \n " ,
335- " \n " ,
336- " Section.insert(make_section(0.5))"
337- ]
228+ "source": "Student.insert(dict(k, student_id=i) for i, k in zip(range(100, 300), yield_students()))\n\nDepartment.insert(\n dict(\n dept=dept,\n dept_name=name,\n dept_address=fake.address(),\n dept_phone=fake.phone_number()[:20],\n )\n for dept, name in [\n [\"CS\", \"Computer Science\"],\n [\"BIOL\", \"Life Sciences\"],\n [\"PHYS\", \"Physics\"],\n [\"MATH\", \"Mathematics\"],\n ]\n)\n\nStudentMajor.insert(\n {**s, **d, \"declare_date\": fake.date_between(start_date=datetime.date(1999, 1, 1))}\n for s, d in zip(Student().keys(), random.choices(Department().keys(), k=len(Student())))\n if random.random() < 0.75\n)\n\n# from https://www.utah.edu/\nCourse.insert(\n [\n [\"BIOL\", 1006, \"World of Dinosaurs\", 3],\n [\"BIOL\", 1010, \"Biology in the 21st Century\", 3],\n [\"BIOL\", 1030, \"Human Biology\", 3],\n [\"BIOL\", 1210, \"Principles of Biology\", 4],\n [\"BIOL\", 2010, \"Evolution & Diversity of Life\", 3],\n [\"BIOL\", 2020, \"Principles of Cell Biology\", 3],\n [\"BIOL\", 2021, \"Principles of Cell Science\", 4],\n [\"BIOL\", 2030, \"Principles of Genetics\", 3],\n [\"BIOL\", 2210, \"Human Genetics\", 3],\n [\"BIOL\", 2325, \"Human Anatomy\", 4],\n [\"BIOL\", 2330, \"Plants & Society\", 3],\n [\"BIOL\", 2355, \"Field Botany\", 2],\n [\"BIOL\", 2420, \"Human Physiology\", 4],\n [\"PHYS\", 2040, \"Classcal Theoretical Physics II\", 4],\n [\"PHYS\", 2060, \"Quantum Mechanics\", 3],\n [\"PHYS\", 2100, \"General Relativity and Cosmology\", 3],\n [\"PHYS\", 2140, \"Statistical Mechanics\", 4],\n [\"PHYS\", 2210, \"Physics for Scientists and Engineers I\", 4],\n [\"PHYS\", 2220, \"Physics for Scientists and Engineers II\", 4],\n [\"PHYS\", 3210, \"Physics for Scientists I (Honors)\", 4],\n [\"PHYS\", 3220, \"Physics for Scientists II (Honors)\", 4],\n [\"MATH\", 1250, \"Calculus for AP Students I\", 4],\n [\"MATH\", 1260, \"Calculus for AP Students II\", 4],\n [\"MATH\", 1210, \"Calculus I\", 4],\n [\"MATH\", 1220, \"Calculus II\", 4],\n [\"MATH\", 2210, \"Calculus III\", 3],\n [\"MATH\", 2270, \"Linear Algebra\", 4],\n [\"MATH\", 2280, \"Introduction to Differential Equations\", 4],\n [\"MATH\", 3210, \"Foundations of Analysis I\", 4],\n [\"MATH\", 3220, \"Foundations of Analysis II\", 4],\n [\"CS\", 1030, \"Foundations of Computer Science\", 3],\n [\"CS\", 1410, \"Introduction to Object-Oriented Programming\", 4],\n [\"CS\", 2420, \"Introduction to Algorithms & Data Structures\", 4],\n [\"CS\", 2100, \"Discrete Structures\", 3],\n [\"CS\", 3500, \"Software Practice\", 4],\n [\"CS\", 3505, \"Software Practice II\", 3],\n [\"CS\", 3810, \"Computer Organization\", 4],\n [\"CS\", 4400, \"Computer Systems\", 4],\n [\"CS\", 4150, \"Algorithms\", 3],\n [\"CS\", 3100, \"Models of Computation\", 3],\n [\"CS\", 3200, \"Introduction to Scientific Computing\", 3],\n [\"CS\", 4000, \"Senior Capstone Project - Design Phase\", 3],\n [\"CS\", 4500, \"Senior Capstone Project\", 3],\n [\"CS\", 4940, \"Undergraduate Research\", 3],\n [\"CS\", 4970, \"Computer Science Bachelors Thesis\", 3],\n ]\n)\n\nTerm.insert(dict(term_year=year, term=term) for year in range(1999, 2019) for term in [\"Spring\", \"Summer\", \"Fall\"])\n\nTerm().to_dicts(order_by=(\"term_year DESC\", \"term DESC\"), limit=1)[0]\n\nCurrentTerm().insert1({**Term().to_dicts(order_by=(\"term_year DESC\", \"term DESC\"), limit=1)[0]})\n\n\ndef make_section(prob):\n for c in (Course * Term).proj():\n for sec in \"abcd\":\n if random.random() < prob:\n break\n yield {\n **c,\n \"section\": sec,\n \"auditorium\": random.choice(\"ABCDEF\") + str(random.randint(1, 100)),\n }\n\n\nSection.insert(make_section(0.5))"
338229 },
339230 {
340231 "cell_type" : " code" ,
341- "execution_count" : 9 ,
232+ "execution_count" : null ,
342233 "metadata" : {},
343- "outputs" : [
344- {
345- "name" : " stderr" ,
346- "output_type" : " stream" ,
347- "text" : [
348- " 100%|██████████| 200/200 [00:27<00:00, 7.17it/s]\n "
349- ]
350- }
351- ],
352- "source" : [
353- " # Enrollment\n " ,
354- " terms = Term().fetch(\" KEY\" )\n " ,
355- " quit_prob = 0.1\n " ,
356- " for student in tqdm(Student.fetch(\" KEY\" )):\n " ,
357- " start_term = random.randrange(len(terms))\n " ,
358- " for term in terms[start_term:]:\n " ,
359- " if random.random() < quit_prob:\n " ,
360- " break\n " ,
361- " else:\n " ,
362- " sections = ((Section & term) - (Course & (Enroll & student))).fetch(\" KEY\" )\n " ,
363- " if sections:\n " ,
364- " Enroll.insert(\n " ,
365- " {**student, **section} for section in random.sample(sections, random.randrange(min(5, len(sections))))\n " ,
366- " )\n " ,
367- " \n " ,
368- " # assign random grades\n " ,
369- " grades = LetterGrade.fetch(\" grade\" )\n " ,
370- " \n " ,
371- " grade_keys = Enroll.fetch(\" KEY\" )\n " ,
372- " random.shuffle(grade_keys)\n " ,
373- " grade_keys = grade_keys[: len(grade_keys) * 9 // 10]\n " ,
374- " \n " ,
375- " Grade.insert({**key, \" grade\" : grade} for key, grade in zip(grade_keys, random.choices(grades, k=len(grade_keys))))"
376- ]
234+ "outputs" : [],
235+ "source" : " # Enrollment\n terms = Term().keys()\n quit_prob = 0.1\n for student in tqdm(Student().keys()):\n start_term = random.randrange(len(terms))\n for term in terms[start_term:]:\n if random.random() < quit_prob:\n break\n else:\n sections = ((Section & term) - (Course & (Enroll & student))).keys()\n if sections:\n Enroll.insert(\n {**student, **section} for section in random.sample(sections, random.randrange(min(5, len(sections))))\n )\n\n # assign random grades\n grades = LetterGrade().to_arrays(\" grade\" )[0]\n\n grade_keys = Enroll().keys()\n random.shuffle(grade_keys)\n grade_keys = grade_keys[: len(grade_keys) * 9 // 10]\n\n Grade.insert({**key, \" grade\" : grade} for key, grade in zip(grade_keys, random.choices(grades, k=len(grade_keys))))"
377236 },
378237 {
379238 "cell_type" : " markdown" ,
988847 "execution_count" : null ,
989848 "metadata" : {},
990849 "outputs" : [],
991- "source" : []
850+ "source" : " # Cleanup \n schema.drop() "
992851 }
993852 ],
994853 "metadata" : {
1012871 },
1013872 "nbformat" : 4 ,
1014873 "nbformat_minor" : 2
1015- }
874+ }
0 commit comments