gsoni commited on
Commit
48c9f76
Β·
verified Β·
1 Parent(s): 75aca9c

Update app.py

Browse files

updated the professor distributions to show their average distribution and increased pie chart font size

Files changed (1) hide show
  1. app.py +92 -64
app.py CHANGED
@@ -50,11 +50,11 @@ def greet(subject, course_number, course_title):
50
  GPA = GPA + internal_grades.iloc[i]['GPA']
51
  i += 1
52
  GPA = GPA / internal_grades.GPA.size
53
- print("Average GPA: {:.3}".format(GPA))
54
 
55
  gradedistribution = ''
56
  print('')
57
- print("Grade distribution:")
58
  A = 0
59
  Aminus = 0
60
  Bplus = 0
@@ -88,8 +88,8 @@ def greet(subject, course_number, course_title):
88
  # plt.style.use('dark_background')
89
  sns.set_style("whitegrid")
90
  plt.figure(figsize=(10,10))
91
- plt.pie(df['values'], labels=df['labels'], autopct='%1.1f%%')
92
- plt.title('Average Grade Distribution for ' + subject + ' ' + str(internal_grades.iloc[0]['Course_Number']) + ' - ' + internal_grades.iloc[0]['Course_Title'])
93
  #plt.show()
94
  plot = plt
95
 
@@ -97,62 +97,90 @@ def greet(subject, course_number, course_title):
97
  sortedprofgradedist = ''
98
  print('')
99
  print("Top Professors by GPA:")
100
- k = 1
101
- for k in range(internal_grades.Instructor.size):
102
- j = k - 1
103
- internal_found = False
104
- while (j >= 0):
105
- if (internal_grades.iloc[k]['Instructor'] == internal_grades.iloc[j]['Instructor']):
106
- internal_found = True
107
- j -= 1
108
- if (internal_found != True):
109
- sortedprofgradedist = sortedprofgradedist + str("\nProfessor " + internal_grades.iloc[k]['Instructor'] + ', GPA: ' + str(internal_grades.iloc[k]['GPA']) + ',')
110
- if (internal_grades.iloc[k]['GPA'] > GPA):
111
- sortedprofgradedist = sortedprofgradedist + str(" Above average")
112
- elif (internal_grades.iloc[k]['GPA'] == GPA):
113
- sortedprofgradedist = sortedprofgradedist + str(" Average")
114
- else:
115
- sortedprofgradedist = sortedprofgradedist + str(" Below average")
116
- sortedprofgradedist = sortedprofgradedist + str("\nEnrollment: {}".format(internal_grades.iloc[k]['Enrollment']) + ', Withdraws: {}'.format(internal_grades.iloc[k]['Withdraws']))
117
- sortedprofgradedist = sortedprofgradedist + str("\nGrade distribution:")
118
- sortedprofgradedist = sortedprofgradedist + str(" ")
119
- A = 0
120
- Aminus = 0
121
- Bplus = 0
122
- B = 0
123
- Bminus = 0
124
- Cplus = 0
125
- C = 0
126
- Cminus = 0
127
- Dplus = 0
128
- D = 0
129
- Dminus = 0
130
- F = 0
131
 
132
- j = 0
133
- letterchar = ['A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'D-', 'F']
134
- lettergrades = [A, Aminus, Bplus, B, Bminus, Cplus, C, Cminus, Dplus, D, Dminus, F]
135
- # vals = []
136
- for letter in (lettergrades):
137
- i = 0
138
- while i < internal_grades.A.size:
139
- letter = letter + internal_grades.iloc[k][letterchar[j]]
140
- i += 1
141
- letter = letter / internal_grades.A.size
142
- sortedprofgradedist = sortedprofgradedist + str("{}: {:.3}%".format(letterchar[j], letter))
143
- sortedprofgradedist = sortedprofgradedist + str(', ')
144
- # vals.append(letter)
145
- j += 1
146
- sortedprofgradedist = sortedprofgradedist + str('\n')
147
- # data = {'labels': ['A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'D-', 'F'],
148
- # 'values': vals}
149
- # df = pd.DataFrame(data)
150
- # sns.set_style("whitegrid")
151
- # plt.figure(figsize=(10,10))
152
- # plt.pie(df['values'], labels=df['labels'], autopct='%1.1f%%')
153
- # plt.title('Best Grade Distribution for ' + "Professor " + internal_grades.iloc[k]['Instructor'] + "'s class")
154
- # plt.show()
155
- k += 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  # professors who teach the class
158
  profswhoteach = ''
@@ -163,18 +191,18 @@ def greet(subject, course_number, course_title):
163
 
164
  # enrollment and withdraws
165
  print('')
166
- return (subject + ' ' + str(internal_grades.iloc[0]['Course_Number']) + ' - ' + internal_grades.iloc[0]['Course_Title'] + ' (' + str(internal_grades.iloc[0]['Credits']) + ' Credits)') + ("\nAverage GPA: {:.3}".format(GPA)) + profswhoteach, gradedistribution, plot, sortedprofgradedist
167
 
168
  # gradio interface
169
  demo = gr.Interface(
170
  fn=greet,
171
- inputs=[gr.Textbox(label="Subject (Eg. ECON)"), gr.Number(label="Course Number (Eg. 2005)"), gr.Textbox(label="Course Title (Eg. Principles of Economics)")],
172
- outputs=[gr.Textbox(label="Course Information"), gr.Textbox(label="Average Grade Distribution", lines=2), gr.Plot(label="Average Distribution Plot"), gr.Textbox(label="Grade Distributions by Professors", lines=3)],
173
  title="GradeDistVis",
174
  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,",
175
- # article="Source of data: https://udc.vt.edu/irdata/data/courses/grades",
176
  examples = [["ECON", 2005, ''], ["CHEM", '',"General Chemistry"]],
177
  cache_examples=True,
178
- ).queue(default_concurrency_limit=10000)
179
 
180
  demo.launch()
 
50
  GPA = GPA + internal_grades.iloc[i]['GPA']
51
  i += 1
52
  GPA = GPA / internal_grades.GPA.size
53
+ print("Course Average GPA: {:.3}".format(GPA))
54
 
55
  gradedistribution = ''
56
  print('')
57
+ # print("Grade distribution:")
58
  A = 0
59
  Aminus = 0
60
  Bplus = 0
 
88
  # plt.style.use('dark_background')
89
  sns.set_style("whitegrid")
90
  plt.figure(figsize=(10,10))
91
+ plt.pie(df['values'], labels=df['labels'], autopct='%1.1f%%', textprops={'fontsize': 20})
92
+ plt.title('Course Average Grade Distribution for ' + subject + ' ' + str(internal_grades.iloc[0]['Course_Number']) + ' - ' + internal_grades.iloc[0]['Course_Title'])
93
  #plt.show()
94
  plot = plt
95
 
 
97
  sortedprofgradedist = ''
98
  print('')
99
  print("Top Professors by GPA:")
100
+ profnames = internal_grades.Instructor.unique()
101
+ profaveragegpa = []
102
+ profdict = {}
103
+ for prof in profnames:
104
+ internal_prof = internal_grades.loc[internal_grades.Instructor == prof]
105
+ GPAinternal = 0.00
106
+ i = 0
107
+ while i < internal_prof.GPA.size:
108
+ GPAinternal = GPAinternal + internal_prof.iloc[i]['GPA']
109
+ i += 1
110
+ GPAinternal = GPAinternal / internal_prof.GPA.size
111
+ profaveragegpa.append(GPAinternal)
112
+ profdict[prof] = GPAinternal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
+ # sort profs by highest avg gpa
115
+ sortedprofs = {key: val for key, val in sorted(profdict.items(), key = lambda ele: ele[1], reverse = True)}
116
+ print(sortedprofs)
117
+ profkeys = sortedprofs.keys()
118
+ for key in profkeys:
119
+ internal_prof = internal_grades.loc[internal_grades.Instructor == key]
120
+ enrollment = 0
121
+ withdraws = 0
122
+ A = 0
123
+ Aminus = 0
124
+ Bplus = 0
125
+ B = 0
126
+ Bminus = 0
127
+ Cplus = 0
128
+ C = 0
129
+ Cminus = 0
130
+ Dplus = 0
131
+ D = 0
132
+ Dminus = 0
133
+ F = 0
134
+ i = 0
135
+ while i < internal_prof.GPA.size:
136
+ A = A + internal_prof.iloc[i]['A']
137
+ Aminus = Aminus + internal_prof.iloc[i]['A-']
138
+ Bplus = Bplus + internal_prof.iloc[i]['B+']
139
+ B = B + internal_prof.iloc[i]['B']
140
+ Bminus = Bminus + internal_prof.iloc[i]['B-']
141
+ Cplus = Cplus + internal_prof.iloc[i]['C+']
142
+ C = C + internal_prof.iloc[i]['C']
143
+ Cminus = Cminus + internal_prof.iloc[i]['C-']
144
+ Dplus = Dplus + internal_prof.iloc[i]['D+']
145
+ D = D + internal_prof.iloc[i]['D']
146
+ Dminus = Dminus + internal_prof.iloc[i]['D-']
147
+ F = F + internal_prof.iloc[i]['F']
148
+ enrollment = enrollment + internal_prof.iloc[i]['Enrollment']
149
+ withdraws = withdraws + internal_prof.iloc[i]['Withdraws']
150
+ i += 1
151
+ A = A / internal_prof.GPA.size
152
+ Aminus = Aminus / internal_prof.GPA.size
153
+ Bplus = Bplus / internal_prof.GPA.size
154
+ B = B / internal_prof.GPA.size
155
+ Bminus = Bminus / internal_prof.GPA.size
156
+ Cplus = Cplus / internal_prof.GPA.size
157
+ C = C / internal_prof.GPA.size
158
+ Cminus = Cminus / internal_prof.GPA.size
159
+ Dplus = Dplus / internal_prof.GPA.size
160
+ D = D / internal_prof.GPA.size
161
+ Dminus = Dminus / internal_prof.GPA.size
162
+ F = F / internal_prof.GPA.size
163
+ enrollment = enrollment / internal_prof.GPA.size
164
+ withdraws = withdraws / internal_prof.GPA.size
165
+
166
+ sortedprofgradedist = sortedprofgradedist + str('\nProfessor ' + key + ", Avg GPA: {:.3}".format(sortedprofs.get(key)))
167
+ if (sortedprofs.get(key) > GPA):
168
+ sortedprofgradedist = sortedprofgradedist + str(", Above average")
169
+ elif (sortedprofs.get(key) == GPA):
170
+ sortedprofgradedist = sortedprofgradedist + str(", Average")
171
+ else:
172
+ sortedprofgradedist = sortedprofgradedist + str(", Below average")
173
+ # print('')
174
+ sortedprofgradedist = sortedprofgradedist + str("\nEnrollment: {:.0f}".format(enrollment) + ', Withdraws: {:.0f}'.format(withdraws))
175
+ sortedprofgradedist = sortedprofgradedist + str("\nAvg Distribution: ")
176
+ letterchar = ['A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'D-', 'F']
177
+ lettergrades = [A, Aminus, Bplus, B, Bminus, Cplus, C, Cminus, Dplus, D, Dminus, F]
178
+ j = 0
179
+ for letter in lettergrades:
180
+ sortedprofgradedist = sortedprofgradedist + str("{}: {:.3}%".format(letterchar[j], letter))
181
+ sortedprofgradedist = sortedprofgradedist + str(', ')
182
+ j += 1
183
+ sortedprofgradedist = sortedprofgradedist + str('\n')
184
 
185
  # professors who teach the class
186
  profswhoteach = ''
 
191
 
192
  # enrollment and withdraws
193
  print('')
194
+ 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
195
 
196
  # gradio interface
197
  demo = gr.Interface(
198
  fn=greet,
199
+ inputs=[gr.Textbox(label="Subject (Eg. ECON, chem)"), gr.Number(label="Course Number (Eg. 2005)"), gr.Textbox(label="Course Title (Eg. Principles of Economics) (case sensitive)")],
200
+ 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)],
201
  title="GradeDistVis",
202
  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,",
203
+ article="Feedback Form: https://forms.gle/G4zV25XH8tDYLsRW9",
204
  examples = [["ECON", 2005, ''], ["CHEM", '',"General Chemistry"]],
205
  cache_examples=True,
206
+ ).queue(default_concurrency_limit=1000)
207
 
208
  demo.launch()