Skip to content
Extraits de code Groupes Projets
Valider 326838a4 rédigé par Adrien Payen's avatar Adrien Payen
Parcourir les fichiers

last update

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