This repository was archived by the owner on Jan 3, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathRequirementModel.py
More file actions
686 lines (662 loc) · 23.5 KB
/
Copy pathRequirementModel.py
File metadata and controls
686 lines (662 loc) · 23.5 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
"""
RequirementModel.py will act as an ORM for the requirements table in the sqlite database
to the objects that we will use within this application. This will attempt
to make querying the table much simpler.
Authors:
(RegTools)
Joseph Goh
Mason Sayyadi
Owen McEvoy
Ryan Gurnick
Samuel Lundquist
Priority credit to:
Ryan Gurnick - 03/05/20 Creation
"""
import json
import sqlite3
from datetime import date, datetime
import Datastore
class RequirementModel:
def __init__(self, db_file):
"""
Initializer for the requirement model. This will want to know which file to look at for the db.
Then it will provide a connection to that database and allow for some ORM operations, such
as insert and select.
db_file :str
Example Usage:
rm = RequirementModel.RequirementModel('testing.db')
"""
# init db connection using the datastore
self.conn = Datastore.DB(db_file).ret().conn
def _insert(self, term, major, type, data):
"""
Insert method for the requirement model that allows the caller to provide the specified
information and create a record within the database, this will return the id of
the row created.
:param term:
:param major:
:param type:
:param data:
:return:
"""
sql = '''INSERT INTO "main"."requirements"("term","major","type","data","created_at","updated_at") VALUES (?,?,?,?,?,?);'''
cur = self.conn.cursor()
try:
cur.execute(sql, (term, major, type, data, date.today(), date.today()))
self.conn.commit()
cur.close()
return cur.lastrowid
except sqlite3.IntegrityError:
return None
def setupTable(self):
"""
This method will seed the database and ensure that the required rows exist for
requirements. This data is manually generated and then added here to ensure
that its in the initial seed and the empty database if needed.
:return:
"""
# CIS BS
BS = 'BS'
# year 1 fall
self._insert(0, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 122 Introduction to Programming and Problem Solving",
"milestones": "",
"course": "CIS 122"
},
{
"description": "MATH 112 Elementary Functions",
"milestones": "",
"course": "MATH 112"
},
{
"description": "General-education course in arts and letters",
"milestones": "",
"course": ">1"
},
{
"description": "General-education course in social science",
"milestones": "",
"course": ">2"
}
]))
# year 1 winter
self._insert(1, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 210 Computer Science I",
"milestones": "Need grade of B- or better for majors",
"course": "CIS 210"
},
{
"description": "MATH 231 Elements of Discrete Mathematics I",
"milestones": "Need grade of B- or better for majors",
"course": "MATH 231"
},
{
"description": "WR 121 College Composition I",
"milestones": "",
"course": "WR 121"
},
{
"description": "General-education course in arts and letters",
"milestones": "",
"course": ">1"
}
]))
# year 1 spring
self._insert(2, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 211 Computer Science II",
"milestones": "Need grade of B- or better for majors",
"course": "CIS 211"
},
{
"description": "MATH 232 Elements of Discrete Mathematics II",
"milestones": "Need grade of B- or better for majors",
"course": "MATH 232"
},
{
"description": "WR 122 College Composition II/WR 123 College Composition III",
"milestones": "",
"course": "WR 122/123"
},
{
"description": "General-education course in social science",
"milestones": "",
"course": ">2"
},
]))
# year 1 summer (no classes)
self._insert(3, "Computer & Information Science", BS, json.dumps([]))
# year 2 fall
self._insert(4, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 212 Computer Science III",
"milestones": "Need grade of B- or better for majors",
"course": "CIS 212"
},
{
"description": "MATH 251 Calculus I/MATH 246 Calculus for the Biological Sciences I/MATH 261 Calculus "
"with Theory I",
"milestones": "",
"course": "MATH 251/246/261"
},
{
"description": "General-education course in arts and letters",
"milestones": "",
"course": ">1"
},
{
"description": "General-education course in social science",
"milestones": "",
"course": ">2"
},
]))
# year 2 winter
self._insert(5, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 313 Intermediate Data Structures",
"milestones": "",
"course": "CIS 313"
},
{
"description": "CIS 314 Computer Organization",
"milestones": "",
"course": "CIS 314"
},
{
"description": "MATH 252 Calculus II/MATH 246 Calculus for the Biological Sciences II/MATH 261 "
"Calculus with Theory II",
"milestones": "",
"course": "MATH 252/246/262"
},
{
"description": "General-education course in arts and letters that also satisfies multicultural "
"requirement",
"milestones": "",
"course": ">1 AC IP IC"
},
]))
# year 2 spring
self._insert(6, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 315 Intermediate Algorithms",
"milestones": "",
"course": "CIS 315"
},
{
"description": "CIS 330 C/C++ and Unix",
"milestones": "",
"course": "CIS 330"
},
{
"description": "MATH 253 Calculus III/MATH 283 Calculus with Theory III/MATH 341 Elementary Linear "
"Algebra/MATH 343 Statistical Models and Methods/MATH 425 Statistical Methods I",
"milestones": "",
"course": "MATH 253/283/341"
},
{
"description": "General-education course in social science that also satisfies a multicultural "
"requirement",
"milestones": "",
"course": ">2 AC IP IC"
},
]))
# year 2 summer
self._insert(7, "Computer & Information Science", BS, json.dumps([]))
# year 3 fall
self._insert(8, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 415 Operating Systems",
"milestones": "",
"course": "CIS 415"
},
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "Maximum of 8 upper-division elective credits in courses with numbers less than 410",
"course": ""
},
{
"description": "First course of additional science sequence",
"milestones": "",
"course": ""
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
},
]))
# year 3 winter
self._insert(9, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 422 Software Methodology I",
"milestones": "",
"course": "CIS 422"
},
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "",
"course": ""
},
{
"description": "Second course of additional science sequence",
"milestones": "",
"course": ""
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
},
]))
# year 3 spring
self._insert(10, "Computer & Information Science", BS, json.dumps([
{
"description": "CIS 425 Principles of Programming Languages",
"milestones": "",
"course": "CIS 425"
},
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "",
"course": ""
},
{
"description": "Third course of additional science sequence",
"milestones": "",
"course": ""
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
},
]))
# year 3 summer
self._insert(11, "Computer & Information Science", BS, json.dumps([]))
# year 4 fall
self._insert(12, "Computer & Information Science", BS, json.dumps([
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "",
"course": ""
},
{
"description": "Upper-division mathematics elective",
"milestones": "",
"course": ""
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
},
]))
# year 4 winter
self._insert(13, "Computer & Information Science", BS, json.dumps([
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "",
"course": ""
},
{
"description": "Upper-division mathematics elective",
"milestones": "",
"course": ""
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
},
]))
# year 4 spring
self._insert(14, "Computer & Information Science", BS, json.dumps([
{
"description": "WR 320/321",
"milestones": "",
"course": "WR 320/321"
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
},
{
"description": "Elective course 2",
"milestones": "",
"course": ""
},
]))
# year 4 summer
self._insert(15, "Computer & Information Science", BS, json.dumps([]))
# CIS BA
BA = 'BA'
# year 1 fall
self._insert(0, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 122 Introduction to Programming and Problem Solving",
"milestones": "",
"course": "CIS 122"
},
{
"description": "MATH 112 Elementary Functions",
"milestones": "",
"course": "CIS 112"
},
{
"description": "First term of second-language sequence",
"milestones": "",
"course": ""
},
{
"description": "General-education course in social science",
"milestones": "",
"course": ">2"
}
]))
# year 1 winter
self._insert(1, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 210 Computer Science I",
"milestones": "Need grade of B- or better for majors",
"course": "CIS 210"
},
{
"description": "MATH 231 Elements of Discrete Mathematics I",
"milestones": "Need grade of B- or better for majors",
"course": "MATH 231"
},
{
"description": "WR 121 College Composition I",
"milestones": "",
"course": "WR 121"
},
{
"description": "Second term of second-language sequence",
"milestones": "",
"course": ""
}
]))
# year 1 spring
self._insert(2, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 211 Computer Science II",
"milestones": "Need grade of B- or better for majors",
"course": "CIS 211"
},
{
"description": "MATH 232 Elements of Discrete Mathematics II",
"milestones": "Need grade of B- or better for majors",
"course": "MATH 232"
},
{
"description": "WR 122/WR 123",
"milestones": "",
"course": "WR 122/123"
},
{
"description": "Third term of second-language sequence",
"milestones": "",
"course": ""
}
]))
# year 1 summer
self._insert(3, "Computer & Information Science", BA, json.dumps([]))
# year 2 fall
self._insert(4, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 212 Computer Science III",
"milestones": "Need grade of B- or better for majors",
"course": "CIS 212"
},
{
"description": "Math 251/Math 246/Math 261",
"milestones": "",
"course": "MATH 251/246/261"
},
{
"description": "General-education course in arts and letters",
"milestones": "",
"course": ">1"
},
{
"description": "General-education course in social science",
"milestones": "",
"course": ">2"
}
]))
# year 2 winter
self._insert(5, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 313 Intermediate Data Structures",
"milestones": "",
"course": "CIS 313"
},
{
"description": "CIS 314 Computer Organization",
"milestones": "",
"course": "CIS 314"
},
{
"description": "MATH 252/MATH 247/MATH 262",
"milestones": "",
"course": "MATH 252/247/262"
},
{
"description": "General-education course in arts and letters that also satisfies multicultural requirement",
"milestones": "",
"course": ">1 AC IP IC"
}
]))
# year 2 spring
self._insert(6, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 315 Intermediate Algorithms",
"milestones": "",
"course": "CIS 315"
},
{
"description": "CIS 330 C/C++ and Unix",
"milestones": "",
"course": "CIS 330"
},
{
"description": "MATH 253/MATH 263/MATH 341/MATH 343/MATH 425",
"milestones": "",
"course": "MATH 253/263/341/343/425"
},
{
"description": "General-education course in social science that also satisfies a multicultural "
"requirement",
"milestones": "",
"course": ">2 AC IP IC"
}
]))
# year 2 summer
self._insert(7, "Computer & Information Science", BA, json.dumps([]))
# year 3 fall
self._insert(8, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 415 Operating Systems",
"milestones": "",
"course": "CIS 415"
},
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "Maximum of 8 upper-division elective credits in courses with numbers less than 410",
"course": ""
},
{
"description": "First course of additional science sequence",
"milestones": "",
"course": ""
},
{
"description": "General-education course in arts and letters",
"milestones": "",
"course": ">1"
},
]))
# year 3 winter
self._insert(9, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 422 Software Methodology I",
"milestones": "",
"course": "CIS 422"
},
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "",
"course": ""
},
{
"description": "Second course of additional science sequence",
"milestones": "",
"course": ""
},
{
"description": "General-education course in social science that also meets multicultural requirements",
"milestones": "",
"course": ">2"
}
]))
# year 3 spring
self._insert(10, "Computer & Information Science", BA, json.dumps([
{
"description": "CIS 425 Principles of Programming Languages",
"milestones": "",
"course": "CIS 425"
},
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "",
"course": ""
},
{
"description": "Third course of additional science sequence",
"milestones": "",
"course": ""
},
{
"description": "General-education course in arts and letters that also meets multicultural requirements",
"milestones": "",
"course": ">1"
}
]))
# year 3 summer
self._insert(11, "Computer & Information Science", BA, json.dumps([]))
# year 4 fall
self._insert(12, "Computer & Information Science", BA, json.dumps([
{
"description": "MATH 253/263/341/343/425",
"milestones": "",
"course": "MATH 253/263/341/343/425"
},
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "",
"course": ""
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
}
]))
# year 4 winter
self._insert(13, "Computer & Information Science", BA, json.dumps([
{
"description": "Upper-division elective course with CIS subject code",
"milestones": "",
"course": ""
},
{
"description": "Upper-division mathematics elective",
"milestones": "",
"course": ""
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
}
]))
# year 4 spring
self._insert(14, "Computer & Information Science", BA, json.dumps([
{
"description": "WR 320/321",
"milestones": "",
"course": "WR 320/321"
},
{
"description": "Elective course 1",
"milestones": "",
"course": ""
},
{
"description": "Elective course 2",
"milestones": "",
"course": ""
}
]))
# year 4 summer
self._insert(15, "Computer & Information Science", BA, json.dumps([]))
def find_by(self, haystack, needle):
"""
Search for records within the requirements table and return them as lists of lists.
:param
haystack :str
needle :str
return :list
Example Usage:
rm = RequirementModel.RequirementModel('testing.db')
rm.find_by('term', 201901)
rm.find_by('type', 321321)
"""
sql = "SELECT * FROM \"main\".\"requirements\" WHERE \"{}\" = \"{}\"".format(haystack, needle)
cur = self.conn.cursor()
try:
cur.execute(sql)
except ValueError:
return cur.fetchall()
return cur.fetchall()
def find(self, major, type):
"""
Find for records within the requirements table and return them as lists of lists.
:param
major :str
type :str
return :list
Example Usage:
rm = RequirementModel.RequirementModel('testing.db')
rm.find('CIS', "BA")
"""
sql = "SELECT * FROM \"main\".\"requirements\" WHERE \"major\" = \"{}\" AND \"type\" = \"{}\"".format(major,
type)
cur = self.conn.cursor()
try:
cur.execute(sql)
except ValueError:
return cur.fetchall()
return cur.fetchall()
def find_by_term(self, major, type, term):
"""
Find for records within the requirements table and return them as lists of lists.
:param
major :str
type :str
return :list
Example Usage:
rm = RequirementModel.RequirementModel('testing.db')
rm.find('CIS', "BA")
"""
sql = "SELECT * FROM \"main\".\"requirements\" WHERE \"major\" = \"{}\" AND \"type\" = \"{}\" AND \"term\" = \"{}\" ".format(
major, type, term)
cur = self.conn.cursor()
try:
cur.execute(sql)
except ValueError:
return cur.fetchall()
return cur.fetchall()