diff --git a/projet_personnel/algorithme_gestion_etudiants.py b/projet_personnel/algorithme_gestion_etudiants.py index d56573970741a4f89a4e4b40b9fec0386fce9f23..03b03100f5ba0a0d8367f733fa3a60acd12de098 100644 --- a/projet_personnel/algorithme_gestion_etudiants.py +++ b/projet_personnel/algorithme_gestion_etudiants.py @@ -19,9 +19,7 @@ all_course_MA2 = ("Advanced English 2", "Español avanzado 1", "Responsabilité - - -file_path = '/Users/adrien/vscodeworkspace/coding-project/Data_Base.xlsx' +file_path = '/coding-project/Data_Base.xlsx' data = pd.read_excel(file_path) excel_file_path = 'export_names.xlsx' @@ -46,159 +44,164 @@ def reload_data(file_path): # REGISTER def register_student(data): # Setting up the patterns to follow for entering information - while True: - Firstname = input("What is the student's firstname? ") # Ask the user for the name - if name_pattern.match(Firstname): # Check if the name matches the specified format - print(f"The firstname is valid : {Firstname}") - break # Exit the loop if the name is valid - else: - print("The firstname is not valid. Make sure to follow the specified format.") + user_input = input("Enter 'q' to quit or any other key to continue: ") + if user_input.lower() == 'q': + print("Operation canceled.") + return - while True: - Lastname = input("What is the student's lastname? ") # Ask the user for the surname - if name_pattern.match(Lastname): - print(f"The lastname is valid : {Lastname}") - break # Exit the loop if the surname is valid - else: - print("The lastname is not valid. Make sure to follow the specified format.") + while True: + Firstname = input("What is the student's firstname? ") # Ask the user for the name + if name_pattern.match(Firstname): # Check if the name matches the specified format + print(f"The firstname is valid : {Firstname}") + break # Exit the loop if the name is valid + else: + print("The firstname is not valid. Make sure to follow the specified format.") - while True: - Date_of_birth = input("Please enter a date in the format dd/mm/yyyy: ") - if date_pattern.match(Date_of_birth): - print(f"The date is valid : {Date_of_birth}") - break # Exit the loop if the date is valid - else: - print("The date is not valid. Make sure to follow the format dd/mm/yyyy.") + while True: + Lastname = input("What is the student's lastname? ") # Ask the user for the surname + if name_pattern.match(Lastname): + print(f"The lastname is valid : {Lastname}") + break # Exit the loop if the surname is valid + else: + print("The lastname is not valid. Make sure to follow the specified format.") - while True: - Place_of_birth = input("What is the city of birth? ") - if place_of_birth_pattern.match(Place_of_birth): - print(f"The place of birth is valid : {Place_of_birth}") - break # Exit the loop if the city of birth is valid - else: - print("The city of birth is not valid. Make sure to use only letters and spaces.") + while True: + Date_of_birth = input("Please enter a date in the format dd/mm/yyyy: ") + if date_pattern.match(Date_of_birth): + print(f"The date is valid : {Date_of_birth}") + break # Exit the loop if the date is valid + else: + print("The date is not valid. Make sure to follow the format dd/mm/yyyy.") - while True: - Address = input("Please enter an address in the format 'street number, city': ") - if address_pattern.match(Address): - print(f"The address is valid : {Address}") - break # Exit the loop if the address is valid - else: - print("The address is not valid. Make sure to follow the format 'street number, city'.") + while True: + Place_of_birth = input("What is the city of birth? ") + if place_of_birth_pattern.match(Place_of_birth): + print(f"The place of birth is valid : {Place_of_birth}") + break # Exit the loop if the city of birth is valid + else: + print("The city of birth is not valid. Make sure to use only letters and spaces.") - while True: - Telephone = input("What is the telephone number? (in the format 0000/00.00.00) ") - if telephone_pattern.match(Telephone): - print(f"The telephone number is valid : {Telephone}") - break # Exit the loop if the telephone number is valid - else: - print("The telephone number is not valid. Make sure to follow the requested format.") + while True: + Address = input("Please enter an address in the format 'street number, city': ") + if address_pattern.match(Address): + print(f"The address is valid : {Address}") + break # Exit the loop if the address is valid + else: + print("The address is not valid. Make sure to follow the format 'street number, city'.") - print("The email address was completed automatically. If it is not suitable you can modify it later : ") - email_of_student = f"{Firstname}{'.'}{Lastname}{'@student.uclouvain.be'}" - Email = email_of_student.lower() - print(Email) + while True: + Telephone = input("What is the telephone number? (in the format 0000/00.00.00) ") + if telephone_pattern.match(Telephone): + print(f"The telephone number is valid : {Telephone}") + break # Exit the loop if the telephone number is valid + else: + print("The telephone number is not valid. Make sure to follow the requested format.") + + print("The email address was completed automatically. If it is not suitable you can modify it later : ") + email_of_student = f"{Firstname}{'.'}{Lastname}{'@student.uclouvain.be'}" + Email = email_of_student.lower() + print(Email) + + while True: + Gender = input("What is your gender? (For Male enter M, for Female enter F, and for another type enter O): ") + if gender_pattern.match(Gender): + print(f"The gender is valid : {Gender}") + break # Exit the loop if the gender is valid + else: + print("The gender is not valid. Make sure to follow the requested format.") - while True: - Gender = input("What is your gender? (For Male enter M, for Female enter F, and for another type enter O): ") - if gender_pattern.match(Gender): - print(f"The gender is valid : {Gender}") - break # Exit the loop if the gender is valid - else: - print("The gender is not valid. Make sure to follow the requested format.") + while True: + Academic_year = input("What is your academic year? (BAC1/BAC2/BAC3/MA1/MA2): ") + if academic_year_pattern.match(Academic_year): + print(f"The academic year is valid : {Academic_year}") + break # Exit the loop if the academic year is valid + else: + print("The academic year is not valid. Make sure to follow the requested format.") - while True: - Academic_year = input("What is your academic year? (BAC1/BAC2/BAC3/MA1/MA2): ") - if academic_year_pattern.match(Academic_year): - print(f"The academic year is valid : {Academic_year}") - break # Exit the loop if the academic year is valid - else: - print("The academic year is not valid. Make sure to follow the requested format.") - - if Academic_year in ['BAC1', 'BAC2', 'BAC3'] : - Curriculum = "INGM1BA" - else : - Curriculum = "INGM2M" - - Courses_and_grade = {} - if Academic_year == 'MA2': - for course in all_course_BAC1 + all_course_BAC2 + all_course_BAC3 + all_course_MA1 + all_course_MA2: - grade = input(f"What is the grade for {course}? ") - while not grade.isdigit() or int(grade) not in range(0, 21): - print("The grade must be an integer between 0 and 20.") + if Academic_year in ['BAC1', 'BAC2', 'BAC3'] : + Curriculum = "INGM1BA" + else : + Curriculum = "INGM2M" + + Courses_and_grade = {} + if Academic_year == 'MA2': + for course in all_course_BAC1 + all_course_BAC2 + all_course_BAC3 + all_course_MA1 + all_course_MA2: grade = input(f"What is the grade for {course}? ") - Courses_and_grade[course] = int(grade) - elif Academic_year == 'MA1': - for course in all_course_BAC1 + all_course_BAC2 + all_course_BAC3 + all_course_MA1: - grade = input(f"What is the grade for {course}? ") - while not grade.isdigit() or int(grade) not in range(0, 21): - print("The grade must be an integer between 0 and 20.") + while not grade.isdigit() or int(grade) not in range(0, 21): + print("The grade must be an integer between 0 and 20.") + grade = input(f"What is the grade for {course}? ") + Courses_and_grade[course] = int(grade) + elif Academic_year == 'MA1': + for course in all_course_BAC1 + all_course_BAC2 + all_course_BAC3 + all_course_MA1: grade = input(f"What is the grade for {course}? ") - Courses_and_grade[course] = int(grade) - elif Academic_year == 'BAC3': - for course in all_course_BAC1 + all_course_BAC2 + all_course_BAC3: - grade = input(f"What is the grade for {course}? ") - while not grade.isdigit() or int(grade) not in range(0, 21): - print("The grade must be an integer between 0 and 20.") + while not grade.isdigit() or int(grade) not in range(0, 21): + print("The grade must be an integer between 0 and 20.") + grade = input(f"What is the grade for {course}? ") + Courses_and_grade[course] = int(grade) + elif Academic_year == 'BAC3': + for course in all_course_BAC1 + all_course_BAC2 + all_course_BAC3: grade = input(f"What is the grade for {course}? ") - Courses_and_grade[course] = int(grade) - elif Academic_year == 'BAC2': - for course in all_course_BAC1 + all_course_BAC2: - grade = input(f"What is the grade for {course}? ") - while not grade.isdigit() or int(grade) not in range(0, 21): - print("The grade must be an integer between 0 and 20.") + while not grade.isdigit() or int(grade) not in range(0, 21): + print("The grade must be an integer between 0 and 20.") + grade = input(f"What is the grade for {course}? ") + Courses_and_grade[course] = int(grade) + elif Academic_year == 'BAC2': + for course in all_course_BAC1 + all_course_BAC2: grade = input(f"What is the grade for {course}? ") - Courses_and_grade[course] = int(grade) - elif Academic_year == 'BAC1': - for course in all_course_BAC1: - grade = input(f"What is the grade for {course}? ") - while not grade.isdigit() or int(grade) not in range(0, 21): - print("The grade must be an integer between 0 and 20.") + while not grade.isdigit() or int(grade) not in range(0, 21): + print("The grade must be an integer between 0 and 20.") + grade = input(f"What is the grade for {course}? ") + Courses_and_grade[course] = int(grade) + elif Academic_year == 'BAC1': + for course in all_course_BAC1: grade = input(f"What is the grade for {course}? ") - Courses_and_grade[course] = int(grade) - - while True: - Campus = input("Enter 'Louvain-la-Neuve' or 'Mons' depending on the campus: ") - if campus_pattern.match(Campus): - print("The campus choice is valid.") - break # Exit the loop if the campus choice is valid - else: - print("The campus choice is not valid. Make sure to follow the requested format.") - - matricule = generate_matricule(Firstname, Lastname, Date_of_birth) - - register(data, Firstname, Lastname, Curriculum, Date_of_birth, Place_of_birth, Address, Telephone, Email, Gender, Academic_year, Courses_and_grade, Campus, matricule) - - # Display the entered information - print("\nEntered Information:") - print(f"Firstname: {Firstname}") - print(f"Lastname: {Lastname}") - print(f"Date of Birth: {Date_of_birth}") - print(f"Place of Birth: {Place_of_birth}") - print(f"Address: {Address}") - print(f"Telephone: {Telephone}") - print(f"Email: {Email}") - print(f"Gender: {Gender}") - print(f"Academic Year: {Academic_year}") - print(f"Curriculum: {Curriculum}") - print(f"Courses and Grades: {Courses_and_grade}") - print(f"Campus: {Campus}") - print(f"Matricule: {matricule}") - - while True: - # Ask the user if they want to modify any information before registration - modify_info = input("Do you want to modify any information before registration? (YES/NO): ").upper() - if modify_info == "YES": - data = reload_data(file_path) - modify(data) # Call the modify function to update information - break # Exit the loop after modification - elif modify_info == "NO": - break # Exit the loop if no modification is needed - else: - print("Invalid input. Please enter either 'YES' or 'NO'.") + while not grade.isdigit() or int(grade) not in range(0, 21): + print("The grade must be an integer between 0 and 20.") + grade = input(f"What is the grade for {course}? ") + Courses_and_grade[course] = int(grade) + + while True: + Campus = input("Enter 'Louvain-la-Neuve' or 'Mons' depending on the campus: ") + if campus_pattern.match(Campus): + print("The campus choice is valid.") + break # Exit the loop if the campus choice is valid + else: + print("The campus choice is not valid. Make sure to follow the requested format.") + + matricule = generate_matricule(Firstname, Lastname, Date_of_birth) + + register(data, Firstname, Lastname, Curriculum, Date_of_birth, Place_of_birth, Address, Telephone, Email, Gender, Academic_year, Courses_and_grade, Campus, matricule) + + # Display the entered information + print("\nEntered Information:") + print(f"Firstname: {Firstname}") + print(f"Lastname: {Lastname}") + print(f"Date of Birth: {Date_of_birth}") + print(f"Place of Birth: {Place_of_birth}") + print(f"Address: {Address}") + print(f"Telephone: {Telephone}") + print(f"Email: {Email}") + print(f"Gender: {Gender}") + print(f"Academic Year: {Academic_year}") + print(f"Curriculum: {Curriculum}") + print(f"Courses and Grades: {Courses_and_grade}") + print(f"Campus: {Campus}") + print(f"Matricule: {matricule}") + + while True: + # Ask the user if they want to modify any information before registration + modify_info = input("Do you want to modify any information before registration? (YES/NO): ").upper() + if modify_info == "YES": + data = reload_data(file_path) + modify(data) # Call the modify function to update information + break # Exit the loop after modification + elif modify_info == "NO": + break # Exit the loop if no modification is needed + else: + print("Invalid input. Please enter either 'YES' or 'NO'.") - return + return @@ -479,64 +482,75 @@ field_mapping = { # DELETION OF A STUDENT BASED ON HIS MATRICULE BECAUSE IT'S UNIQUE def delete(data): - matricule_to_delete = input("Enter the matricule of the student you want to delete: ") - student_index = data[data['Matricule'] == matricule_to_delete.lower()].index.tolist() + while True: + user_input = input("Enter 'q' to quit or any other key to continue: ") + if user_input.lower() == 'q': + print("Operation canceled.") + return + + matricule_to_delete = input("Enter the matricule of the student you want to delete: ") + student_index = data[data['Matricule'] == matricule_to_delete.lower()].index.tolist() - if not student_index: - print("No student found with the specified matricule.") - return + if not student_index: + print("No student found with the specified matricule.") + return - student_index = student_index[0] - print(f"\nDeleting the student with matricule {matricule_to_delete}:\n") + student_index = student_index[0] + print(f"\nDeleting the student with matricule {matricule_to_delete}:\n") - # Display the details of the student before deletion - print("Details of the student before deletion:") - print(data.iloc[student_index]) + # Display the details of the student before deletion + print("Details of the student before deletion:") + print(data.iloc[student_index]) - confirmation = input("Do you really want to delete this student? (YES/NO) ").upper() - if confirmation == "YES": - # Delete the student - data = data.drop(index=student_index) + confirmation = input("Do you really want to delete this student? (YES/NO) ").upper() + if confirmation == "YES": + # Delete the student + data = data.drop(index=student_index) - # Save the modified data to the Excel file - data.to_excel(file_path, index=False) - print("Deletion successful.") - else: - print("Deletion canceled.") + # Save the modified data to the Excel file + data.to_excel(file_path, index=False) + print("Deletion successful.") + else: + print("Deletion canceled.") # FIND def find_student(data): - print("Below are the search criteria:") - print("1. By his/her lastname") - print("2. By his/her firstname") - print("3. By his/her matricule") - while True: - search_criteria = input("Enter the number of what you want to do: ") - - if search_criteria == "1": - surname_search = input("Enter the lastname of the student: ") - results = find_similar_data(data['Lastname'], surname_search, 'Lastname') - break - elif search_criteria == "2": - name_search = input("Enter the firstname of the student: ") - results = find_similar_data(data['Firstname'], name_search, 'Firstname') - break - elif search_criteria == "3": - matricule_search = input("Enter the matricule of the student: ") - results = find_similar_data(data['Matricule'], matricule_search, 'Matricule') - break + user_input = input("Enter 'q' to quit or any other key to continue: ") + if user_input.lower() == 'q': + print("Operation canceled.") + return + print("Below are the search criteria:") + print("1. By his/her Lastname") + print("2. By his/her Firstname") + print("3. By his/her Matricule") + + while True: + search_criteria = input("Enter the number of what you want to do: ") + + if search_criteria == "1": + surname_search = input("Enter the lastname of the student: ") + results = find_similar_data(data['Lastname'], surname_search, 'Lastname') + break + elif search_criteria == "2": + name_search = input("Enter the firstname of the student: ") + results = find_similar_data(data['Firstname'], name_search, 'Firstname') + break + elif search_criteria == "3": + matricule_search = input("Enter the matricule of the student: ") + results = find_similar_data(data['Matricule'], matricule_search, 'Matricule') + break + else: + print("Invalid search criteria. Please enter a valid number.") + + if results.empty: + print("No student found with the specified criteria.") else: - print("Invalid search criteria. Please enter a valid number.") - - if results.empty: - print("No student found with the specified criteria.") - else: - print("Student(s) found:") - for index, row in results.iterrows(): - print(f"Firstname: {row['Firstname']}, Lastname: {row['Lastname']}, Matricule: {row['Matricule']}") + print("Student(s) found:") + for index, row in results.iterrows(): + print(f"Firstname: {row['Firstname']}, Lastname: {row['Lastname']}, Matricule: {row['Matricule']}") def find_similar_data(column, search_term, column_name): # Using fuzzywuzzy to find similar values in the specified column diff --git a/~$Data_Base.xlsx b/~$Data_Base.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..d10daf560a7f8247050905285b3e618c244966d6 Binary files /dev/null and b/~$Data_Base.xlsx differ