-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_class.py
145 lines (121 loc) · 4.79 KB
/
student_class.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
#REcords for 2021 entrants
from sqlalchemy import create_engine, Column, String, REAL, desc
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from subject_class import *
Base = declarative_base()
class Student(Base):
__tablename__ = "student_records"
regno = Column("regno" , String, primary_key = True, nullable=False, unique=True)
fullname = Column("fullname", String, nullable=False)
tcur = Column('tcur', REAL)
tcue = Column('tcue', REAL)
cgpa = Column('cgpa', REAL)
remarks = Column('remarks', String)
"""defines instances of students"""
def __init__(self, std_full_name, reg_no):
self.fullname = std_full_name.upper()
self.regno = reg_no.upper()
self.tcur = 0
self.tcue = 0
self.cgpa = 0
self.remarks = ''
def calculate_cgpa(self, subject, score):
self.tcur += subject.credit_unit
if score >= 70:
grade_point = 4.00
if subject.course_code in self.remarks:
update = self.remarks.replace(subject.course_code, '')
self.remarks = update
elif score >= 65:
grade_point = 3.50
if subject.course_code in self.remarks:
update = self.remarks.replace(subject.course_code, '')
self.remarks = update
elif score >= 60:
grade_point = 3.00
if subject.course_code in self.remarks:
update = self.remarks.replace(subject.course_code, '')
self.remarks = update
elif score >= 55:
grade_point = 2.50
if subject.course_code in self.remarks:
update = self.remarks.replace(subject.course_code, '')
self.remarks = update
elif score >= 50:
grade_point = 2.00
if subject.course_code in self.remarks:
update = self.remarks.replace(subject.course_code, '')
self.remarks = update
else:
grade_point = 0.00
self.remarks += subject.course_code
cue = float(grade_point * subject.credit_unit)
self.tcue += cue
self.cgpa = round(self.tcue/self.tcur, 2)
def __repr__(self):
return f"""
NAME: {self.fullname}
REG NO: {self.regno}
TCUR: {self.tcur}
TCUE: {self.tcue}
CGPA: {self.cgpa}
REMARKS: {self.remarks}"""
def test_print(self):
return f"""
NAME: {self.fullname}
REG NO: {self.regno}
TCUR: {self.tcur}
TCUE: {self.tcue}
CGPA: {self.cgpa}
REMARKS: {self.remarks}\n\n"""
engine = create_engine("sqlite:///2021_admission_pharm_tech_results.db", echo = True)
Base.metadata.create_all(bind=engine)
Session = sessionmaker(bind=engine)
session = Session()
# student_14 = Student('Zainab Dauda', 'cchstz/pt/105/21')
# student_14.calculate_cgpa(ctz_101, 64)
# student_14.calculate_cgpa(eng_101, 18)
# student_14.calculate_cgpa(ict_101, 40)
# student_14.calculate_cgpa(ptp_111, 50)
# student_14.calculate_cgpa(phy_111, 55)
# student_14.calculate_cgpa(chm_111, 41)
# student_14.calculate_cgpa(bio_111, 50)
# student_14.calculate_cgpa(etp_101, 50)
# student_14.calculate_cgpa(bdt_151, 62)
# student_14.calculate_cgpa(mth_111, 62)
# student_14.calculate_cgpa(bio_112, 60)
# student_14.calculate_cgpa(chm_112, 55)
# student_14.calculate_cgpa(phy_112, 47)
# student_14.calculate_cgpa(mth_112, 0)
# student_14.calculate_cgpa(eng_102, 37)
# student_14.calculate_cgpa(bdt_152, 33)
# student_14.calculate_cgpa(mcb_112, 34)
# student_14.calculate_cgpa(aum_122, 40)
# session.add(student_14)
# session.commit()
# with open('new', 'a') as f:
# test = session.query(Student).order_by(Student.regno).all()
# for student in test:
# f.write(student.test_print())
test = session.query(Student).order_by(desc(Student.cgpa)).all()
print(test)
#query and then update student
# update_record = session.query(Student).filter(Student.regno == 'cchstz/pt/104/21'.upper()).first()
# update_record.calculate_cgpa(hcp_361, 90)
# session.commit()
# DELETING DATA
# query = session.query(Student)
# query = query.filter(Student.regno == "cchstz/pt/105/21".upper())
# dcc_cookie = query.first()
# session.delete(dcc_cookie)
# session.commit()
# dcc_cookie = query.first()
# print(dcc_cookie)
#trying get method
# student = session.query(Student).get('cchstz/pt/107/21'.upper())
# print(student)
#how many students are above 2.0 cgpa
# student_2_0 = session.query(Student).filter(Student.cgpa >= 1.5).all()
# total_students = session.query(Student).all()
# print(f'{len(student_2_0)} students have above 1.5 cgpa out of {len(total_students)} students')