-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_methods.py
More file actions
145 lines (114 loc) · 4.29 KB
/
main_methods.py
File metadata and controls
145 lines (114 loc) · 4.29 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
from students import Student
from students_linked_list_queue import StudentsLinkedQueue as Sq
from create_db import *
from random import randint as r
from priority_list_students import PriorityList
class EntryException(Exception):
pass
def create_database(database):
create_student_table(database)
create_assignment_table(database)
create_assignment_name_table(database)
def create_new_student(database, first_name, last_name):
"""Create a new student"""
# minimum and maximum of 6-Digit ID
minimum_id = 100000
maximum_id = 999999
# get random 6 digit number as student_id
student_id = r(minimum_id, maximum_id)
# test if student id already exists
test = exists_student(database, student_id)
# until an unused student ID is found, get new id
while test is not None:
student_id = r(minimum_id, maximum_id)
# insert student into database with first_name, last_name, and random student_id
insert_student(database, student_id, first_name, last_name)
def create_new_assignment_name(database, assignment_name):
"""Create a new assignment"""
# minimum and maximum of 6-Digit ID
minimum_id = 100000
maximum_id = 999999
# get random 6 digit number as assignment_id
assignment_id = r(minimum_id, maximum_id)
# test if assignment_id already exists
test = exists_assignment(database, assignment_id)
# until an unused assignment_id is found, get new id
while test is not None:
assignment_id = r(minimum_id, maximum_id)
# insert assignment into database with name and assignment_id
insert_assignment_name(database, assignment_id, assignment_name)
return assignment_id
def test_if_students_exist(database):
"""Test if the student table is empty"""
result = True
if len(select_all_students(database)) == 0:
result = False
return result
def generate_student_linked_list(database):
"""Create linked list queue from SQL table"""
students_list = Sq()
# Get all students
students = select_all_students(database)
# define index variables
id_index, fname_index, lname_index = 0, 1, 2
# iterate through students
for student in students:
# create new student object
new_student = Student(student[id_index], student[fname_index], student[lname_index])
# enqueue the student object
students_list.enqueue(new_student)
# return linked list object
return students_list
def check_entry(entry):
"""Check for valid characters in entry"""
acceptable = set("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'-")
if not (acceptable.issuperset(entry)) or len(entry) == 0:
raise EntryException
def assign_average_grades_from_linked_list(db, queue):
"""Assign average grades for students"""
# get next student
node = queue.get_next_student()
# get the assignments for that student
assignments = select_all_assignments_by_id(db)
grades = []
possible = 0
actual = 1
i = 0
actual_points = 0
attempted_points = 0
# for each assignment, get the grade, and calculate average
while i < len(assignments):
assignment_id = assignments[i][0]
grades.append(select_assignment_by_student(db, assignment_id, node.id)[0])
i += 1
if i == len(assignments):
for grade in grades:
actual_points += grade[actual]
attempted_points += grade[possible]
# assign average as percentage rounded to next whole number
average = round((actual_points/attempted_points) * 100)
node.overall_grade = average
if node.next_student is not None:
node = node.next_student
actual_points = 0
attempted_points = 0
i = 0
def assign_priorities(database, nodes):
p = PriorityList()
HIGH = 3
MEDIUM = 2
LOW = 1
node = nodes.get_next_student()
assign_average_grades_from_linked_list(database, nodes)
not_end = True
while not_end:
if node.overall_grade >= 85:
p.insert(node, LOW)
elif node.overall_grade >= 75:
p.insert(node, MEDIUM)
else:
p.insert(node, HIGH)
node = node.next
if node is None:
not_end = False
return p