def create_new_batch(self): global class_codes class_name = self.tv_class.get() number_of_studs = int(self.tv_number.get()) batchexists = os.path.exists( os.path.join(os.getcwd(), "extras", class_name)) if batchexists: messagebox.showerror("Error", "This batch name already exists") return if number_of_studs < 1 or number_of_studs > 99: messagebox.showerror("Error", "Number of students not in allowed range!") return images_dir = os.path.join(os.getcwd(), "images", class_name) unrecog_studs_dir = os.path.join(os.getcwd(), "images", class_name, "unrecognized students") os.makedirs(unrecog_studs_dir) for i in range(number_of_studs): os.makedirs(os.path.join(images_dir, "s" + str(i).zfill(2))) studs_list_file = os.path.join(os.getcwd(), "student's list", f"{class_name}.xlsx") wb = Workbook() wb.guess_types = True ws = wb.active ws["A1"] = 0 ws["B1"] = number_of_studs wb.save(studs_list_file) classes_file = os.path.join(os.getcwd(), "extras", "classes.xlsx") wb = load_workbook(classes_file) ws = wb.active row = ws["A1"].value ws["A1"] = row + 1 ws["A" + str(row + 2)] = class_name wb.save(classes_file) sl = StudentsList(class_name) sl.make_pkl_file() atten_reg_dir = os.path.join(os.getcwd(), "extras", class_name) os.makedirs(atten_reg_dir) wb = excel.attendance_workbook(class_name) messagebox.showinfo( "Batch Successfully Created", "All the necessary Directories and Files created" f"for Batch-Code {class_name}", ) class_codes.add(class_name) self.tv_class.delete(0, END) self.tv_number.delete(0, END) self.tv_number.insert(0, "") self.controller.show_frame("StartPage")
def doWork(self): global current_class students_list_file = os.path.join(os.getcwd(), "student's list", f'{current_class}.xlsx') wb = load_workbook(students_list_file) ws = wb.active total_studs = ws['B1'].value currently_studs = ws['A1'].value if currently_studs == total_studs: messagebox.showinfo("Batch Full", "No more accomodation for any new student") return ws['A1'] = currently_studs + 1 row_here = currently_studs + 2 student_name = self.tv_name.get() ws['A' + str(row_here)] = student_name roll_no = currently_studs roll_no = str(roll_no).zfill(2) ws['B' + str(row_here)] = current_class + roll_no wb.save(students_list_file) sl = StudentsList(current_class) sl.make_pkl_file() atten_reg = os.path.join(os.getcwd(), 'extras', current_class, f'{current_class}.xlsx') wb = load_workbook(atten_reg) today = datetime.now().date() month = today.strftime('%B') try: # If current month exists ws = wb[month] row_here = excel.gap + int(roll_no) ws.merge_cells(start_row=row_here, start_column=3, end_row=row_here, end_column=4) ws.cell(row=row_here, column=1, value=str(int(roll_no) + 1)) fill_roll = excel.PatternFill(fgColor='A5EFAF', fill_type='solid') fill_name = excel.PatternFill(fgColor='E9EFA5', fill_type='solid') ws.cell(row=row_here, column=2, value=current_class + roll_no).fill = fill_roll ws.cell(row=row_here, column=3, value=student_name).fill = fill_name cellrange = 'A' + str(row_here) + ':AN' + str(row_here) excel.set_border(ws, cellrange) first_date_column = excel.get_column_letter(excel.date_column) days_in_month = monthrange(today.year, today.month)[1] last_date_column = excel.get_column_letter(excel.date_column + days_in_month - 1) sum_cell_column = excel.date_column + days_in_month + 1 fill_total = excel.PatternFill(fgColor='25F741', fill_type='solid') ws.cell(row=row_here, column=sum_cell_column, value="=SUM(" + first_date_column + str(row_here) + ":" + last_date_column + str(row_here) + ")").fill = fill_total wb.save(atten_reg) except: # If current month does not exist wb = excel.attendance_workbook(current_class) image_dir = os.path.join(os.getcwd(), 'images', current_class, 's' + roll_no) messagebox.showinfo('Student Added', f"{student_name} admitted!\n" "Click OK to proceed for capturing training images. " "Make sure that your surroundings are well lit") i = 5 face_detected_right = False xml_file = os.path.join(os.getcwd(), 'haarcascade_frontalface_default.xml') while i > 0: while face_detected_right is False: img_path, frame = capture() face_detected_right = detect_faces(xml_file, frame) img_path = os.path.join( os.getcwd(), 'images', current_class, "s"+str(roll_no).zfill(2), os.path.basename(img_path) ) cv2.imwrite(img_path, frame) cv2.destroyAllWindows() face_detected_right = False i = i - 1 if i == 0: messagebox.showinfo("Message", "Training images added successfully!") messagebox.showinfo('Enrollment Number', f'Roll Number of student: {current_class + roll_no}') self.tv_name.delete(0, END)