-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainLogic.py
475 lines (431 loc) · 15.6 KB
/
mainLogic.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
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
'''
Project: ERP System
Made by: Mohak Bhalla
'''
from datetime import datetime, date
from time import sleep
from os import system
import sys
import pyrebase
import smtplib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import winsound
config = {
"apiKey": "apiKey",
"authDomain": "ENTER YOUR DOMAIN NAME HERE",
"databaseURL": "ENTER DATABASE URL HERE",
"storageBucket": "ENTER YOUR DOMAIN NAME HERE"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
today = date.today()
today = str(today)
studentDB = pd.read_csv("Student_data.csv", index_col="Enroll ID")
facultyDB = pd.read_csv("Faculty_data.csv", index_col="Faculty ID")
#Clear function
def clear():
system('cls')
#The start menu function
def start_function(flag='y'):
clear()
day = datetime.now().strftime("%a")
if day != "Sat" and day != "Sun":
default_attendance()
while flag == 'y':
try:
print("\nERP System\n")
ch = int(input("""Would you like to :-
1. Log In
2. Sign Up
3. Exit
Choice : (1 / 2 / 3) -> """))
if 1 <= ch <= 3:
if ch == 1:
log_in_choice()
if ch == 2:
if day != "Sat" and day != "Sun":
sign_up_choice()
else:
print("\nThe institution is not functional on weekends.")
if ch == 3:
print(" ")
print("Exiting the program....")
sys.exit()
else:
print("Wrong choice:")
continue
except ValueError:
print("Wrong choice:")
continue
#Log-in menu function
def log_in_choice():
day = datetime.now().strftime("%a")
while 1:
print(" ")
ch = int(input("""Select an account type to Log In :-
1. For Students
2. For Faculty
3. For Management
4. Back
Choice : (1 / 2 / 3 / 4) -> """))
if 1 <= ch <= 4:
if ch == 1:
if day != "Sat" and day != "Sun":
for_student()
else:
print('''\nThe institution is not functional on weekends.
Attendance records are locked.''')
if ch == 2:
if day != "Sat" and day != "Sun":
for_faculty()
else:
print('''\nThe institution is not functional on weekends.
Attendance records are locked.''')
if ch == 3:
for_management()
if ch == 4:
print(" ")
print("Moving to previous Window....")
start_function('y')
else:
print("Wrong choice.")
continue
#Sign-up menu function
def sign_up_choice():
while 1:
print(" ")
ch = int(input("""Select an account type to Sign-Up :-
1. For Students
2. For Faculty
3. Back
Choice : (1 / 2 / 3 ) -> """))
if 1 <= ch <= 3:
if ch == 1:
sign_up("Student")
elif ch == 2:
sign_up("Faculty")
elif ch == 3:
print(" ")
print("Moving to previous Window....")
start_function('y')
else:
print("Wrong choice:")
continue
#Sign-up function
def sign_up(dept_name):
clear()
csvdate = datetime.now().strftime("%d-%b")
if dept_name == "Student":
enroll_id = input("Enter your Enrollment id: ")
a = 0
while a == 0:
if enroll_id not in list(db.child("Student_Data").get().val()):
a = 1
std_name = input("Enter Student Name: ")
en_pass = input("Enter a new Password: ")
data = {enroll_id: {en_pass: std_name}}
db.child("Student_Data").update(data)
if enroll_id in list(db.child("Student_Data").get().val()):
print("You have successfully enrolled as a Student.")
studentDB.loc[enroll_id, csvdate] = ['P']
studentDB.loc[enroll_id, ["Student Name"]] = [std_name]
print("\nYou have been marked PRESENT, " + std_name)
studentDB.to_csv("Student_data.csv")
else:
print("This Enrollment ID is already registered.")
print("Please Log in!..")
log_in_choice()
else:
faculty_id = input("Enter your Faculty id: ")
a = 0
while a == 0:
if faculty_id not in list(db.child("Faculty_Data").get().val()):
a = 1
fac_name = input("Enter Faculty Name: ")
en_pass = input("Enter a new Password: ")
data = {faculty_id: {en_pass: fac_name}}
db.child("Faculty_Data").update(data)
if faculty_id in list(db.child("Faculty_Data").get().val()):
print("You have successfully enrolled as a Faculty.")
facultyDB.loc[faculty_id, csvdate] = ['P']
facultyDB.loc[faculty_id, ["Faculty Name"]] = [fac_name]
print("\nYou have been marked PRESENT, " + fac_name)
facultyDB.to_csv("Faculty_data.csv")
else:
print("This Faculty ID is already registered.")
print("Please Log in!..")
log_in_choice()
#List to string function
def list_to_string(s):
str1 = ""
return str1.join(s)
#Student Sign-in functon
def for_student():
clear()
members = db.child("Student_Data").get().val()
b = 0
d = 0
while b == 0:
enroll_id = input("Enter your Enrollment ID: ")
if enroll_id in list(db.child("Student_Data").get().val()):
b = 1
while d == 0:
password = input("Enter your Password: ")
db_pass = list_to_string(list(members[enroll_id].keys()))
if db_pass == password:
d = 1
attendance(enroll_id, "Student Attendance")
print("\nYou have been marked PRESENT, " + members[enroll_id][password] + ".")
else:
d = 0
print("Wrong password . Try again...")
elif input("Did you enter the correct username? (y/n) ") == 'y':
print("Username does not exist!")
print("Please Sign Up ")
sign_up_choice()
else:
b = 0
continue
#Faculty Sign-in functon
def for_faculty():
clear()
members = db.child("Faculty_Data").get().val()
b = 0
d = 0
while b == 0:
enroll_id = input("Enter your Faculty ID: ")
if enroll_id in list(db.child("Faculty_Data").get().val()):
b = 1
while d == 0:
password = input("Enter your Password: ")
db_pass = list_to_string(list(members[enroll_id].keys()))
if db_pass == password:
d = 1
r = attendance(enroll_id, "Faculty Attendance")
if r == 1:
print("You have been marked PRESENT, " + members[enroll_id][password] + ".")
elif r == 0:
print("Your LEAVE application has been mailed to the Principal, " + members[enroll_id][password] + ".")
else:
d = 0
print("Wrong password . Try again...")
elif input("Did you enter the correct username? (y/n) ") == 'y':
print("Username does not exist!")
print("Please Sign Up ")
sign_up_choice()
else:
b = 0
continue
#Marking default attendance function
def default_attendance():
fac_att = db.child("Faculty Attendance").get()
student_att = db.child("Student Attendance").get()
csvdate = datetime.now().strftime("%d-%b")
series = pd.Series(np.array([]))
studentDB[csvdate] = series
facultyDB[csvdate] = series
for enroll_id in fac_att.each():
Date = max(enroll_id.val())
if today > Date:
now = datetime.now()
current_time = now.strftime("%H:%M")
data = {current_time: "A"}
facultyDB[csvdate].fillna("A", inplace=True)
db.child("Faculty Attendance").child(enroll_id.key()).update({today: data})
facultyDB.to_csv("Faculty_data.csv")
for enroll_id in student_att.each():
Date = max(enroll_id.val())
if today > Date:
now = datetime.now()
current_time = now.strftime("%H:%M")
data = {current_time: "A"}
studentDB[csvdate].fillna("A", inplace=True)
db.child("Student Attendance").child(enroll_id.key()).update({today: data})
studentDB.to_csv("Student_data.csv")
#Marking attendance function
'''
Add your email id in place of "PRINVIPAL_ID"
to receive the email.
Also, add 'googlemail.com' instead of 'gmail.com'
at the end of your email id.
'''
def attendance(enroll_id, temp):
csvdate = datetime.now().strftime("%d-%b")
if temp == "Faculty Attendance":
if fifty_alarm("Faculty Attendance", enroll_id) is True:
winsound.PlaySound("SystemExclamation", winsound.SND_ALIAS)
print("Your Attendance is less than 50%. ")
ch = input("\nInput 'P' to mark Present.\n"
"Input 'L' to inform for Leave.\n"
"Enter your choice: ").upper()
if ch == 'L':
emailid = input("Enter your Email ID:- ")
pswd = getpass.getpass("Enter your Password: ")
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.login(emailid, pswd)
print("\nType 'END' to end the message")
print("Type here...")
buffer = ''
text = ''
while buffer != 'END':
text += "\n" + buffer
buffer = input()
message = 'Subject: {}\n\n{}'.format("Leave Application for " + csvdate, text)
s.sendmail(emailid, "PRINCIPAL_ID", message)
s.close()
facultyDB = pd.read_csv("Faculty_data.csv", index_col="Faculty ID")
now = datetime.now()
current_time = now.strftime("%H:%M")
data = {current_time: ch}
db.child(temp).child(enroll_id).update({today: data})
tempDB = facultyDB.to_dict()
tempDB[csvdate][int(enroll_id)] = ch
DataB = pd.DataFrame(tempDB)
DataB.index.name = 'Faculty ID'
DataB.to_csv("Faculty_data.csv")
if ch == 'P':
return 1
else:
return 0
else:
if fifty_alarm("Student Attendance", enroll_id) is True:
winsound.PlaySound("SystemExclamation", winsound.SND_ALIAS)
print("Your Attendance is less than 50%. ")
studentDB = pd.read_csv("Student_data.csv", index_col="Enroll ID")
now = datetime.now()
current_time = now.strftime("%H:%M")
data = {current_time: "P"}
db.child(temp).child(enroll_id).update({today: data})
tempDB = studentDB.to_dict()
tempDB[csvdate][int(enroll_id)] = 'P'
DataB = pd.DataFrame(tempDB)
DataB.index.name = 'Enroll ID'
DataB.to_csv("Student_data.csv")
#Alarm function
def fifty_alarm(dept_name, enroll_id):
if dept_name == "Faculty Attendance":
FacultyDB = pd.read_csv("Faculty_data.csv", index_col="Faculty ID")
tempDB = FacultyDB.to_dict()
p = 0
a = 0
for ident in tempDB:
if ident != "Faculty Name":
if tempDB[ident][int(enroll_id)] == "P":
p += 1
elif tempDB[ident][int(enroll_id)] == "A" or "L":
a += 1
perc = p / (p + a) * 100
if perc < 50.00:
return True
else:
studentDB = pd.read_csv("Student_data.csv", index_col="Enroll ID")
tempDB = studentDB.to_dict()
p = 0
a = 0
for ident in tempDB:
if ident != "Faculty Name":
if tempDB[ident][int(enroll_id)] == "P":
p += 1
elif tempDB[ident][int(enroll_id)] == "A":
a += 1
perc = p / (p + a) * 100
if perc < 50.00:
return True
#Displaying Graph function
def view_graph(dept_name):
if dept_name == "Student":
studentDB = pd.read_csv("Student_data.csv", index_col="Enroll ID")
print("")
print(studentDB)
tempDB = studentDB.to_dict('index')
name = []
percent = []
for ident in tempDB:
data = tempDB[ident]
name.append(data.pop("Student Name"))
t = 0
c = 0
for given_date in data:
if data[given_date] == 'P':
t += 1
c += 1
elif data[given_date] == 'A':
t += 1
percent.append(100 * c / t)
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ax.bar(name, percent)
ax.set_title("Student's Attendance Records Chart")
ax.set_xlabel("Name")
ax.set_ylabel("Attendance Percentage")
plt.show()
else:
facultyDB = pd.read_csv("Faculty_data.csv", index_col="Faculty ID")
print("")
print(facultyDB)
tempDB = facultyDB.to_dict('index')
name = []
percent = []
for ident in tempDB:
data = tempDB[ident]
name.append(data.pop("Faculty Name"))
t = 0
c = 0
for given_date in data:
if data[given_date] == 'P':
t += 1
c += 1
elif data[given_date] == 'A' or 'L':
t += 1
percent.append(100 * c / t)
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ax.bar(name, percent)
ax.set_title("Student's Attendance Records Chart")
ax.set_xlabel("Name")
ax.set_ylabel("Attendance Percentage")
plt.show()
#Management view function
def for_management():
princi = db.child("Principal").get().val()
b = 0
while b == 0:
pswd = input("\nEnter the password: ")
if pswd in db.child("Principal").child(pswd).get().key():
print("\nWelcome Principal " + princi[pswd])
b = 1
while 1:
print(" ")
ch = int(input("""Access attendance records of:-
1. Students
2. Faculty
3. Back
Choice : (1 / 2 / 3 ) -> """))
if 1 <= ch <= 3:
if ch == 1:
view_graph("Student")
if ch == 2:
view_graph("Faculty")
if ch == 3:
print(" ")
print("Moving to previous Window....")
log_in_choice()
else:
print("Incorrect choice.")
continue
else:
b = 0
print("Incorrect Password.")
print("Try Again.")
continue
#Program start commands
print("Connecting to Database....")
sleep(2)
print("Connected!")
print("Loading Main Screen....")
sleep(3)
start_function()