Ejemplo n.º 1
0
def grade_new_submissions():
    print("Checking for new submissions")
    students = c.downloadAssignment(courseName=course_name, assignmentName=assignment_name,
            subdirName=homework_path, allowLate=True)
    print("Downloaded new submissions from {}".format(students))
    # Check if there's any students we failed to grade and comment on
    # and also grab their stuff to grade.
    for dir in next(os.walk(os.path.abspath(homework_path)))[1]:
        student_dir = os.path.abspath(homework_path + "/" + dir)
        if not os.path.isfile(student_dir + "/final_score.diff"):
            print("Student {} is missing their final score, will force regrade".format(dir))
            student_id = int(dir)
            if student_id not in students:
                students.append(int(dir))

    for student_id in students:
        student_dir = os.path.abspath(homework_path + "/" + str(student_id))
        print('Processing student ' + student_dir)
        os.chdir(student_dir)

        for name, problem in reference_soln.items():
            cl_stdout_file = name + '_cl.txt'
            stdin_file = ref_homework_dir + '/' + problem["stdin"]
            stdout_file = name + "_stdout.txt"
            ref_stdout_file = ref_homework_dir + '/' + problem["stdout"]
            result_file = name + '_results.txt'
            grade_file = name + '_grade.txt'

            # Compile the student's submission
            print('Compiling ' + name)
            grading.compile(cl_stdout_file, problem, name)

            # Run the student's submission
            exe = name + '.exe'
            print('Running ' + exe)
            grading.run_student(exe, stdin_file, stdout_file, cl_stdout_file)

            # Check the student's submision
            print('Checking ' + name)
            # Compare the student's output to our expected output
            grading.compare(ref_stdout_file, stdout_file, result_file)
            # count the number of warnings and errors
            grading.count_warnings_errors(cl_stdout_file, result_file)

            # Compile the grading document but don't assign a grade to the student
            # since the server has no idea what grade to assign
            grading.grade(problem, stdout_file, result_file, grade_file, ref_stdout_file, None)

        # Build the final score file
        print("Building final score for " + student_dir)
        graded_files = [f for f in next(os.walk(student_dir))[2]]
        grading.build_final_score(graded_files, reference_soln, None)
        # Upload their grade
        grading.upload_grade(c, False)
        # CD back up out of the student's directory
        os.chdir("..")
        if student_id not in student_submission_count:
            student_submission_count[student_id] = 1
        else:
            student_submission_count[student_id] += 1

    now = datetime.datetime.now()
    print("Students graded for {}".format(now))
Ejemplo n.º 2
0
for dir in next(os.walk(homework_dir))[1]:
    num_students += 1

# Collect the list of all student directories
print(homework_dir)
current_student = 1
for dir in next(os.walk(homework_dir))[1]:
    student_dir = os.path.abspath(homework_dir + '/' + dir)
    print('Processing student id {} progress {}/{}'.format(student_dir, current_student, num_students))
    current_student += 1
    os.chdir(student_dir)
    files = [f for f in next(os.walk(student_dir))[2]]
    # Collect the list of all of the student's files if we're uploading their
    # total score
    if sys.argv[2] == 'upload':
        grading.upload_grade(c)
        continue
    elif sys.argv[2] == 'stats':
        grade_stats.append(grading.compute_total_score(files, reference_soln))
        continue

    for name, problem in reference_soln.items():
        # If a file name is provided, skip other files
        if len(sys.argv) > 3 and name != sys.argv[3]:
            continue

        cl_stdout_file = name + '_cl.txt'
        stdin_file = ref_homework_dir + '/' + problem["stdin"]
        stdout_file = name + "_stdout.txt"
        ref_stdout_file = ref_homework_dir + '/' + problem["stdout"]
        result_file = name + '_results.txt'