-
Notifications
You must be signed in to change notification settings - Fork 0
/
abilities.py
191 lines (149 loc) · 7.89 KB
/
abilities.py
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
"""
This script defines the Ability classes for the admin and student users in a student project.
The script includes the following classes:
1. Abilitiy: The base class that contains common abilities for both admin and student users.
- select_course(student_id): Allows a user to select a course and add the grade to the STCOT table.
- remove_course(student_id): Allows a user to remove a course from the STCOT table.
- student_average(student_id): Calculates and displays the average grade for a specific student.
2. AdminAbility(Abilitiy): Inherits from the Ability class and includes additional abilities specific to the admin user.
- remove_default_course(): Allows the admin to remove a default course from the COT table.
- add_course(): Allows the admin to add a new course to the COT table.
- add_student(): Allows the admin to add a new student to the STT table.
- add_professor(): Placeholder method for adding a new professor (implementation is missing).
- total_average(): Calculates and displays the average grade for all students.
3. StudentAbility(Abilitiy): Inherits from the Ability class and includes additional abilities specific to the student user.
The script also imports the following helper functions and classes:
- department_id(): Prompts the user to select a department and returns the corresponding department ID.
- lesson_type(): Prompts the user to select a lesson type and returns the corresponding type.
- student_level(): Prompts the user to select a student level and returns the corresponding level.
- Connection: A class for handling database connections (implementation is missing).
These classes and methods provide the functionality and abilities for the admin and student users in the student project.
Note: The script does not provide a complete implementation of the project's logic. It only includes the ability classes and some placeholder methods.
"""
from helper_script import department_id, lesson_type, student_level
from connections import Connection
class Abilitiy:
def select_course(self, student_id): #only admin can add the grade
database_connection = Connection()
try:
lesson_id = int(input("enter lesson ID: "))
term = int(input("term : "))
year = input(" year : ")
grade = input (" grade: ")
query = "INSERT INTO STCOT (STID, COID, TR, YRYR, Grade) VALUES (?,?,?,?,?)"
values = (student_id,lesson_id, term, year, grade)
cursor, connection = database_connection._open()
database_connection._execute(cursor, connection, query, values)
database_connection._close(cursor,connection)
print("\nselect the course successfully!")
except Exception as e:
print("An error occurred while adding the course:")
print(e)
# in the available courses
# user can select the course and submit it in stcot table
def remove_course(self, student_id):
database_connection = Connection()
try:
lesson_id = int(input("enter lesson ID: "))
query = "DELETE from STCOT where STCOT.STID = ? AND STCOT.COID = ?"
values = (student_id,lesson_id)
cursor, connection = database_connection._open()
database_connection._execute(cursor, connection, query, values)
database_connection._close(cursor,connection)
print("\nremove the course successfully!!")
except Exception as e:
print("An error occurred while adding the course:")
print(e)
# user can delete the course that select ---> delete from STCOT
def student_average(self, student_id):
database_connection = Connection()
try:
query = f""" select STT.STNAME,STT.STID,
sum(STCOT.Grade*COT.CREDIT)/sum(COT.CREDIT) as AVE from
STT,COT,STCOT
where STT.STID = STCOT.STID and COT.COID = STCOT.COID and STT.STID = {student_id}
group by STT.STNAME,STT.STID """
cursor, connection = database_connection._open()
database_connection._execute(cursor, connection, query, "")
database_connection._fetch(cursor)
database_connection._close(cursor,connection)
except Exception as e:
print("An error occurred while calculating the student average!")
print(e)
class AdminAbility(Abilitiy):
def remove_default_course(self):
database_connection = Connection()
# hint : helper function
try:
lesson_id = int(input("\nenter lesson ID : "))
delete_query = "DELETE FROM COT WHERE COID = ?"
values = (lesson_id)
cursor, connection = database_connection._open()
database_connection._execute(cursor, connection, delete_query, values)
database_connection._close(cursor,connection)
# can drop the row with first fetching and after delete that row
print("\n remove the default course by admin successfully!")
except Exception as e:
print("An error occurred while adding the course:")
print(e)
def add_course(self):
database_connection = Connection()
try:
type = lesson_type()
de_id = department_id()
title = input("title : ")
credit = input ("credit: ")
query = "INSERT INTO COT (CODEID, CoTitle, Credit, COtype) VALUES (?,?,?,?)"
values = (de_id, title, credit, type)
cursor, connection = database_connection._open()
database_connection._execute(cursor, connection, query, values)
database_connection._close(cursor,connection)
print("\nCourse added successfully!")
except Exception as e:
print("An error occurred while adding the course!")
print(e)
def add_student(self):
database_connection = Connection()
try:
name = input("name : ")
major = input("major: ")
level = student_level() # hint : helper function
de_id = department_id()
query = "INSERT INTO STT (STName, STMJR, STLev, STDEID) VALUES (?,?,?,?)"
values = (name, major, level, de_id)
cursor, connection = database_connection._open()
database_connection._execute(cursor, connection, query, values)
database_connection._close(cursor,connection)
print("\nStudent added successfully!")
except Exception as e:
print("An error occurred while adding the student!")
print(e)
def add_professor(self):
pass
# like add student we
# pass the elemnts and execute the query
def total_average(self):
database_connection = Connection()
try:
query = f""" select STT.STNAME,STT.STID,
sum(STCOT.Grade*COT.CREDIT)/sum(COT.CREDIT) as AVE from
STT,COT,STCOT
where STT.STID = STCOT.STID and COT.COID = STCOT.COID
group by STT.STNAME,STT.STID """
cursor, connection = database_connection._open()
database_connection._execute(cursor, connection, query, "")
database_connection._fetch(cursor)
database_connection._close(cursor,connection)
except Exception as e:
print("An error occurred while calculating the average.")
print(e)
def remove_student(self, student_id):
database_connection = Connection()
# hint : helper function
delete_query = "DELETE FROM STT WHERE STT.STID = ?"
values = (student_id)
cursor, connection = database_connection._open()
database_connection._execute(cursor, connection, delete_query, values)
database_connection._close(cursor,connection)
class StudentAbility(Abilitiy):
pass