File size: 9,451 Bytes
7372d1d
 
7b3d91b
84d3413
 
3d3e316
eb295f0
5fc1fc9
7372d1d
5fc1fc9
7372d1d
c93f217
7372d1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fc1fc9
eb295f0
7372d1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48c9f76
7372d1d
 
 
48c9f76
7372d1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d3e316
7372d1d
 
 
 
 
 
3d3e316
7372d1d
84d3413
7372d1d
3d3e316
 
 
a2d8ceb
3d3e316
 
48c9f76
 
3d3e316
 
7372d1d
 
 
 
 
48c9f76
 
 
 
 
 
 
 
 
 
 
 
 
5fc1fc9
48c9f76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7372d1d
 
5fc1fc9
da93b97
7372d1d
 
 
 
 
62ad90c
48c9f76
7372d1d
5fc1fc9
7372d1d
 
eb295f0
48c9f76
da93b97
75aca9c
48c9f76
fcbc6fa
cdede07
48c9f76
da93b97
7105268
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import gradio as gr
import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
import seaborn as sns

def greet(subject, course_number):
    # modify the inputs
    subject = subject.upper()

    # import data as csv file
    grades = pd.read_csv("gradedist2025.csv")
    grades = grades.rename(columns={'Course No.': 'Course_Number', 
                                    'Course Title': 'Course_Title',
                                    'Graded Enrollment': 'Enrollment', 
                                    'A (%)': 'A', 
                                    'A- (%)': 'A-', 
                                    'B+ (%)': 'B+', 
                                    'B (%)': 'B', 
                                    'B- (%)': 'B-', 
                                    'C+ (%)': 'C+', 
                                    'C (%)': 'C',
                                    'C- (%)': 'C-',
                                    'D+ (%)': 'D+',
                                    'D (%)': 'D',
                                    'D- (%)': 'D-',
                                    'F (%)': 'F'})
    grades = grades.sort_values(by='Course_Number')
    internal_grades = grades

    # user interface
    while True:
        # filter the csv file by the input subject and course number/title
        internal_grades = grades.loc[(grades.Subject == subject) & (grades.Course_Number == course_number)]
        internal_grades = internal_grades.sort_values(by='GPA', ascending=False)

        # class information label
        print('')
        print( subject + ' ' + str(internal_grades.iloc[0]['Course_Number']) + ' - ' + internal_grades.iloc[0]['Course_Title'] + ' (' + str(internal_grades.iloc[0]['Credits']) + ' Credits)')

        
        # gpa calculation
        print('')
        GPA = 0.00
        i = 0
        while i < internal_grades.GPA.size:
            GPA = GPA + internal_grades.iloc[i]['GPA']
            i += 1
        GPA = GPA / internal_grades.GPA.size
        print("Course Average GPA: {:.3}".format(GPA))

        gradedistribution = ''
        print('')
        # print("Grade distribution:")
        A = 0
        Aminus = 0
        Bplus = 0
        B = 0
        Bminus = 0
        Cplus = 0
        C = 0
        Cminus = 0
        Dplus = 0
        D = 0
        Dminus = 0
        F = 0
        
        j = 0
        letterchar = ['A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'D-', 'F']
        lettergrades = [A, Aminus, Bplus, B, Bminus, Cplus, C, Cminus, Dplus, D, Dminus, F]
        val = []
        for letter in (lettergrades):
            i = 0
            while i < internal_grades.GPA.size:
                letter = letter + internal_grades.iloc[i][letterchar[j]]
                i += 1
            letter = letter / internal_grades.GPA.size
            val.append(letter)
            gradedistribution = gradedistribution + str("{}: {:.3}%".format(letterchar[j], letter))
            gradedistribution = gradedistribution + str(', ')
            j += 1
        data = {'labels': ['A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'D-', 'F'],
            'values': val}
        df = pd.DataFrame(data)
        # plt.style.use('dark_background')
        sns.set_style("whitegrid")
        plt.figure(figsize=(10,10))
        plt.pie(df['values'], labels=df['labels'], autopct='%1.1f%%', textprops={'fontsize': 20})
        plt.title('Course Average Grade Distribution for ' + subject + ' ' + str(internal_grades.iloc[0]['Course_Number']) + ' - ' + internal_grades.iloc[0]['Course_Title'])
        #plt.show()
        plot = plt

        # sort professors
        sortedprofgradedist = ''
        print('')
        print("Top Professors by GPA:")
        profnames = internal_grades.Instructor.unique()
        profaveragegpa = []
        profdict = {}
        for prof in profnames:
                internal_prof = internal_grades.loc[internal_grades.Instructor == prof]
                GPAinternal = 0.00
                i = 0
                while i < internal_prof.GPA.size:
                    GPAinternal = GPAinternal + internal_prof.iloc[i]['GPA']
                    i += 1
                GPAinternal = GPAinternal / internal_prof.GPA.size
                profaveragegpa.append(GPAinternal)
                profdict[prof] = GPAinternal

        # sort profs by highest avg gpa
        sortedprofs = {key: val for key, val in sorted(profdict.items(), key = lambda ele: ele[1], reverse = True)}
        print(sortedprofs)
        profkeys = sortedprofs.keys()
        for key in profkeys:
            internal_prof = internal_grades.loc[internal_grades.Instructor == key]
            enrollment = 0
            withdraws = 0
            A = 0
            Aminus = 0
            Bplus = 0
            B = 0
            Bminus = 0
            Cplus = 0
            C = 0
            Cminus = 0
            Dplus = 0
            D = 0
            Dminus = 0
            F = 0
            i = 0
            while i < internal_prof.GPA.size:
                    A = A + internal_prof.iloc[i]['A']
                    Aminus = Aminus + internal_prof.iloc[i]['A-']
                    Bplus = Bplus + internal_prof.iloc[i]['B+']
                    B = B + internal_prof.iloc[i]['B']
                    Bminus = Bminus + internal_prof.iloc[i]['B-']
                    Cplus = Cplus + internal_prof.iloc[i]['C+']
                    C = C + internal_prof.iloc[i]['C']
                    Cminus = Cminus + internal_prof.iloc[i]['C-']
                    Dplus = Dplus + internal_prof.iloc[i]['D+']
                    D = D + internal_prof.iloc[i]['D']
                    Dminus = Dminus + internal_prof.iloc[i]['D-']
                    F = F + internal_prof.iloc[i]['F']
                    enrollment = enrollment + internal_prof.iloc[i]['Enrollment']
                    withdraws = withdraws + internal_prof.iloc[i]['Withdraws']
                    i += 1
            A = A / internal_prof.GPA.size
            Aminus = Aminus / internal_prof.GPA.size
            Bplus = Bplus / internal_prof.GPA.size
            B = B / internal_prof.GPA.size
            Bminus = Bminus / internal_prof.GPA.size
            Cplus = Cplus / internal_prof.GPA.size
            C = C / internal_prof.GPA.size
            Cminus = Cminus / internal_prof.GPA.size
            Dplus = Dplus / internal_prof.GPA.size
            D = D / internal_prof.GPA.size
            Dminus = Dminus / internal_prof.GPA.size
            F = F / internal_prof.GPA.size
            enrollment = enrollment / internal_prof.GPA.size
            withdraws = withdraws / internal_prof.GPA.size

            sortedprofgradedist = sortedprofgradedist + str('\nProfessor ' + key + ", Avg GPA: {:.3}".format(sortedprofs.get(key)))
            if (sortedprofs.get(key) > GPA):
                sortedprofgradedist = sortedprofgradedist + str(", Above average")
            elif (sortedprofs.get(key) == GPA):
                sortedprofgradedist = sortedprofgradedist + str(", Average")
            else:
                sortedprofgradedist = sortedprofgradedist + str(", Below average")
            # print('')
            sortedprofgradedist = sortedprofgradedist + str("\nEnrollment: {:.0f}".format(enrollment) + ', Withdraws: {:.0f}'.format(withdraws))
            sortedprofgradedist = sortedprofgradedist + str("\nAvg Distribution: ")
            letterchar = ['A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'D-', 'F']
            lettergrades = [A, Aminus, Bplus, B, Bminus, Cplus, C, Cminus, Dplus, D, Dminus, F]
            j = 0
            for letter in lettergrades:
                sortedprofgradedist = sortedprofgradedist + str("{}: {:.3}%".format(letterchar[j], letter))
                sortedprofgradedist = sortedprofgradedist + str(', ')
                j += 1
            sortedprofgradedist = sortedprofgradedist + str('\n')

        # professors who teach the class
        profswhoteach = ''
        profswhoteach = profswhoteach + str('\n')
        profswhoteach = profswhoteach + str("Professors who teach {}:".format(internal_grades.iloc[0]['Course_Title']))
        profswhoteach = profswhoteach + str('\n')
        profswhoteach = profswhoteach + str(internal_grades.Instructor.unique())

        # enrollment and withdraws
        print('')
        return (subject + ' ' + str(internal_grades.iloc[0]['Course_Number']) + ' - ' + internal_grades.iloc[0]['Course_Title'] + ' (' + str(internal_grades.iloc[0]['Credits']) + ' Credits)') + ("\nCourse Average GPA: {:.3}".format(GPA)) + profswhoteach, gradedistribution, plot, sortedprofgradedist 

# gradio interface
demo = gr.Interface(
    fn=greet,
    inputs=[gr.Textbox(label="Subject (Eg. ECON, chem)"), gr.Number(label="Course Number (Eg. 2005)")],
    outputs=[gr.Textbox(label="Course Information"), gr.Textbox(label="Course Average Grade Distribution", lines=2), gr.Plot(label="Course Average Grade Distribution Plot"), gr.Textbox(label="Average Grade Distributions by Professors", lines=3)],
    title="GradeDistVis",
    description="πŸ“š Plan your courses like a PRO with GradeDistVis! πŸŽ“βœ¨ Access grade distributions and other key metrics to maximize your GPA!πŸ”₯ \n\n For Virginia Tech students,",
    article="Feedback Form: https://forms.gle/G4zV25XH8tDYLsRW9",
    examples = [["ECON", 2005], ["chem", 1036]],
    cache_examples=True,
).queue(default_concurrency_limit=1000)

demo.launch()