#!/usr/bin/env python3 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_new import * import config_cs330s20 from config_cs330s20 import * # ----------- constants, depend on the course ----------------- # ------------- 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) """ 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. 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 phd-extras select phd-extras cuts grcomp --exam phd-extras grcomp --target course-phd --student sowmya (for diagn) modify course-phd.cuts into course-phd.cuts.xcp grcomp --exam course-phd """ # # 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 main(): progname = os.path.basename(sys.argv[0]) argc = len(sys.argv) course_name = Config.course_name exam_data = Config.exam_data default_list = Config.default_list if 2 > argc: usage(progname) long_optlist = ["help", "custom", "course", "distr", "exam=", "exams=", "target=", "method=","student=","student-list="] options, restargs = getopt_map("x", long_optlist) if "--help" in options: usage(sys.argv[0]) if "--course" in options: course_name = options["course"] else: cwd = os.getcwd() cwdlist = cwd.split(os.sep) course_name = cwdlist[-2] if "--student" in options: show_student = options["--student"] warn("Showing results for "+show_student) else: show_student = "" if "--student-list" in options: student_list = options["--student-list"] else: student_list = "rst" course = Course.Course(course_name = course_name, exam_data=exam_data, default_list = default_list) if "--exam" in options: exam_name = options["--exam"] # if "homeworks" == exam_name or "quizzes" == exam_name: # for hw in multipart[exam_name]: # course.proc_exam(exam_name = hw, print_grade = 0, only_by_score = 1) # else: course.proc_exam(exam_name = exam_name) if "--distr" in options: course.get_exam(exam_name).print_records(only_distr = True) if "--exams" in options: # More exams must be in a quoted string, separated by whitespace. exam_names = options["--exams"].split() print("exam_names=") print(exam_names) course.print_student_data_list(exam_names, 'output') if "--target" in options: target = options["--target"] target_name = target if "best-homework" == target: target_exam = course.get_exam('homework') target_name = 'homework' else: target_exam = course.get_exam(target) exam_details = exam_data[target_name] if 'sources' not in exam_details: warn('Exam '+target_name+' has no sources.' ) return sources = exam_details['sources'] if "best-homework" == target: proc_best_hw(course, target = "homework", sources = sources, delete_worst=1, print_grade = False, show_student=show_student) # elif "midterm" == target: # course.exams_better(exam_names = ["midterm-1", "midterm-2"], # target = "midterm") # course.proc_exam(exam = "midterm") # elif "hw1to5" == target: # proc1to5(course, 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_name, show_student = show_student, print_grade = True, student_list=student_list) elif 'phd-extras'==target: calc_target(course, target=target_name, show_student = show_student, print_grade = True) elif "phd-midterm"==target: calc_target(course, target=target_name, show_student = show_student, print_grade = True) elif "course-phd"==target: calc_target(course, target=target_name, show_student = show_student, print_grade = True) elif "course-nonphd"==target: calc_target(course, target=target_name, show_student = show_student, print_grade = True) else: proc_hw(course, target = target_name, sources = sources, print_grade = False, show_student=show_student) # 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) def proc_best_hw(course, target, sources={}, delete_worst=True, print_grade=False, show_student = ""): target_exam = course.get_exam(target) warn("Adding the best scores for %s" % (target)) course.exams_sum_best_scores(target, sources = sources, delete_worst = delete_worst, show_student = show_student ) target_exam.print_records(sorted_by = "score", target = target, print_name = True, print_grade = print_grade, show_student = show_student, precision = 0 ) target_exam.print_cuts() def proc_hw(course, target = 'homework', sources={}, # should get a value! print_grade = False, show_student = ""): warn("Adding up scores") course.exams_calc_average(target = target, sources = sources, show_student = show_student, grades = False ) hw = course.get_exam(target) hw.calc_grades() warn("Printing "+target+" ...") hw.print_records(sorted_by = "score", target = target, print_name = True, print_grade = print_grade, show_student = show_student ) def calc_extra_info(course, target="absences", source=[], # should get a value, was 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 = True, print_grade = False, show_student = show_student ) def calc_target(course, target = 'course', show_student = '', print_grade = True, student_list = 'rst'): target_details = course.exam_data[target] if 'list' in target_details: student_list = target_details['list'] target_exam = course.get_exam(target) course.exams_calc_average(target = target, sources = target_details['sources'], show_student = show_student, student_list = student_list ) target_exam.print_records(sorted_by = 'score', target = target, print_name = True, print_grade = print_grade, show_student = show_student, ) target_exam.print_cuts() target_exam.read_cuts() # to read possibly course.cuts.xcp # --------------------- main ----------------------- # The executed part if __name__ == "__main__": main()