def test_get_single_peer_grading_item(self): for i in xrange(0,settings.MIN_TO_USE_PEER): test_sub = test_util.get_sub("PE", STUDENT_ID, LOCATION, "PE") test_sub.save() handle_submission(test_sub) test_grader = test_util.get_grader("IN") test_grader.submission=test_sub test_grader.save() test_sub.state = SubmissionState.finished test_sub.previous_grader_type = "IN" test_sub.posted_results_back_to_queue = True test_sub.save() test_sub = test_util.get_sub("PE", ALTERNATE_STUDENT, LOCATION, "PE") test_sub.save() handle_submission(test_sub) test_sub.is_duplicate = False test_sub.save() pl = peer_grading_util.PeerLocation(LOCATION, STUDENT_ID) found, grading_item = pl.next_item() self.assertEqual(found, True) pl = peer_grading_util.PeerLocation(LOCATION,"1") subs_graded = pl.graded()
def get_peer_grading_data_for_location(request): if request.method != 'GET': return util._error_response("Request type must be GET", _INTERFACE_VERSION) for tag in ['student_id', 'location']: if tag not in request.GET: return util._error_response("Missing required key {0}".format(tag), _INTERFACE_VERSION) location = request.GET.get('location') student_id = request.GET.get('student_id') pl = peer_grading_util.PeerLocation(location, student_id) student_sub_count = pl.submitted_count() submissions_graded = pl.graded_count() submissions_required = pl.required_count() submissions_available = pl.pending_count() peer_data = { 'count_graded': submissions_graded, 'count_required': submissions_required, 'student_sub_count': student_sub_count, 'count_available': submissions_available } util.log_connection_data() return util._success_response(peer_data, _INTERFACE_VERSION)
def test_get_next_submission_true(self): test_sub = test_util.get_sub("PE", "1", LOCATION, "PE") test_sub.save() grader = test_util.get_grader("BC") grader.submission = test_sub grader.grader_id = "2" grader.save() pl = peer_grading_util.PeerLocation(LOCATION, "1") control = SubmissionControl(pl.latest_submission()) for i in xrange(0, control.minimum_to_use_peer): test_sub = test_util.get_sub("PE", "1", LOCATION, "PE") test_sub.save() grader = test_util.get_grader("IN") grader.submission = test_sub grader.save() test_sub = test_util.get_sub("PE", STUDENT_ID, LOCATION, "PE") test_sub.save() content = self.c.get( GET_NEXT, data={ 'grader_id': STUDENT_ID, "location": LOCATION }, ) body = json.loads(content.content) self.assertEqual(body['success'], True)
def get_problem_list(request): """ Get the list of problems that need grading in course_id request.GET['course_id']. Returns: list of dicts with keys 'location' 'problem_name' 'num_graded' -- number graded 'num_pending' -- number pending in the queue """ if request.method != "GET": error_message = "Request needs to be GET." log.error(error_message) return util._error_response(error_message, _INTERFACE_VERSION) course_id = request.GET.get("course_id") student_id = request.GET.get("student_id") if not course_id or not student_id: error_message = "Missing needed tag course_id or student_id" log.error(error_message) return util._error_response(error_message, _INTERFACE_VERSION) locations_for_course = [ x['location'] for x in Submission.objects.filter( course_id=course_id).values('location').distinct() ] location_info = [] for location in locations_for_course: pl = peer_grading_util.PeerLocation(location, student_id) if pl.submitted_count() > 0: problem_name = pl.problem_name() submissions_pending = pl.pending_count() submissions_graded = pl.graded_count() submissions_required = max( [0, pl.required_count() - submissions_graded]) if (submissions_graded > 0 or submissions_pending > 0 or control_util.SubmissionControl.peer_grade_finished_subs( pl)): location_dict = { 'location': location, 'problem_name': problem_name, 'num_graded': submissions_graded, 'num_required': submissions_required, 'num_pending': submissions_pending, } location_info.append(location_dict) util.log_connection_data() return util._success_response({'problem_list': location_info}, _INTERFACE_VERSION)
def test_get_required(self): pl = peer_grading_util.PeerLocation(LOCATION, STUDENT_ID) student_required = pl.required_count() test_sub = test_util.get_sub("PE", ALTERNATE_STUDENT, LOCATION, "PE") test_sub.save() self.assertEqual(pl.required_count(), student_required) test_sub = test_util.get_sub("PE", STUDENT_ID, LOCATION, "PE") test_sub.save() self.assertEqual(pl.required_count(), settings.REQUIRED_PEER_GRADING_PER_STUDENT + student_required)
def get_next_submission(request): """ Gets next submission from controller for peer grading. Input: Get request with the following keys: grader_id - Student id of the grader location - The problem id to get peer grading for. """ if request.method != "GET": log.error("Improper request method") raise Http404 grader_id = request.GET.get("grader_id") location = request.GET.get("location") if not grader_id or not location: error_message = "Failed to find needed keys 'grader_id' and 'location'" log.error(error_message) return util._error_response(error_message, _INTERFACE_VERSION) pl = peer_grading_util.PeerLocation(location, grader_id) (found, sub_id) = pl.next_item() if not found: error_message = "You have completed all of the existing peer grading or there are no more submissions waiting to be peer graded." log.error(error_message) return util._error_response(error_message, _INTERFACE_VERSION) try: sub = Submission.objects.get(id=int(sub_id)) except Exception: log.exception("Could not find submission with id {0}".format(sub_id)) return util._error_response("Error getting grading.", _INTERFACE_VERSION) if sub.state != SubmissionState.being_graded: log.error( "Submission with id {0} has incorrect internal state {1}.".format( sub_id, sub.state)) return util._error_response("Error getting grading.", _INTERFACE_VERSION) response = { 'submission_id': sub_id, 'submission_key': sub.xqueue_submission_key, 'student_response': sub.student_response, 'prompt': sub.prompt, 'rubric': sub.rubric, 'max_score': sub.max_score, } return util._success_response(response, _INTERFACE_VERSION)
def test_submission_location(self): Submission.objects.all().delete() test_sub = test_util.get_sub("PE", STUDENT_ID, LOCATION, preferred_grader_type="PE") test_sub.save() test_grader = test_util.get_grader("BC") test_grader.submission = test_sub test_grader.save() pl = peer_grading_util.PeerLocation(LOCATION, STUDENT_ID) self.assertEqual(pl.submitted_count(), 1) self.assertEqual(pl.required_count(), settings.REQUIRED_PEER_GRADING_PER_STUDENT) test_sub2 = test_util.get_sub("PE", ALTERNATE_STUDENT, LOCATION, preferred_grader_type="PE") test_sub2.save() test_grader2 = test_util.get_grader("BC") test_grader2.submission = test_sub2 test_grader2.save() self.assertEqual(pl.pending_count(), 1) found, next_item_id = pl.next_item() self.assertEqual(next_item_id, test_sub2.id) test_sub2 = Submission.objects.get(id=next_item_id) self.assertEqual(SubmissionState.being_graded, test_sub2.state) test_grader3 = test_util.get_grader("PE") test_grader3.submission = test_sub2 test_grader3.grader_id = STUDENT_ID test_grader3.save() self.assertEqual(pl.graded_count(), 1) self.assertEqual(pl.pending_count(), 0)
def test_get_next_get_finished_subs(self): Submission.objects.all().delete() all_students = [STUDENT_ID, ALTERNATE_STUDENT, STUDENT3] # setup 3 submissions from 3 students, passed basic check submissions = [] for student in all_students: test_sub = test_util.get_sub("PE", student, LOCATION, preferred_grader_type="PE") test_sub.next_grader_type = "PE" test_sub.is_duplicate = False test_sub.save() submissions.append(test_sub) bc_grader = test_util.get_grader("BC") bc_grader.submission = test_sub bc_grader.save() # have them each grade the other two and call that finished for student in all_students: for submission in Submission.objects.all().exclude( student_id=student): test_grader = test_util.get_grader("PE") test_grader.grader_id = student test_grader.submission = submission test_grader.save() for sub in submissions: sub.state = SubmissionState.finished sub.posted_results_back_to_queue = True sub.save() pls = [] for student in all_students: pls.append(peer_grading_util.PeerLocation(LOCATION, student)) # check that each student graded 2, and so no submissions are pending for pl in pls: self.assertEqual(pl.graded_count(), 2) self.assertEqual(pl.pending_count(), 0) # check that next_item() cannot returns a submission because each of these students # has graded the submissions by the other 2 students found, _ = pl.next_item() self.assertFalse(found) # now a 4th student comes along and submits. They should get something to grade despite nothing pending student4 = "10" test_sub = test_util.get_sub("PE", student4, LOCATION, preferred_grader_type="PE") test_sub.next_grader_type = "PE" test_sub.is_duplicate = False test_sub.control_fields = json.dumps( {'peer_grade_finished_submissions_when_none_pending': True}) test_sub.save() pl4 = peer_grading_util.PeerLocation(LOCATION, student4) self.assertEqual(pl4.pending_count(), 0) found, next_sub_id = pl4.next_item() self.assertTrue(found) student4_sub_to_grade = Submission.objects.get(id=next_sub_id) self.assertIn(student4_sub_to_grade, submissions) self.assertEqual(student4_sub_to_grade.state, SubmissionState.being_graded)