def get_ora2_responses(self, request, suffix=''): # pylint: disable=unused-argument """ Get information about all ora2 blocks in the course with response count for each step. """ responses = OraAggregateData.collect_ora2_responses( unicode(self.course_id)) return Response(json.dumps(responses), content_type='application/json')
def get_ora2_responses(self, request, suffix=''): # pylint: disable=unused-argument """ Get information about all ora2 blocks in the course with response count for each step. """ # Import is placed here to avoid model import at project startup. from openassessment.data import OraAggregateData responses = OraAggregateData.collect_ora2_responses(six.text_type(self.course_id)) return Response(json.dumps(responses), content_type='application/json', charset='UTF-8')
def get_ora2_responses(self, request, suffix=''): # pylint: disable=unused-argument """ Get information about all ora2 blocks in the course with response count for each step. """ # Import is placed here to avoid model import at project startup. from openassessment.data import OraAggregateData responses = OraAggregateData.collect_ora2_responses(unicode(self.course_id)) return Response(json.dumps(responses), content_type='application/json')
def test_collect_ora2_responses(self): item_id2 = self._other_item(2) item_id3 = self._other_item(3) student_id2 = self._other_student(2) student_id3 = self._other_student(3) self._create_submission(dict( student_id=STUDENT_ID, course_id=COURSE_ID, item_id=item_id2, item_type="openassessment" ), ['self']) self._create_submission(dict( student_id=student_id2, course_id=COURSE_ID, item_id=item_id2, item_type="openassessment" ), STEPS) self._create_submission(dict( student_id=STUDENT_ID, course_id=COURSE_ID, item_id=item_id3, item_type="openassessment" ), ['self']) self._create_submission(dict( student_id=student_id2, course_id=COURSE_ID, item_id=item_id3, item_type="openassessment" ), ['self']) self._create_submission(dict( student_id=student_id3, course_id=COURSE_ID, item_id=item_id3, item_type="openassessment" ), STEPS) data = OraAggregateData.collect_ora2_responses(COURSE_ID) self.assertIn(ITEM_ID, data) self.assertIn(item_id2, data) self.assertIn(item_id3, data) for item in [ITEM_ID, item_id2, item_id3]: self.assertEqual({'total', 'training', 'peer', 'self', 'staff', 'waiting', 'done', 'cancelled'}, set(data[item].keys())) self.assertEqual(data[ITEM_ID], { 'total': 2, 'training': 0, 'peer': 2, 'self': 0, 'staff': 0, 'waiting': 0, 'done': 0, 'cancelled': 0 }) self.assertEqual(data[item_id2], { 'total': 2, 'training': 0, 'peer': 1, 'self': 1, 'staff': 0, 'waiting': 0, 'done': 0, 'cancelled': 0 }) self.assertEqual(data[item_id3], { 'total': 3, 'training': 0, 'peer': 1, 'self': 2, 'staff': 0, 'waiting': 0, 'done': 0, 'cancelled': 0 }) data = OraAggregateData.collect_ora2_responses(COURSE_ID, ['staff', 'peer']) self.assertIn(ITEM_ID, data) self.assertIn(item_id2, data) self.assertIn(item_id3, data) for item in [ITEM_ID, item_id2, item_id3]: self.assertEqual({'total', 'peer', 'staff'}, set(data[item].keys())) self.assertEqual(data[ITEM_ID], {'total': 2, 'peer': 2, 'staff': 0}) self.assertEqual(data[item_id2], {'total': 1, 'peer': 1, 'staff': 0}) self.assertEqual(data[item_id3], {'total': 1, 'peer': 1, 'staff': 0})
def test_collect_ora2_responses(self): item_id2 = self._other_item(2) item_id3 = self._other_item(3) team_item_id = self._other_item(4) student_id2 = self._other_student(2) student_id3 = self._other_student(3) team_1_ids = [STUDENT_ID, student_id2, student_id3] student_id4 = self._other_student(4) student_id5 = self._other_student(5) team_2_ids = [student_id4, student_id5] student_model_1 = UserFactory.create() student_model_2 = UserFactory.create() self._create_submission( dict(student_id=STUDENT_ID, course_id=COURSE_ID, item_id=item_id2, item_type="openassessment"), ['self']) self._create_submission( dict(student_id=student_id2, course_id=COURSE_ID, item_id=item_id2, item_type="openassessment"), STEPS) self._create_submission( dict(student_id=STUDENT_ID, course_id=COURSE_ID, item_id=item_id3, item_type="openassessment"), ['self']) self._create_submission( dict(student_id=student_id2, course_id=COURSE_ID, item_id=item_id3, item_type="openassessment"), ['self']) self._create_submission( dict(student_id=student_id3, course_id=COURSE_ID, item_id=item_id3, item_type="openassessment"), STEPS) self._create_team_submission( COURSE_ID, team_item_id, 'team_1', student_model_1.id, team_1_ids, ) self._create_team_submission(COURSE_ID, team_item_id, 'team_2', student_model_2.id, team_2_ids) data = OraAggregateData.collect_ora2_responses(COURSE_ID) self.assertIn(ITEM_ID, data) self.assertIn(item_id2, data) self.assertIn(item_id3, data) self.assertIn(team_item_id, data) for item in [ITEM_ID, item_id2, item_id3, team_item_id]: self.assertEqual( { 'total', 'training', 'peer', 'self', 'staff', 'waiting', 'done', 'cancelled', 'teams' }, set(data[item].keys())) self.assertEqual( data[ITEM_ID], { 'total': 2, 'training': 0, 'peer': 2, 'self': 0, 'staff': 0, 'waiting': 0, 'done': 0, 'cancelled': 0, 'teams': 0 }) self.assertEqual( data[item_id2], { 'total': 2, 'training': 0, 'peer': 1, 'self': 1, 'staff': 0, 'waiting': 0, 'done': 0, 'cancelled': 0, 'teams': 0 }) self.assertEqual( data[item_id3], { 'total': 3, 'training': 0, 'peer': 1, 'self': 2, 'staff': 0, 'waiting': 0, 'done': 0, 'cancelled': 0, 'teams': 0 }) self.assertEqual( data[team_item_id], { 'total': 2, 'training': 0, 'peer': 0, 'self': 0, 'staff': 0, 'waiting': 0, 'done': 0, 'cancelled': 0, 'teams': 2 }) data = OraAggregateData.collect_ora2_responses(COURSE_ID, ['staff', 'peer']) self.assertIn(ITEM_ID, data) self.assertIn(item_id2, data) self.assertIn(item_id3, data) for item in [ITEM_ID, item_id2, item_id3]: self.assertEqual({'total', 'peer', 'staff'}, set(data[item].keys())) self.assertEqual(data[ITEM_ID], {'total': 2, 'peer': 2, 'staff': 0}) self.assertEqual(data[item_id2], {'total': 1, 'peer': 1, 'staff': 0}) self.assertEqual(data[item_id3], {'total': 1, 'peer': 1, 'staff': 0})