#!/usr/bin/env python import sys, os, re, time, shutil mylib = os.path.join(os.environ["HOME"], "src", "python") grlib = os.path.join(os.environ["HOME"], "src", "grading") sys.path.extend([mylib, grlib]) from Util import * from course import * # ----------- constants, depend on the course ----------------- student_lists = ["rst"] long_exams = ["midterm-1", "midterm-2", # "quiz", "final"] homeworks = ["01","02","03","04","05","06","07", "08", "09", "10"] quizzes = ["q01","q02","q03","q04", # "q05", "q06","q07","q08","q09"] lectures = [ # "a12-07", # "a12-02", # "a11-30", # "a11-23", # "a11-18", # "a11-16", # "a11-11", # "a11-09", # "a11-04", # "a10-28", # "a10-26", # "a10-21", # "a10-19", # "a10-14", # "a10-07", # "a10-05", # "a09-28", # "a09-23", # "a09-21", # "a09-16", # "a09-14", # "a09-09", # "a09-07" ] extras = [] multipart = {"homeworks": homeworks} # adj_homeworks = ["hw1to5","06"] adj_homeworks = homeworks # events = homeworks+["midterm-1","midterm-2", "quiz"] events = lectures class_partic_sources = ["perception","labs"] targets = ["midterm","absences","class_partic","homework","course","course-grade", "quiz_total"] exams = (student_lists + long_exams + homeworks + class_partic_sources + targets) sources = {"course" : long_exams + [ "homework", "class_partic"], "class_partic": class_partic_sources } # ------------- utilities -------------- def usage(progname): usages = [] usages.append(progname+""" --help This message. """) usages.append(progname+""" --custom The script contains some custom action which it will perform. """) usages.append(progname+""" [--course ] --exam When --course is not given, it is assumed that the current directory is ~//grading. The scores of exam are sorted. If a cuts file is present, the grades are also computed. can also be the name of a list of exams. In this case, each exam in the list will be processed. """) usages.append(progname+""" [--course ] --target The target exam will be (re)computed from its constituents. """) usages.append("""Adding the option --student will display the calculations for this particular student.""") usage_string = """Usage: """+" "+" ".join(usages)+""" """ sys.stderr.write(usage_string) sys.exit(1) # # When there is a show_student argument to the functions below, then the # results for the student in question will also be displayed on the screen. # def proc_best_hw(course, target, source=[], delete_worst=1, print_grade=0, show_student = ""): target_exam = course.get_exam(target) warn("Adding the best scores for %s" % (target)) course.exams_sum_best_scores(target, exam_names = source, delete_worst = delete_worst, show_student = show_student ) target_exam.print_records(sorted_by = "score", target = target, print_name = 1, print_grade = print_grade, show_student = show_student, precision = 0 ) target_exam.print_cuts() def proc1to5(course, show_student = ""): hw1to5list = "01 02 03 04 05".split() hw1to5 = course.get_exam() proc_best_hw(course, "hw1to5", source=hw1to5list, delete_worst=1, show_student = show_student) def proc_hw(course, target = "homework", source = adj_homeworks, print_grade = 0, show_student = ""): warn("Adding up scores") course.exams_calc_average(target = target, exam_names = source, show_student = show_student, grades = 0 ) hw = course.get_exam(target) hw.calc_grades() warn("Printing "+target+" ...") hw.print_records(sorted_by = "score", target = target, print_name = 1, print_grade = print_grade, show_student = show_student ) def calc_extra_info(course, target="absences", source=lectures, show_student="", comment_regexp=r'[\*]'): warn("Calculating absences") exam = course.get_exam(target) course.sum_extra_info(target=target, exam_names=source, show_student=show_student, comment_regexp=comment_regexp) warn("Printing the scores") exam.print_records(sorted_by = "score", target = target, print_name = 1, print_grade = 0, show_student = show_student ) def calc_target(course, target = "course", show_student = "", print_grade = 1, student_list = "rst"): target_exam = course.get_exam(target) # The exam object named course: course.exams_calc_average(target = target, exam_names = target_exam.sources, show_student = show_student, student_list = student_list ) real_list = [] if not student_list == "rst": real_list = course.get_exam(student_list).get_student_list() target_exam.print_records(sorted_by = "score", target = target, print_name = 1, print_grade = print_grade, show_student = show_student, subset = real_list ) target_exam.print_cuts() target_exam.read_cuts() # to read possibly course.cuts.xcp # --------------------- main ----------------------- progname = os.path.basename(sys.argv[0]) argc = len(sys.argv) if 2 > argc: usage(progname) long_optlist = ["help", "custom", "course", "distr", "exam=", "target=", "method=","student=","student-list="] options, restargs = getopt_map("x", long_optlist) if options.has_key("--help"): usage(sys.argv[0]) if options.has_key("--course"): course_name = options["course"] else: cwd = os.getcwd() # cwd == "/home/fac0/gacs/courses/cs332/grading" cwdlist = cwd.split(os.sep) course_name = cwdlist[-2] if options.has_key("--student"): show_student = options["--student"] else: show_student = "" if options.has_key("--student-list"): student_list = options["--student-list"] else: student_list = "rst" course = Course.Course(name = course_name, exam_names = exams) # submit_exams = mail_exams all_students = course.get_student_list() mail_students = all_students submit_students = all_students mail_intro = """ These are your midterm, homework and quiz dates so far. For the score distributions, please visit the link 'Grade Statistics' on the course homepage. """ if options.has_key("--exam"): exam_name = options["--exam"] if "homeworks" == exam_name or "quizzes" == exam_name: for hw in multipart[exam_name]: course.proc_exam(exam = hw, print_grade = 0, only_by_score = 1) else: course.proc_exam(exam = exam_name) if options.has_key("--distr"): course.get_exam(exam_name).print_records(only_distr = 1) if options.has_key("--target"): target = options["--target"] if "midterm" == target: course.exams_better(exam_names = ["midterm-1", "midterm-2"], target = "midterm") course.proc_exam(exam = "midterm") elif "best_homework" == target: proc_best_hw(course, target = "homework", source = homeworks, delete_worst=1, print_grade = 0, show_student=show_student) elif "hw1to5" == target: proc1to5(course, show_student=show_student) elif "homework" == target: proc_hw(course, target = "homework", source = adj_homeworks, print_grade = 0, show_student=show_student) elif "quiz_total" == target: proc_hw(course, source = quizzes, target = "quiz_total", print_grade = 0, show_student=show_student) elif "absences" == target: calc_extra_info(course, target = "absences", source=events, show_student=show_student) elif "bonus" == target: calc_extra_info(course, target = "bonus", source=homeworks, show_student=show_student, comment_regexp=r"(^|\s)bonus") elif "class_partic"==target: calc_target(course, target=target, show_student = show_student, print_grade = 1) elif "course"==target: calc_target(course, target=target, show_student = show_student, print_grade = 1, student_list=student_list) elif "phd-extras"==target: calc_target(course, target=target, show_student = show_student, print_grade = 1, student_list="rst-phd") elif "phd-midterm"==target: calc_target(course, target=target, show_student = show_student, print_grade = 1, student_list="rst-phd") elif "course-phd"==target: calc_target(course, target=target, show_student = show_student, print_grade = 1, student_list="rst-phd") elif "course-nonphd"==target: calc_target(course, target=target, show_student = show_student, print_grade = 1, student_list="rst-nonphd") else: proc_hw(course, source = sources[target], target = target, print_grade = 0) """ Processing an exam, for example midterm-1: grcomp --exam midterm-1 cp cuts midterm-1.cuts Write in the desired cuts. grcomp --exam midterm-1 Diagn: print "ronguida:", course.get_score("midterm", "ronguida") Process midterm-2. g grcomp --target midterm Process final. Process class_partic. Get the homework files, maybe using late_discount, then proceed as follows: grcomp --exam homeworks grcomp --target homework select homework cuts grcomp --exam homework grcomp --target course-nonphd modify course-nonphd.cuts into course-nonphd.cuts.xcp grcomp --exam course-nonphd grcomp --target course-phd-nonphd grcomp --target phds-extras select phd-extras cuts grcomp --exam phds-extras grcomp --target course-phd --student sowmya (for diagn) modify course-phd.cuts into course-phd.cuts.xcp grcomp --exam course-phd """ # # proc1to5(course, show_student = "janerik") # proc1to5(course) # course.proc_exam(exam = "06", print_grade = 0) # # grcomp --exam quizzes # grcomp --target quiz_total # select quiz_total cuts # grcomp --exam quiz_total # "course_grade" is like "course", but is never processed, just sorted. # grcomp --target mail-test # grcomp --target mail # If you want a distribution: # # course.get_exam("final_exam").print_records(only_distr = 1)