-
Notifications
You must be signed in to change notification settings - Fork 16
/
check_attendance.py
132 lines (112 loc) · 4.35 KB
/
check_attendance.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
from PyQt4 import QtGui,QtCore
import sqlite3
import datetime
conn=sqlite3.connect('Attendance System.db')
c=conn.cursor()
class CheckAttendance(QtGui.QMainWindow):
def __init__(self,sub):
self.subject=sub
super(CheckAttendance, self).__init__()
self.setGeometry(300,50,800,600)
self.setWindowTitle("Check Attendance")
self.setWindowIcon(QtGui.QIcon('other_images/logo.png'))
#Heading
h=QtGui.QLabel(self)
h.setAlignment(QtCore.Qt.AlignCenter)
h.setGeometry(QtCore.QRect(250,20,300,40))
h.setStyleSheet("QLabel { background-color : blue;color :white ; }")
font=QtGui.QFont("Times",16,QtGui.QFont.Bold)
h.setFont(font)
h.setText("CHECK ATTENDANCE")
#Label and Date Entry Spinbox
l2=QtGui.QLabel(self)
l2.setAlignment(QtCore.Qt.AlignCenter)
l2.setGeometry(QtCore.QRect(230,100,80,30))
l2.setStyleSheet("QLabel { background-color : gray;color :black ; }")
font1=QtGui.QFont("Times",14,QtGui.QFont.Bold)
l2.setFont(font1)
l2.setText("DATE")
self.dd=QtGui.QSpinBox(self)
self.dd.setAlignment(QtCore.Qt.AlignCenter)
self.dd.setGeometry(330,100,50,30)
self.dd.setFont(font1)
self.dd.setRange(1,31)
self.dd.setValue(datetime.date.today().day)
self.mm=QtGui.QSpinBox(self)
self.mm.setAlignment(QtCore.Qt.AlignCenter)
self.mm.setGeometry(380,100,50,30)
self.mm.setFont(font1)
self.mm.setRange(1,12)
self.mm.setValue(datetime.date.today().month)
self.yyyy=QtGui.QSpinBox(self)
self.yyyy.setGeometry(430,100,70,30)
self.yyyy.setFont(font1)
self.yyyy.setRange(2014,2050)
self.yyyy.setValue(datetime.date.today().year)
#Go Button to check specific Date's Attendance
b=QtGui.QPushButton(self)
b.setText("GO!")
b.setFont(font1)
b.setGeometry(510,100,60,30)
b.setStyleSheet("QPushButton { background-color : green;color : white ; }")
b.clicked.connect(self.show_database)
#Text Area To display database
self.text=QtGui.QTextEdit(self)
self.text.setGeometry(40,170,720,350)
self.text.setFont(font1)
#Default Display of Subject's Total Attendance on every date
xyear = (int(self.subject[2])+1)//2
query='SELECT * FROM YEAR{}'.format(xyear)
c.execute(query)
rolls = []
names = []
for row in c.fetchall():
rolls.append(row[0])
names.append(row[1])
self.text.insertPlainText('Roll\tName\tAttendance %\n')
for i in range(len(rolls)):
query='SELECT ['+ str(rolls[i]) + '] FROM {}'.format(self.subject)
print (query)
c.execute(query)
p = 0 #present
a = 0 #absent
for row in c.fetchall():
if (row[0] == 'P'):
p += 1
else:
a += 1
self.text.insertPlainText(str(rolls[i])+'\t'+str(names[i])+'\t'+str((100*p)/(p+a))+'\n')
def show_database(self):
#To display attendance on specific date
date=str(self.yyyy.value())+str(self.mm.value())+str(self.dd.value())
self.text.clear()
temp = 'Roll\tName\t'+self.format_date(date)
self.text.insertPlainText(temp+'\n')
xyear = (int(self.subject[2])+1)//2
query='SELECT * FROM YEAR{}'.format(xyear)
c.execute(query)
rolls = []
names = []
for row in c.fetchall():
rolls.append(row[0])
names.append(row[1])
for i in range(len(rolls)):
query='SELECT Date, ['+ str(rolls[i]) + '] FROM {} where Date = {}'.format(self.subject, date)
print (query)
c.execute(query)
temp = str(rolls[i])+'\t'+str(names[i])+'\t'
for row in c.fetchall():
temp += (row[1])
self.text.insertPlainText(temp+'\n')
def format_date(self, s):
year = s[:4]
month = s[4:6]
date = s[6:]
return date+'-'+month+'-'+year
if __name__ == '__main__':
app = QtGui.QApplication([])
gui = CheckAttendance()
gui.show()
app.exec_()
c.close()
conn.close()