#!/usr/local/bin/python import sys, os, re, time, shutil mylib = os.path.join(os.environ['HOME'], 'lib', 'python') grlib = os.path.join(os.environ['HOME'], 'lib', 'grading') sys.path.extend([mylib, grlib]) from Util import * from course import * # ----------- constants, depend on the course ----------------- long_exams = ['midterm','final'] multipart = { 'quizzes' : [], 'homeworks' : [] } quizzes = multipart['quizzes'] homeworks = multipart['homeworks'] homeworks = ['01','02','03','04','05','06', '07', '08', '09', '10', '11', '12', '13'] adj_homeworks = homeworks targets = ['homework','class-partic','course','course-grade'] exams = long_exams + homeworks + targets course_grade_sources = long_exams + [ #'quiz-total', 'homework', 'class-partic'] mail_exams = ['course-grade', 'homework', 'midterm', 'final', 'class-partic'] # ------------- 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 student argument to the functions below, then the # results for the student in question will also be displayed on the screen. # def proc1to5(course, student = ''): Student = student hw1to5list = '01 02 03 04 05'.split() hw1to5 = course.get_exam('hw1to5') warn("Adding the best scores in 01-05 ...") course.exams_sum_best_scores(target = 'hw1to5', exams = hw1to5list, delete_worst = 1, student = Student ) hw1to5.print_records(sorted_by = 'score', target = 'hw1to5', print_name = 1, student = Student ) def proc_hw(course, print_grade = 0, student = '', source = adj_homeworks, target = 'homework'): Student = student # for diagnosis warn("Adding up scores") course.exams_calc_average(target = target, exams = source, student = 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, student = Student ) def calc_course_score(course, student = '', print_grade = 1): Student = student # for diagnosis # The exam object named course: course.exams_calc_average(target = 'course', exams = course_grade_sources, student = Student ) course_ex = course.get_exam('course') course_ex.print_records(sorted_by = 'score', target = 'course', print_name = 1, print_grade = print_grade, student = Student ) course_ex.print_cuts() course_ex.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', 'exam=', 'target=', 'method=','student='] options, restargs = getopt_map('x', long_optlist) if options.has_key('--help'): die(usage_string) if options.has_key('--course'): course_name = options['course'] else: cwd = os.getcwd() # cwd == '/home/fac0/gacs/cs332/grading' cwdlist = cwd.split(os.sep) course_name = cwdlist[-2] if options.has_key('--student'): student = options['--student'] else: student = '' course = Course.Course(name = course_name, exams = exams) submit_exams = mail_exams all_students = course.get_student_list() mail_students = all_students submit_students = all_students 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) sys.exit(0) if options.has_key('--target'): target = options['--target'] if 'midterm' == target: course.exams_better(exams = ['midterm-1', 'midterm-2'], target = 'midterm') course.proc_exam(exam = 'midterm') sys.exit(0) if 'hw1to5' == target: proc1to5(course, student=student) sys.exit(0) if 'homework' == target: proc_hw(course, source = adj_homeworks, target = 'homework', print_grade = 0, student=student) sys.exit(0) if 'quiz-total' == target: proc_hw(course, source = quizzes, target = 'quiz-total', print_grade = 0) sys.exit(0) if 'course' == target: calc_course_score(course, print_grade = 1) sys.exit(0) if 'mail-test' == target: course.mail_grades(student = 'gacs', intro="Your course grade has been changed. "+\ "I will take care of the grade change form.", exams = mail_exams) sys.exit(0) if 'mail' == target: confirm = raw_input("About to do mass mailing. Are you sure? (y/n): ") if 'y' == confirm[0]: for student in mail_students: course.mail_grades(student = student, exams = mail_exams) sys.exit(0) if 'submit' == target: for student in submit_students: course.submit_grades(students = [], exams = submit_exams) sys.exit(0) if 'custom' == target: # Fill in sys.exit(0) # Do the following in order: # grcomp --exam midterm-1 # Select midterm cuts. # grcomp --exam midterm-1 # # Diagn: # print 'ronguida:', course.get_score('midterm', 'ronguida') # grcomp --exam midterm-2 # Select midterm cuts. # grcomp --exam midterm-2 # grcomp --target midterm # grcomp --exam final # Select final cuts. # grcomp --exam final # grcomp --exam class-partic # Select class-partic cuts. # grcomp --exam class-partic # Get the homework files using late_discount, then # proceed as follows: # grcomp --exam homeworks # grcomp --target homework # select homework cuts # grcomp --exam homework # # proc1to5(course, 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 # grcomp --target course # modify final cuts, changing course.cuts.xcp. # grcomp --exam course # '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)