def rpt_student_scores(gb, preview=False, send_email=False): students = gb.get_actives() for student in students: text = student_score_text(gb, student) if not send_email and not preview: print(student.name()) print(text) else: salutation = "Hi {},\n\n".format(student.first) salutation += "Here are the scores I have recorded for you. Please let me know if you find any errors: \n\n" body = salutation + text if preview: print(body) else: try: g = gmail.Gmail("Recorded Scores", '') signature = g.signature g.body = body + '\n\n' + signature print(student.email) print(g.body) g.recipients = [student.email] g.send() except: print("failed to send the email. ", \ "Perhaps there is something wrong with the signature file.") ui.pause()
def import_students(gb): if gb.any_students_with_scores(): print( "Some students have scores.\nThese students must be manually deleted before importing can proceed." ) ui.pause() return if gb.students: if not ui.confirm("OK to delete existing students?"): return gb.delete_all_students() try: with open('roster.txt', 'r') as f: text = f.read() lines = text.rstrip().split('\n') for line in lines: first, last, email = line.split('\t') gb.add_student(first, last, email) gb.students.sort(key=lambda s: s.name()) gb.actives = None menus.set_student_options(gb) menus.set_student_last_first_options(gb) except: print( "The file 'roster.txt' could not be found or was incorrectly formatted" ) ui.pause()
def upgrade(course_dict): global schema_version cv = course_dict['schema_version'] if 'schema_version' in course_dict else 0 while cv < schema_version: cv += 1 globals()["migration" + str(cv)](course_dict) course_dict['schema_version'] = cv print("upgraded schema to version ", cv) ui.pause()
def rpt_student_summary_line(gb, send_email=False, stud=None): cats = gb.categories_with_scores() if not cats: ui.pause("No categories with Scores.") return student = stud or gb.cur_student pcts = np.array([c.combined_pct(student) for c in cats]) grade = student.grade() student_summary_line_body(student, grade, cats, pcts, send_email) ui.pause()
def export_students(gb): # try: with open('students.txt', 'w') as f: f.write( "First Name\tLast Name\tEmail\tGrade\tLetter\tNotes\tActive?\tHas Scores\n" ) f.write("\n".join(["{}\t{}\t{}\t{}\t{}\t{}\t{}".format( \ s.first, s.last, s.email, ui.num_na_str(s.grade()), ui.na_str(s.letter_grade()), s.notes, \ "Y" if s.is_active else "N", \ "Y" if s.has_scores() else "N") for s in gb.students])) # except Exception as ex: # print(ex) ui.pause()
def rpt_graded_item_details_by_student(gb): cg = gb.cur_gradeable names = np.array([s.name() for s in gb.get_actives()]) ar = np.array([[gb.get_score(s,cg,q).value for q in cg.questions] \ for s in gb.get_actives()]) tots = np.array([cg.adjusted_score(s) for s in gb.get_actives()]) pcts = np.array([cg.adjusted_pct(s) for s in gb.get_actives()]) title = "{} Details by Student".format(cg.name) m, n = ar.shape col_headings = ["#{0:d}".format(j + 1) for j in range(n)] rpt = SimpleReport(title, name_col_width=16, data_col_width=6, total_col_width=8, \ name_col_name='Student', row_headings=names, col_headings=col_headings, \ data=ar, total_col=tots, total_col_name = "Total", \ pct_col=pcts, has_average_row=True) print(rpt.render()) ui.pause()
def rpt_class_summary_line(gb, send_email=False): if send_email and not ui.confirm( "Are you sure you want to email ALL students?"): return cats = gb.categories_with_scores() if not cats: ui.pause(msg="No categories with Scores.") return students = gb.get_actives() pcts = np.array([[c.combined_pct(s) for c in cats] for s in students]) m, n = pcts.shape grades = np.array([s.grade() for s in gb.get_actives()]) for i in range(m): student = students[i] student_summary_line_body(student, grades[i], cats, pcts[i, :], send_email) ui.pause()
def add_gradeable(gb): if not gb.categories: ui.pause( "Can't create a graded item until there is at least one category.") return name = ui.get_string(gb, "Enter Graded Item Name") cat = ui.get_int_from_list(gb, "Select a numbered category", [c.name for c in gb.categories]) category = gb.categories[cat - 1] fpts = ui.get_space_separated_floats( gb, "Enter question point values separated by whitespace") total_pts = ui.get_valid_float(gb, "Total Points", sum(fpts) / 2, sum(fpts), sum(fpts)) gradeable = Gradeable(gb, name, category, total_pts) questions = [Question(gradeable, p) for p in fpts] gradeable.questions = questions gb.gradeables.append(gradeable) menus.set_gradeable_options(gb)
def rpt_class_detail(gb): gradeables = sorted(gb.gradeables_with_scores(), key=lambda g: g.name) if not gradeables: ui.pause(msg="No Graded Items with Scores.") return names = np.array([s.name() for s in gb.get_actives()]) col_headings = [g.name for g in gradeables] pcts = np.array([[g.adjusted_pct(s) for g in gradeables] for s in gb.get_actives()]) aves = np.array([s.grade() for s in gb.get_actives()]) title = "Class Details Report" plot_hist(aves, title) aveinds = aves.argsort() pcts, names, aves = pcts[aveinds, :], names[aveinds], aves[aveinds] rpt = SimpleReport(title, name_col_width=16, data_col_width=8, total_col_width=8, \ name_col_name='Student', row_headings=names, col_headings=col_headings, \ data=pcts, total_col=aves, total_col_name="Avg.", has_average_row=True) print(rpt.render()) ui.pause()
def rpt_class_summary(gb): cats = gb.categories_with_scores() if not cats: ui.pause(msg="No categories with Scores.") return names = np.array([s.name() for s in gb.get_actives()]) cnames = [c.name for c in cats] pcts = np.array([[c.combined_pct(s) for c in cats] for s in gb.get_actives()]) aves = np.array([s.grade() for s in gb.get_actives()]) title = "Class Summary Report" plot_hist(aves, title) aveinds = aves.argsort() pcts, names, aves = pcts[aveinds, :], names[aveinds], aves[aveinds] name_col_width, data_col_width, total_col_width = 16, 8, 8 rpt = SimpleReport(title, name_col_width=16, data_col_width=8, total_col_width=8, \ name_col_name="Student", row_headings=names, col_headings=cnames, \ data = pcts, total_col=aves, total_col_name="Avg.", has_average_row=True) print(rpt.render()) ui.pause()
def import_scores(gb): if gb.cur_gradeable.has_scores(): if not ui.confirm("Delete existing scores?"): return gb.cur_gradeable.delete_scores() try: with open('online_scores.txt', 'r') as f: text = f.read() scores = [] lines = text.strip().split('\n') scores = [line.split('\t') for line in lines] except Exception as err: print( "The file 'online_scores.txt' could not be found or was incorrectly formatted" ) print(err) ui.pause() try: with open('online_xref.txt', 'r') as f: xref_text = f.read() except: pass else: try: xref_list = [ line.split('\t') for line in xref_text.strip().split('\n') ] xref = {(last + ", " + first).upper(): email for first, last, email in xref_list} except Exception as err: xref = None print("The file 'online_xref.txt' was incorrectly formatted") print(err) ui.pause() update_scores(gb, scores, xref) menus.set_reports_gradeable_sel_options(gb) menus.set_reports_student_sel_options(gb) menus.set_gradeable_options(gb) ui.pause()