Module result_analysis

Expand source code
import os
#Importing os module that will be used to configure paths and create directoriees
import numpy as np 
#Importing numpy for doing statistical operations
import pandas as pd
#Importing pandas for preparing data and creating DataFrames for analysis
import matplotlib.pyplot as plt
#Importing matplotlib.pyplot for plotting graphs
def print_menu():
    """
    Prints the main menu where the user can make options
    """
    print("******************Main Menu******************")
    print("1. Read CSV file of grades")
    print("2. Generate Student report file")
    print("3. Generate Student report charts")
    print("4. Generate Class report file")
    print("5. Generate class report charts")
    print("6. Quit")
    print()

def calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project):
    """
    Calculates the percentage score from exam_mean, labs_mean, quizes_mean, readings_mean, project

    params: float exams_float, float labs_mean, float quizes_mean, float quizes_mean, float readings_mean, float project.

    return: float score
    """
    exams_per = (exams_mean * 45) / 100
    labs_per = (labs_mean * 25) / 100
    quizes_per = (quizes_mean * 10) / 100
    readings_per =  (readings_mean * 10) / 100
    project_per =  (project * 10) / 100

    total = exams_per + labs_per + quizes_per + readings_per + project_per

    return round(total, 1)

def calculate_grade(score):
    """
    calculates the letter grade for a score passed to it as an arguement.
    
    params: float score

    return String grade
    """
    if score >= 90:
        grade = 'A'
    elif score >= 80:
        grade = 'B'
    elif score >= 70:
        grade = 'C'
    elif score >= 60:
        grade = 'D'
    else:
        grade = 'F'
    return grade


def get_user_input():
    """
    Gets input from the user, this input is what is used as menu option

    return: String option
    """
    pass_ = False
    option = input("Enter menu choice: ")

    return option

def save_graph(y_pos, data, ylabel, xlabel, title, labels, file_path):
    """
    Plots a bar graph and saves it as a png formated image on the passed file path

    params: Array y_pos, Array data, String, y_label, String xlabel, String title, Array labels, String file_path
    """
    plt.bar(y_pos, data, align="center", alpha=0.5)
    plt.xticks(y_pos, labels)
    plt.ylabel(ylabel)
    plt.xlabel(str(xlabel))
    plt.title(title)
    figure1 = plt.gcf()

    plt.show()
    #Create Folder if not available
    figure1.savefig(file_path)



def generate_student_report(df):
    """
    Reads data from a passed data frame asking for a user input for the Student UIN and searches the data frame for the vlue.
    Means for Labs, Exams, Activities, Quizes, Readings and Projects mean are calculated and written to a file which holds the Students UIN

    params: DataFrame df.
    """
    pass_ = False
    while not pass_:
        try:
            student_uin = int(input("Enter Student UIN: "))
            if len(str(student_uin)) != 10:
                print("Please enter correct Student UIN: \n")
            else:
                for index,data in df.iterrows():
                    if data['UIN'] == student_uin:
                        pass_=True
                        print("Data Found")
                        filename = str(data['UIN'])
                        #Calculate Exam Mean
                        exams = [data['exam 1'], data['exam 2'], data['exam 3']]
                        exams_mean = round(np.mean(exams), 1)
                        
                        #Labs Mean
                        labs = [data['lab 1'], data['lab 2'], data['lab 3'], data['lab 4'], data['lab 5'], data['lab 6']]
                        labs_mean = round(np.mean(labs), 1)
                        

                        #Quizes Mean
                        quizes = [data['quiz 1'], data['quiz 2'], data['quiz 3'], data['quiz 4'], data['quiz 5'], data['quiz 6']]
                        quizes_mean = round(np.mean(quizes), 1)
                        

                        #Reading Activities Mean
                        readings = [data['reading 1'], data['reading 2'], data['reading 3'], data['reading 4'], data['reading 5'], data['reading 6']]
                        readings_mean = round(np.mean(readings), 1)
                        
                        #project 
                        project = data['project']
                        #Score (%)
                        score = calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project)
                        grade = calculate_grade(score)
                        #Construct PATH to save
                        file_path = f"student_reports/{student_uin}.txt"
                        dir_path ="student_reports"
                        #Creating the directory if it does not exists
                        if not os.path.exists(dir_path):
                            os.makedirs(dir_path)
                        #Saving to file
                        with open(file_path, 'w') as f:
                            f.write(f"Exams mean: {exams_mean}\n")
                            f.write(f"Labs mean: {labs_mean}\n")
                            f.write(f"Quizzes mean: {quizes_mean}\n")
                            f.write(f"Reading activities mean: {readings_mean}\n")
                            f.write(f"Score: {score}\n")
                            f.write(f"Letter grade: {grade}\n")
                if pass_ == False:
                    print("No record found for the Student UIN, Please Retry!!")
        except:
            print("Enter Only numbers")

def generate_student_report_charts(df):
    """
    asks for user for Student UIN which they want to check for their reports, the function searches for the passed input in the DataFrame df, 
    and if a record is found it captures the grades data for the given student and calls the function which plots the bar graph passing the required 
    parameters to the function

    params: DataFrame df.
    """
    pass_ = False
    while not pass_:
        try:
            student_uin = int(input("Enter Student UIN: "))
            if len(str(student_uin)) != 10:
                print("Please enter correct Student UIN: \n")
            else:
                for index,data in df.iterrows():
                    if data['UIN'] == student_uin:
                        pass_=True
                        print("Data Found")

                        #Create the folder to hold plots - If It does not exist
                        dir_path = f"{student_uin}"
                        if not os.path.exists(dir_path):
                            os.makedirs(dir_path)

                        filename = str(data['UIN'])
                        #Exams data - Bar Plot
                        exam_labels = ('1', '2', '3')
                        exams = [data['exam 1'], data['exam 2'], data['exam 3']]
                        file_path = f"{dir_path}/exam_bar_graph.png"
                        y_pos_exam = np.arange(len(exam_labels))

                        #Plotting Graph - Exams
                        #Call the fuctions to save grapgh
                        save_graph(y_pos_exam, exams,'Score (%)',"Exam #", f"Exam Grades for {student_uin}", exam_labels, file_path)

                        #Labs Grapgh
                        lab_labels = ('1', '2', '3', '4', '5', '6')
                        labs = [data['lab 1'], data['lab 2'], data['lab 3'], data['lab 4'], data['lab 5'], data['lab 6']]
                        file_path = f"{dir_path}/lab_bar_graph.png"
                        y_pos_lab = np.arange(len(lab_labels))

                        #Save the graph
                        save_graph(y_pos_lab, labs, "Score (%)", "Lab #", f"Lab Grades for {student_uin}", lab_labels, file_path)
                        
                        #Quizes Graph
                        quiz_labels = ('1', '2', '3', '4', '5', '6')
                        quizes = [data['quiz 1'], data['quiz 2'], data['quiz 3'], data['quiz 4'], data['quiz 5'], data['quiz 6']]
                        file_path = f"{dir_path}/quiz_bar_graph.png"
                        y_pos_quiz = np.arange(len(quiz_labels))

                        #Save to Graph
                        save_graph(y_pos_quiz, quizes, "Score (%)", "Quiz #", f"Quiz Grades for {student_uin}", quiz_labels, file_path)
                
                        #Reading Activities Graph
                        reading_label = ('1', '2', '3', '4', '5', '6')
                        readings = [data['reading 1'], data['reading 2'], data['reading 3'], data['reading 4'], data['reading 5'], data['reading 6']]
                        file_path = f"{dir_path}/readings_bar_graph.png"
                        y_pos_reading = np.arange(len(reading_label))

                        #Save to Graph
                        save_graph(y_pos_reading, readings, "Score (%)", "Reading Activity #", f"Reading activity grades for {student_uin}", reading_label, file_path)
                if pass_ == False:
                    print("No record found for the Student UIN, Please Retry!!")
        except:
            print("Enter Only numbers")


def class_reports(df):
    """
    Generates reports for the class, class means for the labs, exams, readings, quizes and project then class mean score, maximum score,
    median score, minimum and standard deviation.

    params: DataFrame df.
    """
    scores = []
    file_path = "report.txt"
    student_count = 0
    for index,data in df.iterrows():
        filename = str(data['UIN'])
        #Calculate Exam Mean
        exams = [data['exam 1'], data['exam 2'], data['exam 3']]
        exams_mean = round(np.mean(exams), 1)
        
        #Labs Mean
        labs = [data['lab 1'], data['lab 2'], data['lab 3'], data['lab 4'], data['lab 5'], data['lab 6']]
        labs_mean = round(np.mean(labs), 1)
        
        #Quizes Mean
        quizes = [data['quiz 1'], data['quiz 2'], data['quiz 3'], data['quiz 4'], data['quiz 5'], data['quiz 6']]
        quizes_mean = round(np.mean(quizes), 1)
        
        #Reading Activities Mean
        readings = [data['reading 1'], data['reading 2'], data['reading 3'], data['reading 4'], data['reading 5'], data['reading 6']]
        readings_mean = round(np.mean(readings), 1)
        
        #project 
        project = data['project']
        #Score (%)
        s_score = float(calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project))
        #Adding student Score to scores
        scores.append(s_score)
        #print(scores)
        student_count +=1 
    #Saving to file
    #GETTING VARIBALES
    #Mean score
    mean_score = round(np.mean(scores), 1)
    #Minimum Score
    min_score = round(np.min(scores), 1)
    #Maximum score
    max_score = round(np.max(scores), 1)
    #Median Score
    median_score = round(np.median(scores), 1)
    #STD Deviation
    std_dev = round(np.std(scores), 1)
    with open("report.txt", 'w') as f:
        f.write(f"Total number of students: {student_count}\n")
        f.write(f"Minimum score: {min_score}\n")
        f.write(f"Maximum score: {max_score}\n")
        f.write(f"Median score: {median_score}\n")
        f.write(f"Mean score: {mean_score}\n")
        f.write(f"Standard deviation: {std_dev}\n")


def draw_pie_chart(arr1, arr2, file_path):
    """ 
    Draws pie chart based on the paramters passed  to it and saves the images as png formatted images in the passed file path.

    params: Array arr1, Array arr2, String file_path

    return: None
    """
    piechart = plt.figure()
    ax = piechart.add_axes([0,0,1,1])
    ax.axis('equal')
    ax.set_title("Class Grade Distribution")
    ax.pie(arr1, labels = arr2, autopct='%1.2f%%')
    figure1 = plt.gcf()
    plt.show()

    figure1.savefig(file_path)


def generate_class_report_charts(df):
    """ 
    Draws pie-chart and Bar Graph for letter grade distribution when a given DataFrame (df) is passed to it,  the results of the analysis is saved 
    as png formatted images on class_reports directory.

    params: Datafrane (df)

    return None:
    """
    #grades
    grades = ['A', 'B', 'C', 'D', 'F']
    #The number of students with each grade
    grades_count = [0, 0, 0, 0, 0]

    #Looping through each Grade
    for index,data in df.iterrows():
        filename = str(data['UIN'])
        #Calculate Exam Mean
        exams = [data['exam 1'], data['exam 2'], data['exam 3']]
        exams_mean = round(np.mean(exams), 1)
        
        #Labs Mean
        labs = [data['lab 1'], data['lab 2'], data['lab 3'], data['lab 4'], data['lab 5'], data['lab 6']]
        labs_mean = round(np.mean(labs), 1)
        

        #Quizes Mean
        quizes = [data['quiz 1'], data['quiz 2'], data['quiz 3'], data['quiz 4'], data['quiz 5'], data['quiz 6']]
        quizes_mean = round(np.mean(quizes), 1)
        

        #Reading Activities Mean
        readings = [data['reading 1'], data['reading 2'], data['reading 3'], data['reading 4'], data['reading 5'], data['reading 6']]
        readings_mean = round(np.mean(readings), 1)
        
        #project 
        project = data['project']
        #Score (%)
        score = float(calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project))
        #Adding student Score to scores
        grade = calculate_grade(score)

        #Updating the the counts based on grade of the student
        if grade == "A":
            grades_count[0] += 1
        elif grade == "B":
            grades_count[1] += 1
        elif grade == "C":
            grades_count[2] += 1
        elif grade == "D":
            grades_count[3] += 1    
        elif grade == "F":
            grades_count[4] += 1

    #Construct File path
    dir_path = "class_charts"
    #Create the directory if not existing
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
    file_path = f"{dir_path}/grade_distribution_pie_chart.png"
    #Plotting Piechart
    draw_pie_chart(grades_count, grades, file_path)
    file_path = f"{dir_path}/grade_distribution_bar_chart.png"
    y_pos = np.arange(len(grades))
    save_graph(y_pos, grades_count, "Count", "Grade #", "Grade Distribution", grades, file_path)


    
def main():
    """
    The entry point of the program where all the functions are all brought together and are run based on user input
    """
    exit = False
    while not exit:
        print_menu()
        option = get_user_input()
        if option == '1':
            print()
            
            csv_path = input("Enter Path to Data file: ")
            try:
                df = pd.read_csv(csv_path)
                print(df)
            except FileNotFoundError:
                print("File Not found, Try again!!!")
            print()
        elif option == '2':
            print()
            try:
                generate_student_report(df)
            except:
                print("Error occured@..Please Load the Data to analyze first..!!!")
            print()
        elif option == '3':
            print()
            try:
                generate_student_report_charts(df)
            except:
                print("Error occured@..Please Load the Data to analyze first..!!!")
            print()
        elif option == '4':
            print()
            try:
                class_reports(df)
            except:
                print("Error occured@..Please Load the Data to analyze first..!!!")
            print()
        elif option == '5':
            print()
            try:
                generate_class_report_charts(df)
            except:
                print("Error occured@..Please Load the Data to analyze first..!!!")
            print()
        elif option == 'q' or option == 'Q':
            print()
            exit = True
            print("Thank you for using the system.")
            print()
        else:
            print()
            print("Wrong Menu Choice, Try again...")
            print()

if __name__ == '__main__':
    main()

Functions

def calculate_grade(score)

calculates the letter grade for a score passed to it as an arguement.

params: float score

return String grade

Expand source code
def calculate_grade(score):
    """
    calculates the letter grade for a score passed to it as an arguement.
    
    params: float score

    return String grade
    """
    if score >= 90:
        grade = 'A'
    elif score >= 80:
        grade = 'B'
    elif score >= 70:
        grade = 'C'
    elif score >= 60:
        grade = 'D'
    else:
        grade = 'F'
    return grade
def calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project)

Calculates the percentage score from exam_mean, labs_mean, quizes_mean, readings_mean, project

params: float exams_float, float labs_mean, float quizes_mean, float quizes_mean, float readings_mean, float project.

return: float score

Expand source code
def calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project):
    """
    Calculates the percentage score from exam_mean, labs_mean, quizes_mean, readings_mean, project

    params: float exams_float, float labs_mean, float quizes_mean, float quizes_mean, float readings_mean, float project.

    return: float score
    """
    exams_per = (exams_mean * 45) / 100
    labs_per = (labs_mean * 25) / 100
    quizes_per = (quizes_mean * 10) / 100
    readings_per =  (readings_mean * 10) / 100
    project_per =  (project * 10) / 100

    total = exams_per + labs_per + quizes_per + readings_per + project_per

    return round(total, 1)
def class_reports(df)

Generates reports for the class, class means for the labs, exams, readings, quizes and project then class mean score, maximum score, median score, minimum and standard deviation.

params: DataFrame df.

Expand source code
def class_reports(df):
    """
    Generates reports for the class, class means for the labs, exams, readings, quizes and project then class mean score, maximum score,
    median score, minimum and standard deviation.

    params: DataFrame df.
    """
    scores = []
    file_path = "report.txt"
    student_count = 0
    for index,data in df.iterrows():
        filename = str(data['UIN'])
        #Calculate Exam Mean
        exams = [data['exam 1'], data['exam 2'], data['exam 3']]
        exams_mean = round(np.mean(exams), 1)
        
        #Labs Mean
        labs = [data['lab 1'], data['lab 2'], data['lab 3'], data['lab 4'], data['lab 5'], data['lab 6']]
        labs_mean = round(np.mean(labs), 1)
        
        #Quizes Mean
        quizes = [data['quiz 1'], data['quiz 2'], data['quiz 3'], data['quiz 4'], data['quiz 5'], data['quiz 6']]
        quizes_mean = round(np.mean(quizes), 1)
        
        #Reading Activities Mean
        readings = [data['reading 1'], data['reading 2'], data['reading 3'], data['reading 4'], data['reading 5'], data['reading 6']]
        readings_mean = round(np.mean(readings), 1)
        
        #project 
        project = data['project']
        #Score (%)
        s_score = float(calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project))
        #Adding student Score to scores
        scores.append(s_score)
        #print(scores)
        student_count +=1 
    #Saving to file
    #GETTING VARIBALES
    #Mean score
    mean_score = round(np.mean(scores), 1)
    #Minimum Score
    min_score = round(np.min(scores), 1)
    #Maximum score
    max_score = round(np.max(scores), 1)
    #Median Score
    median_score = round(np.median(scores), 1)
    #STD Deviation
    std_dev = round(np.std(scores), 1)
    with open("report.txt", 'w') as f:
        f.write(f"Total number of students: {student_count}\n")
        f.write(f"Minimum score: {min_score}\n")
        f.write(f"Maximum score: {max_score}\n")
        f.write(f"Median score: {median_score}\n")
        f.write(f"Mean score: {mean_score}\n")
        f.write(f"Standard deviation: {std_dev}\n")
def draw_pie_chart(arr1, arr2, file_path)

Draws pie chart based on the paramters passed to it and saves the images as png formatted images in the passed file path.

params: Array arr1, Array arr2, String file_path

return: None

Expand source code
def draw_pie_chart(arr1, arr2, file_path):
    """ 
    Draws pie chart based on the paramters passed  to it and saves the images as png formatted images in the passed file path.

    params: Array arr1, Array arr2, String file_path

    return: None
    """
    piechart = plt.figure()
    ax = piechart.add_axes([0,0,1,1])
    ax.axis('equal')
    ax.set_title("Class Grade Distribution")
    ax.pie(arr1, labels = arr2, autopct='%1.2f%%')
    figure1 = plt.gcf()
    plt.show()

    figure1.savefig(file_path)
def generate_class_report_charts(df)

Draws pie-chart and Bar Graph for letter grade distribution when a given DataFrame (df) is passed to it, the results of the analysis is saved as png formatted images on class_reports directory.

params: Datafrane (df)

return None:

Expand source code
def generate_class_report_charts(df):
    """ 
    Draws pie-chart and Bar Graph for letter grade distribution when a given DataFrame (df) is passed to it,  the results of the analysis is saved 
    as png formatted images on class_reports directory.

    params: Datafrane (df)

    return None:
    """
    #grades
    grades = ['A', 'B', 'C', 'D', 'F']
    #The number of students with each grade
    grades_count = [0, 0, 0, 0, 0]

    #Looping through each Grade
    for index,data in df.iterrows():
        filename = str(data['UIN'])
        #Calculate Exam Mean
        exams = [data['exam 1'], data['exam 2'], data['exam 3']]
        exams_mean = round(np.mean(exams), 1)
        
        #Labs Mean
        labs = [data['lab 1'], data['lab 2'], data['lab 3'], data['lab 4'], data['lab 5'], data['lab 6']]
        labs_mean = round(np.mean(labs), 1)
        

        #Quizes Mean
        quizes = [data['quiz 1'], data['quiz 2'], data['quiz 3'], data['quiz 4'], data['quiz 5'], data['quiz 6']]
        quizes_mean = round(np.mean(quizes), 1)
        

        #Reading Activities Mean
        readings = [data['reading 1'], data['reading 2'], data['reading 3'], data['reading 4'], data['reading 5'], data['reading 6']]
        readings_mean = round(np.mean(readings), 1)
        
        #project 
        project = data['project']
        #Score (%)
        score = float(calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project))
        #Adding student Score to scores
        grade = calculate_grade(score)

        #Updating the the counts based on grade of the student
        if grade == "A":
            grades_count[0] += 1
        elif grade == "B":
            grades_count[1] += 1
        elif grade == "C":
            grades_count[2] += 1
        elif grade == "D":
            grades_count[3] += 1    
        elif grade == "F":
            grades_count[4] += 1

    #Construct File path
    dir_path = "class_charts"
    #Create the directory if not existing
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
    file_path = f"{dir_path}/grade_distribution_pie_chart.png"
    #Plotting Piechart
    draw_pie_chart(grades_count, grades, file_path)
    file_path = f"{dir_path}/grade_distribution_bar_chart.png"
    y_pos = np.arange(len(grades))
    save_graph(y_pos, grades_count, "Count", "Grade #", "Grade Distribution", grades, file_path)
def generate_student_report(df)

Reads data from a passed data frame asking for a user input for the Student UIN and searches the data frame for the vlue. Means for Labs, Exams, Activities, Quizes, Readings and Projects mean are calculated and written to a file which holds the Students UIN

params: DataFrame df.

Expand source code
def generate_student_report(df):
    """
    Reads data from a passed data frame asking for a user input for the Student UIN and searches the data frame for the vlue.
    Means for Labs, Exams, Activities, Quizes, Readings and Projects mean are calculated and written to a file which holds the Students UIN

    params: DataFrame df.
    """
    pass_ = False
    while not pass_:
        try:
            student_uin = int(input("Enter Student UIN: "))
            if len(str(student_uin)) != 10:
                print("Please enter correct Student UIN: \n")
            else:
                for index,data in df.iterrows():
                    if data['UIN'] == student_uin:
                        pass_=True
                        print("Data Found")
                        filename = str(data['UIN'])
                        #Calculate Exam Mean
                        exams = [data['exam 1'], data['exam 2'], data['exam 3']]
                        exams_mean = round(np.mean(exams), 1)
                        
                        #Labs Mean
                        labs = [data['lab 1'], data['lab 2'], data['lab 3'], data['lab 4'], data['lab 5'], data['lab 6']]
                        labs_mean = round(np.mean(labs), 1)
                        

                        #Quizes Mean
                        quizes = [data['quiz 1'], data['quiz 2'], data['quiz 3'], data['quiz 4'], data['quiz 5'], data['quiz 6']]
                        quizes_mean = round(np.mean(quizes), 1)
                        

                        #Reading Activities Mean
                        readings = [data['reading 1'], data['reading 2'], data['reading 3'], data['reading 4'], data['reading 5'], data['reading 6']]
                        readings_mean = round(np.mean(readings), 1)
                        
                        #project 
                        project = data['project']
                        #Score (%)
                        score = calculte_percentage_score(exams_mean, labs_mean, quizes_mean, readings_mean, project)
                        grade = calculate_grade(score)
                        #Construct PATH to save
                        file_path = f"student_reports/{student_uin}.txt"
                        dir_path ="student_reports"
                        #Creating the directory if it does not exists
                        if not os.path.exists(dir_path):
                            os.makedirs(dir_path)
                        #Saving to file
                        with open(file_path, 'w') as f:
                            f.write(f"Exams mean: {exams_mean}\n")
                            f.write(f"Labs mean: {labs_mean}\n")
                            f.write(f"Quizzes mean: {quizes_mean}\n")
                            f.write(f"Reading activities mean: {readings_mean}\n")
                            f.write(f"Score: {score}\n")
                            f.write(f"Letter grade: {grade}\n")
                if pass_ == False:
                    print("No record found for the Student UIN, Please Retry!!")
        except:
            print("Enter Only numbers")
def generate_student_report_charts(df)

asks for user for Student UIN which they want to check for their reports, the function searches for the passed input in the DataFrame df, and if a record is found it captures the grades data for the given student and calls the function which plots the bar graph passing the required parameters to the function

params: DataFrame df.

Expand source code
def generate_student_report_charts(df):
    """
    asks for user for Student UIN which they want to check for their reports, the function searches for the passed input in the DataFrame df, 
    and if a record is found it captures the grades data for the given student and calls the function which plots the bar graph passing the required 
    parameters to the function

    params: DataFrame df.
    """
    pass_ = False
    while not pass_:
        try:
            student_uin = int(input("Enter Student UIN: "))
            if len(str(student_uin)) != 10:
                print("Please enter correct Student UIN: \n")
            else:
                for index,data in df.iterrows():
                    if data['UIN'] == student_uin:
                        pass_=True
                        print("Data Found")

                        #Create the folder to hold plots - If It does not exist
                        dir_path = f"{student_uin}"
                        if not os.path.exists(dir_path):
                            os.makedirs(dir_path)

                        filename = str(data['UIN'])
                        #Exams data - Bar Plot
                        exam_labels = ('1', '2', '3')
                        exams = [data['exam 1'], data['exam 2'], data['exam 3']]
                        file_path = f"{dir_path}/exam_bar_graph.png"
                        y_pos_exam = np.arange(len(exam_labels))

                        #Plotting Graph - Exams
                        #Call the fuctions to save grapgh
                        save_graph(y_pos_exam, exams,'Score (%)',"Exam #", f"Exam Grades for {student_uin}", exam_labels, file_path)

                        #Labs Grapgh
                        lab_labels = ('1', '2', '3', '4', '5', '6')
                        labs = [data['lab 1'], data['lab 2'], data['lab 3'], data['lab 4'], data['lab 5'], data['lab 6']]
                        file_path = f"{dir_path}/lab_bar_graph.png"
                        y_pos_lab = np.arange(len(lab_labels))

                        #Save the graph
                        save_graph(y_pos_lab, labs, "Score (%)", "Lab #", f"Lab Grades for {student_uin}", lab_labels, file_path)
                        
                        #Quizes Graph
                        quiz_labels = ('1', '2', '3', '4', '5', '6')
                        quizes = [data['quiz 1'], data['quiz 2'], data['quiz 3'], data['quiz 4'], data['quiz 5'], data['quiz 6']]
                        file_path = f"{dir_path}/quiz_bar_graph.png"
                        y_pos_quiz = np.arange(len(quiz_labels))

                        #Save to Graph
                        save_graph(y_pos_quiz, quizes, "Score (%)", "Quiz #", f"Quiz Grades for {student_uin}", quiz_labels, file_path)
                
                        #Reading Activities Graph
                        reading_label = ('1', '2', '3', '4', '5', '6')
                        readings = [data['reading 1'], data['reading 2'], data['reading 3'], data['reading 4'], data['reading 5'], data['reading 6']]
                        file_path = f"{dir_path}/readings_bar_graph.png"
                        y_pos_reading = np.arange(len(reading_label))

                        #Save to Graph
                        save_graph(y_pos_reading, readings, "Score (%)", "Reading Activity #", f"Reading activity grades for {student_uin}", reading_label, file_path)
                if pass_ == False:
                    print("No record found for the Student UIN, Please Retry!!")
        except:
            print("Enter Only numbers")
def get_user_input()

Gets input from the user, this input is what is used as menu option

return: String option

Expand source code
def get_user_input():
    """
    Gets input from the user, this input is what is used as menu option

    return: String option
    """
    pass_ = False
    option = input("Enter menu choice: ")

    return option
def main()

The entry point of the program where all the functions are all brought together and are run based on user input

Expand source code
def main():
    """
    The entry point of the program where all the functions are all brought together and are run based on user input
    """
    exit = False
    while not exit:
        print_menu()
        option = get_user_input()
        if option == '1':
            print()
            
            csv_path = input("Enter Path to Data file: ")
            try:
                df = pd.read_csv(csv_path)
                print(df)
            except FileNotFoundError:
                print("File Not found, Try again!!!")
            print()
        elif option == '2':
            print()
            try:
                generate_student_report(df)
            except:
                print("Error occured@..Please Load the Data to analyze first..!!!")
            print()
        elif option == '3':
            print()
            try:
                generate_student_report_charts(df)
            except:
                print("Error occured@..Please Load the Data to analyze first..!!!")
            print()
        elif option == '4':
            print()
            try:
                class_reports(df)
            except:
                print("Error occured@..Please Load the Data to analyze first..!!!")
            print()
        elif option == '5':
            print()
            try:
                generate_class_report_charts(df)
            except:
                print("Error occured@..Please Load the Data to analyze first..!!!")
            print()
        elif option == 'q' or option == 'Q':
            print()
            exit = True
            print("Thank you for using the system.")
            print()
        else:
            print()
            print("Wrong Menu Choice, Try again...")
            print()
def print_menu()

Prints the main menu where the user can make options

Expand source code
def print_menu():
    """
    Prints the main menu where the user can make options
    """
    print("******************Main Menu******************")
    print("1. Read CSV file of grades")
    print("2. Generate Student report file")
    print("3. Generate Student report charts")
    print("4. Generate Class report file")
    print("5. Generate class report charts")
    print("6. Quit")
    print()
def save_graph(y_pos, data, ylabel, xlabel, title, labels, file_path)

Plots a bar graph and saves it as a png formated image on the passed file path

params: Array y_pos, Array data, String, y_label, String xlabel, String title, Array labels, String file_path

Expand source code
def save_graph(y_pos, data, ylabel, xlabel, title, labels, file_path):
    """
    Plots a bar graph and saves it as a png formated image on the passed file path

    params: Array y_pos, Array data, String, y_label, String xlabel, String title, Array labels, String file_path
    """
    plt.bar(y_pos, data, align="center", alpha=0.5)
    plt.xticks(y_pos, labels)
    plt.ylabel(ylabel)
    plt.xlabel(str(xlabel))
    plt.title(title)
    figure1 = plt.gcf()

    plt.show()
    #Create Folder if not available
    figure1.savefig(file_path)