diff --git a/Adrien Payen_statistics.xlsx b/Adrien Payen_statistics.xlsx deleted file mode 100644 index a1f752b154bcd6908d51748127d31b5f3f2a7121..0000000000000000000000000000000000000000 Binary files a/Adrien Payen_statistics.xlsx and /dev/null differ diff --git a/Aubree Coleman_statistics.xlsx b/Aubree Coleman_statistics.xlsx deleted file mode 100644 index 3fbcb6617a7cbfae85a41cbe295aa31ab8e7bc8e..0000000000000000000000000000000000000000 Binary files a/Aubree Coleman_statistics.xlsx and /dev/null differ diff --git a/Cooper Lopez_statistics.xlsx b/Cooper Lopez_statistics.xlsx deleted file mode 100644 index 720b644c99765c7763b608ac59a0cdbe19c4010b..0000000000000000000000000000000000000000 Binary files a/Cooper Lopez_statistics.xlsx and /dev/null differ diff --git a/overall_statistics.xlsx b/overall_statistics.xlsx deleted file mode 100644 index a1f752b154bcd6908d51748127d31b5f3f2a7121..0000000000000000000000000000000000000000 Binary files a/overall_statistics.xlsx and /dev/null differ diff --git a/projet_personnel/algorithme_gestion_etudiants.py b/projet_personnel/algorithme_gestion_etudiants.py index 693394b5111e4d11ab2d75e202dadf5ec194970f..d56573970741a4f89a4e4b40b9fec0386fce9f23 100644 --- a/projet_personnel/algorithme_gestion_etudiants.py +++ b/projet_personnel/algorithme_gestion_etudiants.py @@ -747,15 +747,11 @@ def see_the_data(data, columns_to_show=None): # STATS def statistics_analysis(data): - print_menu([ - "Get basic statistics of a student", - "Get all grades of a student", - "Get all grades of a course", - ]) - + print_menu(["Get basic statistics of a student", "Get all grades of a student", "Get all grades of a course"]) + stats_choice = get_valid_input("Enter the number of what you want to do: ", 1, 3) - if stats_choice == 1 : + if stats_choice == 1: results = search_and_display_stats(data, "Statistics") elif stats_choice == 2: results = search_and_display_stats(data, "Grades") @@ -797,13 +793,15 @@ def search_and_display_stats(data, stats_type): if not results.empty: if stats_type == "Statistics": - display_statistics(results) + display_statistics(results, data) elif stats_type == "Grades": - display_student_grades(results) + display_student_grades(results, data) else: print(f"No students found with the specified {field_name}.") -def display_statistics(results): + +# STATISTICAL_STUDENT +def display_statistics(results, data): numeric_columns = results.select_dtypes(include=['number']).columns for index, row in results.iterrows(): @@ -812,11 +810,39 @@ def display_statistics(results): if student_grades: print_student_statistics(student_name, student_grades) - else: - print(f"\nNo grades found for student {student_name}.") + + # Move the export_statistics call outside the loop + export_statistics(results, data, numeric_columns) + + +def export_statistics(results, data, numeric_columns): export_choice = input("Do you want to export these statistics? (YES/NO): ").upper() if export_choice == 'YES': - export_stats(results) + file_name = input("Enter the Excel file name (without extension): ") + '.xlsx' + export_path = file_name + export_df = calculate_student_stats(results, numeric_columns) + export_df.to_excel(export_path, index=False) + print(f"Statistics exported to {export_path}.") + + +def calculate_student_stats(results, numeric_columns): + student_grades = pd.Series(results[numeric_columns].stack().dropna()) + + # Check if the student_grades Series is empty + if student_grades.empty: + # If no grades are found, return an empty DataFrame + return pd.DataFrame(columns=["Metric", "Value"]) + + student_stats = { + "Lowest grade": min(student_grades), + "Highest grade": max(student_grades), + "Average grade": statistics.mean(student_grades), + "Median grade": statistics.median(student_grades), + "Standard deviation of grades": statistics.stdev(student_grades) + } + + return pd.DataFrame(list(student_stats.items()), columns=["Metric", "Value"]) + def print_student_statistics(student_name, student_grades): lowest_grade = min(student_grades) @@ -836,16 +862,31 @@ def print_student_statistics(student_name, student_grades): print(f"\nStatistics for student {student_name}:") print(tabulate(table, headers=["Metric", "Value"], tablefmt="pretty")) -def display_student_grades(results): +# STUDENT_GRADES +def display_student_grades(results, data): for index, row in results.iterrows(): student_name = f"{row['Firstname']} {row['Lastname']}" print(f"\nGrades for student {student_name}:") table = [[column, grade] for column, grade in row.items() if pd.notna(grade) and column not in ['Firstname', 'Lastname', 'Academic Year', 'Curriculum', 'Place of Birth', 'Telephone', 'Address', 'Gender', 'Email', 'Campus', 'Date of Birth', 'Matricule']] print(tabulate(table, headers=["Course", "Grade"], tablefmt="pretty")) + export_student_grades(results, data) + +def export_student_grades(results, data): export_choice = input("Do you want to export these statistics? (YES/NO): ").upper() if export_choice == 'YES': - export_stats(results) + file_name = input("Enter the Excel file name (without extension): ") + '.xlsx' + export_path = file_name + columns_to_remove = ['Firstname', 'Lastname', 'Academic Year', 'Curriculum', 'Place of Birth', 'Telephone', 'Address', 'Gender', 'Email', 'Campus', 'Date of Birth', 'Matricule'] + export_df = results.drop(columns=columns_to_remove) + + # Melt the DataFrame to have data in columns with courses and grades + export_df_melted = pd.melt(export_df, id_vars=[], value_vars=export_df.columns, var_name='Course', value_name='Grade') + + export_df_melted.to_excel(export_path, index=False) + print(f"Data exported to {export_path}.") + +# COURSE_GRADES def course_grades(data): print("Here is the list of courses:") for course in data.columns[13:]: @@ -857,53 +898,32 @@ def course_grades(data): students_in_course = data[data[course_name].notnull()] if not students_in_course.empty: - display_course_grades(students_in_course, course_name) + display_course_grades(students_in_course, course_name, data) + export_course_grades(students_in_course, course_name) else: print(f"No students participated in the course {course_name}.") else: print(f"The specified course ({course_name}) was not found.") - - export_choice = input("Do you want to export these statistics? (YES/NO): ").upper() - if export_choice == 'YES': - export_stats(students_in_course) - - return students_in_course + return -def display_course_grades(students_in_course, course_name): +def display_course_grades(students_in_course, course_name, data): print(f"\nGrades of students for the course {course_name}:") - table = [ - ["Matricule", "Grade"], - *[[row['Matricule'], row[course_name]] for _, row in students_in_course.iterrows() if not pd.isnull(row[course_name])] + table = [["Firstname", "Lastname", "Matricule", "Grade"], + *[[row['Firstname'], row['Lastname'], row['Matricule'], row[course_name]] for _, row in students_in_course.iterrows() if not pd.isnull(row[course_name])] ] print(tabulate(table, headers="firstrow", tablefmt="pretty")) -def export_stats(data): - # Ensure numeric columns only - numeric_columns = data.select_dtypes(include=['number']).columns - - # Calculate and save statistics for each student - for index, row in data.iterrows(): - student_name = f"{row['Firstname']} {row['Lastname']}" - student_stats = calculate_student_stats(row, numeric_columns) - student_stats.to_excel(f"{student_name}_statistics.xlsx", index=False) - - print("Statistics exported successfully.") - - +def export_course_grades(students_in_course, course_name): + export_choice = input("Do you want to export these statistics? (YES/NO): ").upper() + if export_choice == 'YES': + file_name = input("Enter the Excel file name (without extension): ") + '.xlsx' + export_path = file_name + export_df = students_in_course[['Firstname', 'Lastname','Matricule', course_name]] + export_df.to_excel(export_path, index=False) + print(f"Data exported to {export_path}.") -def calculate_student_stats(row, numeric_columns): - student_grades = [row[column] for column in numeric_columns if not pd.isnull(row[column])] - student_stats = { - "Lowest grade": min(student_grades), - "Highest grade": max(student_grades), - "Average grade": statistics.mean(student_grades), - "Median grade": statistics.median(student_grades), - "Standard deviation of grades": statistics.stdev(student_grades) - } - - return pd.DataFrame(list(student_stats.items()), columns=["Metric", "Value"]) # Example of usage diff --git a/~$adrien.xlsx b/~$adrien.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..d10daf560a7f8247050905285b3e618c244966d6 Binary files /dev/null and b/~$adrien.xlsx differ