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

90% of the project done

parent 50e8e88e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Fichier ajouté
...@@ -3,8 +3,24 @@ import pandas as pd ...@@ -3,8 +3,24 @@ import pandas as pd
import os import os
import statistics import statistics
import re import re
from IPython.display import display
from tabulate import tabulate
file_path = '/content/Data_Base.xlsx' all_course_BAC1 = ("Anglais 1", "Fondements du droit public", "Fondements du droit de l'entreprise", "Economie", "Espagnol 1", "Comptabilité", "Informatique de gestion", "Mathématiques de gestion 1", "Statistiques et probabilités", "Pilosophie", "Psychologie", "Sociologie", "Séminaire de travail universitaire en gestion")
all_course_BAC2 = ("Anglais 2", "Droit de l'entreprise", "Macroéconomie", "Microéconomie", "Espagnol 2", "Marketing", "Production", "Informatique et algorithmique", "Finance", "Inférences statistiques", "Mathématiques de gestion 2", "Technologies industrielles")
all_course_BAC3 = ("Anglais 3", "Economie industrielle", "Espagnol 3", "Séminaire : organisations et transformation digitale", "Management humain", "Projet entrepreneurial", "Comptabilité et contrôle de gestion", "Gestion de données", "Coding project", "Econométrie", "Recherche opérationnelle", "Optimization", "Séminaire : organisation et mutations sociales", "Questions de sciences religieuses")
all_course_MA1 = ("Advanced English 1", "Español avanzado 1", "Data analytics", "Projet quantitatif et gestion de projet", "Data Mining", "Nouvelles technologies et pratiques émergentes", "Web mining", "Machine learning", "Quantitative Decision Making", "Recommender Systems", "Pilotage stratégique de l'entreprise", "Séminaire on Current Managerial Issues")
all_course_MA2 = ("Advanced English 2", "Español avanzado 1", "Responsabilité sociétale de l'entreprise","Integrated Information Systems", "Mémoire", "Séminaire d'accompagnement du mémoire")
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'
...@@ -27,25 +43,25 @@ def register_student(data): ...@@ -27,25 +43,25 @@ 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:
Name = input("What is the student's name? ") # Ask the user for the name Firstname = input("What is the student's firstname? ") # Ask the user for the name
if name_pattern.match(Name): # Check if the name matches the specified format if name_pattern.match(Firstname): # Check if the name matches the specified format
print("The name is valid.") print(f"The firstname is valid : {Firstname}")
break # Exit the loop if the name is valid break # Exit the loop if the name is valid
else: else:
print("The name 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:
Surname = input("What is the student's surname? ") # Ask the user for the surname Lastname = input("What is the student's lastname? ") # Ask the user for the surname
if name_pattern.match(Surname): if name_pattern.match(Lastname):
print("The surname is valid.") print(f"The lastname is valid : {Lastname}")
break # Exit the loop if the surname is valid break # Exit the loop if the surname is valid
else: else:
print("The surname is not valid. Make sure to follow the specified format.") print("The lastname 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: ") Date_of_birth = input("Please enter a date in the format dd/mm/yyyy: ")
if date_pattern.match(Date_of_birth): if date_pattern.match(Date_of_birth):
print("The date is valid.") print(f"The date is valid : {Date_of_birth}")
break # Exit the loop if the date is valid break # Exit the loop if the date is valid
else: else:
print("The date is not valid. Make sure to follow the format dd/mm/yyyy.") print("The date is not valid. Make sure to follow the format dd/mm/yyyy.")
...@@ -53,7 +69,7 @@ def register_student(data): ...@@ -53,7 +69,7 @@ def register_student(data):
while True: while True:
Place_of_birth = input("What is the city of birth? ") Place_of_birth = input("What is the city of birth? ")
if place_of_birth_pattern.match(Place_of_birth): if place_of_birth_pattern.match(Place_of_birth):
print("The city of birth is valid.") print(f"The place of birth is valid : {Place_of_birth}")
break # Exit the loop if the city of birth is valid break # Exit the loop if the city of birth is valid
else: else:
print("The city of birth is not valid. Make sure to use only letters and spaces.") print("The city of birth is not valid. Make sure to use only letters and spaces.")
...@@ -61,7 +77,7 @@ def register_student(data): ...@@ -61,7 +77,7 @@ def register_student(data):
while True: while True:
Address = input("Please enter an address in the format 'street number, city': ") Address = input("Please enter an address in the format 'street number, city': ")
if address_pattern.match(Address): if address_pattern.match(Address):
print("The address is valid.") print(f"The address is valid : {Address}")
break # Exit the loop if the address is valid break # Exit the loop if the address is valid
else: else:
print("The address is not valid. Make sure to follow the format 'street number, city'.") print("The address is not valid. Make sure to follow the format 'street number, city'.")
...@@ -69,7 +85,7 @@ def register_student(data): ...@@ -69,7 +85,7 @@ def register_student(data):
while True: while True:
Telephone = input("What is the telephone number? (in the format 000/00.00.00) ") Telephone = input("What is the telephone number? (in the format 000/00.00.00) ")
if telephone_pattern.match(Telephone): if telephone_pattern.match(Telephone):
print("The telephone number is valid.") print(f"The telephone number is valid : {Telephone}")
break # Exit the loop if the telephone number is valid break # Exit the loop if the telephone number is valid
else: else:
print("The telephone number is not valid. Make sure to follow the requested format.") print("The telephone number is not valid. Make sure to follow the requested format.")
...@@ -77,7 +93,7 @@ def register_student(data): ...@@ -77,7 +93,7 @@ def register_student(data):
while True: while True:
Email = input("Enter the university email (@student.uclouvain.be): ") Email = input("Enter the university email (@student.uclouvain.be): ")
if email_pattern.match(Email): if email_pattern.match(Email):
print("The email is valid.") print(f"The email is valid : {Email}")
break # Exit the loop if the email is valid break # Exit the loop if the email is valid
else: else:
print("The email is not valid. Make sure to follow the requested format.") print("The email is not valid. Make sure to follow the requested format.")
...@@ -85,7 +101,7 @@ def register_student(data): ...@@ -85,7 +101,7 @@ def register_student(data):
while True: while True:
Gender = input("What is your gender? (For Male enter M, for Female enter F, and for another type enter O): ") 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): if gender_pattern.match(Gender):
print("The gender is valid.") print(f"The gender is valid : {Gender}")
break # Exit the loop if the gender is valid break # Exit the loop if the gender is valid
else: else:
print("The gender is not valid. Make sure to follow the requested format.") print("The gender is not valid. Make sure to follow the requested format.")
...@@ -93,7 +109,7 @@ def register_student(data): ...@@ -93,7 +109,7 @@ def register_student(data):
while True: while True:
Academic_year = input("What is your academic year? (BAC1/BAC2/BAC3/MA1/MA2): ") Academic_year = input("What is your academic year? (BAC1/BAC2/BAC3/MA1/MA2): ")
if academic_year_pattern.match(Academic_year): if academic_year_pattern.match(Academic_year):
print("The academic year is valid.") print(f"The academic year is valid : {Academic_year}")
break # Exit the loop if the academic year is valid break # Exit the loop if the academic year is valid
else: else:
print("The academic year is not valid. Make sure to follow the requested format.") print("The academic year is not valid. Make sure to follow the requested format.")
...@@ -143,15 +159,15 @@ def register_student(data): ...@@ -143,15 +159,15 @@ def register_student(data):
else: else:
print("The campus choice is not valid. Make sure to follow the requested format.") print("The campus choice is not valid. Make sure to follow the requested format.")
register(data, Name, Surname, Date_of_birth, Place_of_birth, Address, Telephone, Email, Gender, Academic_year, Courses_and_grade, Campus) register(data, Firstname, Lastname, Date_of_birth, Place_of_birth, Address, Telephone, Email, Gender, Academic_year, Courses_and_grade, Campus)
def register(data, name, surname, date_of_birth, place_of_birth, address, telephone, email, gender, academic_year, courses_and_grade, campus): def register(data, firstname, lastname, date_of_birth, place_of_birth, address, telephone, email, gender, academic_year, courses_and_grade, campus):
matricule = generate_matricule(name, surname, date_of_birth) matricule = generate_matricule(firstname, lastname, date_of_birth)
student = { student = {
"Name": name, "Name": firstname,
"Surname": surname, "Surname": lastname,
"Date of Birth": date_of_birth, "Date of Birth": date_of_birth,
"Place of Birth": place_of_birth, "Place of Birth": place_of_birth,
"Address": address, "Address": address,
...@@ -173,10 +189,10 @@ def register(data, name, surname, date_of_birth, place_of_birth, address, teleph ...@@ -173,10 +189,10 @@ def register(data, name, surname, date_of_birth, place_of_birth, address, teleph
return return
def generate_matricule(name, surname, date_of_birth): def generate_matricule(firstname, lastname, date_of_birth):
consonants_name = ''.join([c for c in name if c.lower() not in 'aeiouy'])[:3] consonants_name = ''.join([c for c in firstname if c.lower() not in 'aeiouy'])[:3]
consonants_surname = ''.join([c for c in surname if c.lower() not in 'aeiouy'])[:2] consonants_surname = ''.join([c for c in lastname if c.lower() not in 'aeiouy'])[:2]
last_consonant_surname = ''.join([c for c in surname if c.lower() not in 'aeiouy']).lower()[-1] # not sure if it's the consonant of the first name or the last name last_consonant_surname = ''.join([c for c in lastname if c.lower() not in 'aeiouy']).lower()[-1] # not sure if it's the consonant of the first name or the last name
birth_year_last_two_digits = str(date_of_birth)[-2:] birth_year_last_two_digits = str(date_of_birth)[-2:]
random_integer = random.randint(0, 10) random_integer = random.randint(0, 10)
matricule_e = f"{consonants_name}{consonants_surname}{last_consonant_surname}{birth_year_last_two_digits}{random_integer}" matricule_e = f"{consonants_name}{consonants_surname}{last_consonant_surname}{birth_year_last_two_digits}{random_integer}"
...@@ -184,7 +200,7 @@ def generate_matricule(name, surname, date_of_birth): ...@@ -184,7 +200,7 @@ def generate_matricule(name, surname, date_of_birth):
return matricule_e return matricule_e
# MODIFYING THE DATA OF A STUDENT
def modify(data): def modify(data):
while True: while True:
matricule_to_modify = input("Enter the matricule of the student you want to modify (or 'q' to quit): ") matricule_to_modify = input("Enter the matricule of the student you want to modify (or 'q' to quit): ")
...@@ -192,146 +208,165 @@ def modify(data): ...@@ -192,146 +208,165 @@ def modify(data):
print("Operation canceled.") print("Operation canceled.")
break break
student_index = data[data['Matricule'] == matricule_to_modify.lower()].index.tolist() student_row = data[data['Matricule'] == matricule_to_modify.lower()]
if not student_index: if student_row.empty:
print("No student found with the specified matricule.") print("No student found with the specified matricule.")
return return
student_index = student_index[0] print("\nDetails of the student before modification:")
print(f"\nModifying the student with matricule {matricule_to_modify}:\n") print(student_row[['Matricule', 'Firstname', 'Lastname']])
print("1. Name")
print("2. Surname") confirmation = input("Do you really want to modify this student? (YES/NO) ").upper()
print("3. Date of Birth") if confirmation == "YES":
print("4. Place of Birth") student_index = student_row.index[0]
print("5. Address")
print("6. Telephone") print(f"\nModifying the student with matricule {matricule_to_modify}:\n")
print("7. Email") print("1. Firstname")
print("8. Sex (M | F | O)") print("2. Lastname")
print("9. Academic Year") print("3. Date of Birth")
print("10. Curriculum") print("4. Place of Birth")
print("11. Courses already passed and their grade") print("5. Address")
print("12. Campus") print("6. Telephone")
print("7. Email")
field_to_modify = int(input("Enter the number of the field you want to modify: ")) print("8. Sex (M | F | O)")
print("9. Academic Year")
field_name_to_modify = field_mapping.get(field_to_modify, None) print("10. Curriculum")
print(f"You are modifying the field: {field_name_to_modify}") print("11. Courses already passed and their grade")
print("12. Campus")
if field_to_modify == 1: # If the field to modify is the name (Name)
while True: field_to_modify = int(input("Enter the number of the field you want to modify: "))
name = input("What is the name you want to modify? ")
if name_pattern.match(name): field_name_to_modify = field_mapping.get(field_to_modify, None)
print("The name is valid.") print(f"You are modifying the field: {field_name_to_modify}")
data.at[student_index, 'Name'] = name
break # Exit the loop if the name is valid if field_to_modify == 1: # If the field to modify is the name (Name)
else: while True:
print("The name is not valid. Make sure to follow the specified format.") firstname = input("What is the name you want to modify? ")
elif field_to_modify == 2: if name_pattern.match(firstname):
while True: # Ask the user for the surname print(f"The firstname is valid : {firstname}")
surname = input("What is the surname? ") if field_to_modify in (1, 2, 3):
if name_pattern.match(surname): matricule = generate_matricule(firstname, data.at[student_index, 'Lastname'], data.at[student_index, 'Date of Birth'])
print("The surname is valid.") data.at[student_index, 'Firstame'] = firstname
data.at[student_index, 'Surname'] = surname break # Exit the loop if the name is valid
break # Exit the loop if the surname is valid else:
else: print("The name is not valid. Make sure to follow the specified format.")
print("The surname is not valid. Make sure to follow the specified format.") elif field_to_modify == 2:
elif field_to_modify == 3: while True: # Ask the user for the surname
while True: lastname = input("What is the surname? ")
date_of_birth = input("Please enter a date in the format dd/mm/yyyy: ") if name_pattern.match(lastname):
if date_pattern.match(date_of_birth): print(f"The lastname is valid : {lastname}")
print("The date is valid.") if field_to_modify in (1, 2, 3):
data.at[student_index, 'Date of Birth'] = date_of_birth matricule = generate_matricule(data.at[student_index, 'Firstname'], lastname, data.at[student_index, 'Date of Birth'])
break # Exit the loop if the date is valid data.at[student_index, 'Lastname'] = lastname
else: break # Exit the loop if the surname is valid
print("The date is not valid. Make sure to follow the format dd/mm/yyyy.") else:
elif field_to_modify == 4: print("The surname is not valid. Make sure to follow the specified format.")
while True: elif field_to_modify == 3:
place_of_birth = input("What is the city of birth? ") while True:
if place_of_birth_pattern.match(place_of_birth): date_of_birth = input("Please enter a date in the format dd/mm/yyyy: ")
print("The city of birth is valid.") if date_pattern.match(date_of_birth):
data.at[student_index, 'Place of Birth'] = place_of_birth print(f"The date is valid : {date_of_birth}")
break # Exit the loop if the city of birth is valid if field_to_modify in (1, 2, 3):
else: matricule = generate_matricule(data.at[student_index, 'Firstname'], data.at[student_index, 'Lastname'], date_of_birth)
print("The city of birth is not valid. Make sure to use only letters and spaces.") data.at[student_index, 'Date of Birth'] = date_of_birth
elif field_to_modify == 5: break # Exit the loop if the date is valid
while True: else:
address = input("Please enter an address in the format 'street number, city': ") print("The date is not valid. Make sure to follow the format dd/mm/yyyy.")
if address_pattern.match(address): elif field_to_modify == 4:
print("The address is valid.") while True:
data.at[student_index, 'Address'] = address place_of_birth = input("What is the city of birth? ")
break # Exit the loop if the address is valid if place_of_birth_pattern.match(place_of_birth):
else: print(f"The city of birth is valid : {place_of_birth}")
print("The address is not valid. Make sure to follow the format 'street number, city'.") data.at[student_index, 'Place of Birth'] = place_of_birth
elif field_to_modify == 6: break # Exit the loop if the city of birth is valid
while True: else:
telephone = input("What is the telephone number? (in the format 000/00.00.00) ") print("The city of birth is not valid. Make sure to use only letters and spaces.")
if telephone_pattern.match(telephone): elif field_to_modify == 5:
print("The telephone number is valid.") while True:
data.at[student_index, 'Telephone'] = telephone address = input("Please enter an address in the format 'street number, city': ")
break # Exit the loop if the telephone number is valid if address_pattern.match(address):
else: print(f"The address is valid : {address}")
print("The telephone number is not valid. Make sure to follow the requested format.") data.at[student_index, 'Address'] = address
elif field_to_modify == 7: break # Exit the loop if the address is valid
while True: else:
email = input("Enter the university email (@student.uclouvain.be): ") print("The address is not valid. Make sure to follow the format 'street number, city'.")
if email_pattern.match(email): elif field_to_modify == 6:
print("The email is valid.") while True:
data.at[student_index, 'Email'] = email telephone = input("What is the telephone number? (in the format 000/00.00.00) ")
break # Exit the loop if the email is valid if telephone_pattern.match(telephone):
else: print(f"The telephone number is valid : {telephone}")
print("The email is not valid. Make sure to follow the requested format.") data.at[student_index, 'Telephone'] = telephone
elif field_to_modify == 8: break # Exit the loop if the telephone number is valid
while True: else:
gender = input("What is your gender? (For Male enter M, for Female enter F, and for other type enter O): ") print("The telephone number is not valid. Make sure to follow the requested format.")
if gender_pattern.match(gender): elif field_to_modify == 7:
print("The gender is valid.") while True:
data.at[student_index, 'Gender'] = gender email = input("Enter the university email (@student.uclouvain.be): ")
break # Exit the loop if the gender is valid if email_pattern.match(email):
else: print(f"The email is valid : {email}")
print("The gender is not valid. Make sure to follow the requested format.") data.at[student_index, 'Email'] = email
elif field_to_modify == 9: break # Exit the loop if the email is valid
while True: else:
academic_year = input("What is your academic year? (BAC1/BAC2/BAC3/MA1/MA2): ") print("The email is not valid. Make sure to follow the requested format.")
if academic_year_pattern.match(academic_year): elif field_to_modify == 8:
print("The academic year is valid.") while True:
data.at[student_index, 'Academic Year'] = academic_year gender = input("What is your gender? (For Male enter M, for Female enter F, and for other type enter O): ")
break # Exit the loop if the academic year is valid if gender_pattern.match(gender):
else: print(f"The gender is valid : {gender}")
print("The academic year is not valid. Make sure to follow the requested format.") data.at[student_index, 'Gender'] = gender
elif field_to_modify == 11: # Courses and grades break # Exit the loop if the gender is valid
print("Courses already passed and their grade:\n") else:
for course, grade in data.iloc[student_index].items(): print("The gender is not valid. Make sure to follow the requested format.")
if course not in field_mapping.values(): elif field_to_modify == 9:
print(f"{course}: {grade}") while True:
academic_year = input("What is your academic year? (BAC1/BAC2/BAC3/MA1/MA2): ")
while True: if academic_year_pattern.match(academic_year):
course_to_modify = input("Enter the course you want to modify: ") print(f"The academic year is valid : {academic_year}")
if course_to_modify in data.columns: # The course has been found, you can continue with the rest of your code data.at[student_index, 'Academic Year'] = academic_year
print("The specified course has been found.") break # Exit the loop if the academic year is valid
break # Exit the loop since the course has been found else:
else: print("The academic year is not valid. Make sure to follow the requested format.")
print("The specified course has not been found. Please select a new one.") elif field_to_modify == 11: # Courses and grades
print("Courses already passed and their grade:\n")
new_grade = input(f"Enter the new grade for {course_to_modify}: ") for course, grade in data.iloc[student_index].items():
while not new_grade.isdigit() or int(new_grade) not in range(0, 21): if course not in field_mapping.values():
print("The grade must be an integer between 0 and 20.") print(f"{course}: {grade}")
while True:
course_to_modify = input("Enter the course you want to modify: ")
if course_to_modify in data.columns: # The course has been found, you can continue with the rest of your code
print("The specified course has been found.")
break # Exit the loop since the course has been found
else:
print("The specified course has not been found. Please select a new one.")
new_grade = input(f"Enter the new grade for {course_to_modify}: ") new_grade = input(f"Enter the new grade for {course_to_modify}: ")
while not new_grade.isdigit() or int(new_grade) not in range(0, 21):
print("The grade must be an integer between 0 and 20.")
new_grade = input(f"Enter the new grade for {course_to_modify}: ")
# Update the grade
data.at[student_index, course_to_modify] = int(new_grade)
elif field_to_modify == 12:
while True:
campus = input("Enter 'Louvain-la-Neuve' or 'Mons' depending on the campus: ")
if campus_pattern.match(campus):
print(f"The campus choice is valid : {campus}")
data.at[student_index, 'Campus'] = campus
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.")
# Update the grade
data.at[student_index, course_to_modify] = int(new_grade)
elif field_to_modify == 12:
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.")
data.at[student_index, 'Campus'] = campus
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.")
else: else:
new_value = input(f"Enter the new value for the selected field: ") print("Modification canceled.")
data.at[student_index, field_mapping[field_to_modify]] = new_value break # Exit the loop if modification is canceled
data.at[student_index, 'Matricule'] = matricule # Update the Matricule column with the new matricule
print("be careful because of a modification the registration number has changed :")
print(f"the new matricule is : {matricule}")
# 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)
...@@ -353,6 +388,7 @@ field_mapping = { ...@@ -353,6 +388,7 @@ field_mapping = {
} }
# 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: ") 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() student_index = data[data['Matricule'] == matricule_to_delete.lower()].index.tolist()
...@@ -380,104 +416,96 @@ def delete(data): ...@@ -380,104 +416,96 @@ def delete(data):
print("Deletion canceled.") print("Deletion canceled.")
# FIND # FIND
def find_student(data): def find_student(data):
search_criteria = input("Enter the search criteria (Name/Surname/Matricule): ").capitalize()
if search_criteria == "Name": print("Below the search criteria : ")
name_search = input("Enter the name of the student: ") print("1. By his/her lastname")
results = data[data['Name'].str.contains(name_search, case=False, na=False)] print("2. By his/her firstname")
elif search_criteria == "Surname": print("3. By his/her matricule")
surname_search = input("Enter the surname of the student: ")
results = data[data['Surname'].str.contains(surname_search, case=False, na=False)] search_criteria = input("Enter the number of what you want to do: ")
elif search_criteria == "Matricule":
matricule_search = input("Enter the matricule of the student: ") if search_criteria == "1":
results = data[data['Matricule'].str.contains(matricule_search, case=False, na=False)] surname_search = input("Enter the lastname of the student: ")
results = data[data['Lastname'].str.contains(surname_search, case=False, na=False)]
elif search_criteria == "2":
name_search = input("Enter the firstname of the student: ")
results = data[data['Firstname'].str.contains(name_search, case=False, na=False)]
elif search_criteria == "3":
matricule_search = input("Enter the matricule of the student: ")
results = data[data['Matricule'].str.contains(matricule_search, case=False, na=False)]
else: else:
print("Invalid search criteria.") print("Invalid search criteria.")
return return
if results.empty: if results.empty:
print("No student found with the specified criteria.") print("No student found with the specified criteria.")
else: else:
print("Student(s) found:") print("Student(s) found:")
for index, row in results.iterrows(): for index, row in results.iterrows():
print(f"Name: {row['Name']}, Surname: {row['Surname']}, Matricule: {row['Matricule']}") print(f"Firstname: {row['Firstname']}, Lastname: {row['Lastname']}, Matricule: {row['Matricule']}")
# SHOW # SHOW
def filter_students(data): def filter_students(data):
if data.empty: if data.empty:
print("The list of students is empty.") print("The list of students is empty.")
else: else:
print("\nList of students:") table_data = []
for index, row in data.iterrows(): for index, row in data.iterrows():
print(f"Name: {row['Name']}, Surname: {row['Surname']}, Matricule: {row['Matricule']}") table_data.append([row['Firstname'], row['Lastname'], row['Matricule']])
headers = ["Firstname", "Lastname", "Matricule"]
print(tabulate(table_data, headers=headers, tablefmt="pretty"))
export_choice = input("Do you want to export the list to an Excel file? (yes/no): ").lower()
if export_choice == "yes":
export_to_excel(data)
read_choice = input("Do you want to read the exported list from an Excel file? (yes/no): ").lower()
if read_choice == "yes":
read_exported_list()
# Using the function export_filtered_student_list_to_excel def export_to_excel(data):
# export_filtered_student_list_to_excel(data, 'filtered_student_list.xlsx') excel_filename = input("Enter the name of the Excel file (without extension): ")
excel_filename += ".xlsx"
""" try:
print('To filter students, enter SCREEN') data.to_excel(excel_filename, index=False)
print('To export the list to an Excel document, enter EXPORT') print(f"List successfully exported to {excel_filename}.")
print('To read the list, enter READ') except Exception as e:
choice = input("") print(f"An error occurred during export: {e}")
if choice == "SCREEN":
filter_students(data)
elif choice == "EXPORT":
export(data)
elif choice == "READ":
read(data)
"""
def filter_students(data):
show_list = input("Do you want to see the list of students? YES/NO")
if show_list == "YES":
for index, row in data.iterrows():
print(f"Name: {row['Name']}, Surname: {row['Surname']}, Matricule: {row['Matricule']}")
export_choice = input("Do you want to export the list? YES/NO")
if export_choice == "YES":
try:
data.to_excel(excel_file_path, index=False)
print(f"The list of students has been successfully exported to {excel_file_path}.")
except Exception as e:
print(f"Error exporting to Excel: {e}")
read_choice = input("Do you want to read the exported list? YES/NO")
if read_choice == "YES":
try:
os.system(f"start excel {excel_file_path}")
except Exception as e:
print(f"Error opening the Excel file: {e}")
return open_excel(excel_file_path)
return def read_exported_list():
return excel_filename = input("Enter the name of the Excel file to read (include .xlsx extension): ")
def open_excel(excel_file_path):
try: try:
os.system(f"start excel {excel_file_path}") exported_data = pd.read_excel(excel_filename)
print("\nExported List:")
print(exported_data)
print("\nExported list successfully read from Excel.")
except FileNotFoundError:
print(f"File not found: {excel_filename}")
except Exception as e: except Exception as e:
print(f"Error opening the Excel file: {e}") print(f"An error occurred during reading: {e}")
# SORTING
# SORTING
def sort(data): def sort(data):
print('1. Sort in ascending alphabetical order') print('1. Sort in ascending alphabetical order')
print('2. Sort in descending alphabetical order') print('2. Sort in descending alphabetical order')
print('3. Sort by date of birth') print('3. Sort by date of birth')
print('4. Sort by age') print('4. Sort by age')
print('5. Sort by matricule') print('5. Sort by matricule')
print('6. Sort by academic year') print('6. Sort by academic year')
print('7. Get all people who passed a course') print('7. Get all people who passed a course')
print('8. Get all people who failed a course') print('8. Get all people who failed a course')
print('9. Get all Bachelor students') print('9. Get all Bachelor students')
print('10. Get all Master students') print('10. Get all Master students')
sorting_choice = input("") sorting_choice = input("Enter the number of what you want to do: ")
if sorting_choice == "1": if sorting_choice == "1":
sort_ascending(data) sort_ascending(data)
elif sorting_choice == "2": elif sorting_choice == "2":
...@@ -501,24 +529,107 @@ def sort(data): ...@@ -501,24 +529,107 @@ def sort(data):
return return
def sort_ascending(data): def sort_ascending(data):
if 'Name' not in data.columns: sorted_data = data.sort_values(by='Firstname', ascending=True)
print("The 'Name' column does not exist in the DataFrame.") see_the_data(sorted_data, columns_to_show=['Firstname', 'Lastname', 'Matricule'])
return export_option(sorted_data)
def sort_descending(data):
sorted_data = data.sort_values(by='Firstname', ascending=False)
see_the_data(sorted_data, columns_to_show=['Firstname', 'Lastname', 'Matricule'])
export_option(sorted_data)
def sort_by_date(data):
sorted_data = data.sort_values(by='Date of Birth')
see_the_data(sorted_data, columns_to_show=['Firstname', 'Lastname', 'Date of Birth'])
export_option(sorted_data)
def sort_by_age(data):
data['Age'] = (pd.to_datetime('today') - pd.to_datetime(data['Date of Birth'])).astype('<m8[Y]')
sorted_data = data.sort_values(by='Age', ascending=True)
see_the_data(sorted_data, columns_to_show=['Firstname', 'Lastname', 'Age'])
export_option(sorted_data)
def sort_by_matricule(data):
sorted_data = data.sort_values(by='Matricule', ascending=True)
see_the_data(sorted_data, columns_to_show=['Firstname', 'Lastname', 'Matricule'])
export_option(sorted_data)
def sort_by_academic_year(data):
sorted_data = data.sort_values(by='AcademicYear', ascending=True)
see_the_data(sorted_data, columns_to_show=['Firstname', 'Lastname', 'AcademicYear'])
export_option(sorted_data)
# attention il faut pouvoir matcher ceci avec les résultats obtenus
def sort_passed(data):
passed_data = data[data['PassedCourse'] == True]
see_the_data(passed_data, columns_to_show=['Firstname', 'Lastname', 'PassedCourse'])
export_option(passed_data)
def sort_failed(data):
failed_data = data[data['PassedCourse'] == False]
see_the_data(failed_data, columns_to_show=['Firstname', 'Lastname', 'PassedCourse'])
export_option(failed_data)
def sort_bachelor(data):
bachelor_data = data[data['Academic Year'] == 'BAC1' or 'BAC2' or 'BAC3']
see_the_data(bachelor_data, columns_to_show=['Firstname', 'Lastname', 'Academic Year'])
export_option(bachelor_data)
def sort_master(data):
master_data = data[data['Academic Year'] == 'MA1' or 'MA2']
see_the_data(master_data, columns_to_show=['Firstname', 'Lastname', 'Academic Year'])
export_option(master_data)
# export the data into an excel
def export_option(data):
export = input("Do you want to export in a file? (YES/NO) ").upper()
if export == "YES":
filename = input("Enter the filename: ")
filename = filename + '.xlsx'
export_data_to_excel(data, filename)
def export_data_to_excel(data, filename):
data.to_excel(filename, index=False)
print(f"\nData exported to {filename}")
# see the data needed
def see_the_data(data, columns_to_show=None):
if columns_to_show is None:
columns_to_show = data.columns
data_to_show = data[columns_to_show]
table = tabulate(data_to_show, headers='keys', tablefmt='grid')
print(table)
# Sort the DataFrame by the 'Name' column
sorted_data = data.sort_values(by='Name', ascending=True)
# Display the sorted list
print("\nList of students sorted in alphabetical order (ascending):")
for index, row in sorted_data.iterrows():
print(f"Name: {row['Name']}, Surname: {row['Surname']}, Matricule: {row['Matricule']}")
# Example usage # Example usage
# Replace 'data' with the name of your DataFrame # Replace 'data' with the name of your DataFrame
# STATS # STATS
def statistics(data): def statistics_analysis(data):
print('1. Get basic statistics') print('1. Get basic statistics')
print('2. Get all student grades') print('2. Get all student grades')
print('3. Get all grades for a course') print('3. Get all grades for a course')
...@@ -649,7 +760,7 @@ def export_stats(data): ...@@ -649,7 +760,7 @@ def export_stats(data):
# Action # Action
def action(): def action():
print("What do you want to do?\n Below, you will find what is possible followed by the commands to type.\n") print("What do you want to do?\nBelow, you will find what is possible followed by the commands to type.\n")
print("1. Register a student") print("1. Register a student")
print("2. Modify one or more fields") print("2. Modify one or more fields")
print("3. Delete a student") print("3. Delete a student")
...@@ -678,11 +789,11 @@ def action(): ...@@ -678,11 +789,11 @@ def action():
elif command == "4": elif command == "4":
find_student(data) find_student(data)
elif command == "5": elif command == "5":
show(data) filter_students(data)
elif command == "6": elif command == "6":
sort(data) sort(data)
elif command == "7": elif command == "7":
statistics(data) statistics_analysis(data)
elif command == "8": elif command == "8":
return False return False
......
...@@ -184,7 +184,7 @@ for each in range(number_of_students): # générer des données ...@@ -184,7 +184,7 @@ for each in range(number_of_students): # générer des données
grades[courses] = random.randint(0, 20) grades[courses] = random.randint(0, 20)
data_generated.append({"Name": last_name, "Surname": first_name, "Academic Year" : academic_year, "Place of Birth" : city_of_birth , "Telephone": phone, "Address": adress_of_student, "Genre" : gender_of_student, "Email" : email_formated, "Campus" : campus, "Date of Birth" : complete_date_of_birth, "Matricule" : matricule, **grades}) data_generated.append({"Firstname": last_name, "Lastname": first_name, "Academic Year" : academic_year, "Place of Birth" : city_of_birth , "Telephone": phone, "Address": adress_of_student, "Genre" : gender_of_student, "Email" : email_formated, "Campus" : campus, "Date of Birth" : complete_date_of_birth, "Matricule" : matricule, **grades})
# génération de données qui ne peuvent pas se ressembler # génération de données qui ne peuvent pas se ressembler
......
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