def get_workflow_status_counts(self): """ Retrieve the counts of students in each step of the workflow. Returns: tuple of (list, int), where the list contains dicts with keys "status" (unicode value) and "count" (int value), and the integer represents the total number of submissions. Example Usage: >>> status_counts, num_submissions = xblock.get_workflow_status_counts() >>> num_submissions 12 >>> status_counts [ {"status": "peer", "count": 2}, {"status": "self", "count": 1}, {"status": "waiting": "count": 4}, {"status": "done", "count": 5} ] """ student_item = self.get_student_item_dict() status_counts = workflow_api.get_status_counts( course_id=student_item['course_id'], item_id=student_item['item_id'], steps=self._create_step_list(), ) num_submissions = sum(item['count'] for item in status_counts) return status_counts, num_submissions
def test_get_status_counts(self): # Initially, the counts should all be zero counts = workflow_api.get_status_counts("test/1/1", "peer-problem", ["peer", "self"]) self.assertEqual(counts, [ {"status": "peer", "count": 0}, {"status": "self", "count": 0}, {"status": "waiting", "count": 0}, {"status": "done", "count": 0}, ]) # Create assessments with each status # We're going to cheat a little bit by using the model objects # directly, since the API does not provide access to the status directly. self._create_workflow_with_status("user 1", "test/1/1", "peer-problem", "peer") self._create_workflow_with_status("user 2", "test/1/1", "peer-problem", "self") self._create_workflow_with_status("user 3", "test/1/1", "peer-problem", "self") self._create_workflow_with_status("user 4", "test/1/1", "peer-problem", "waiting") self._create_workflow_with_status("user 5", "test/1/1", "peer-problem", "waiting") self._create_workflow_with_status("user 6", "test/1/1", "peer-problem", "waiting") self._create_workflow_with_status("user 7", "test/1/1", "peer-problem", "done") self._create_workflow_with_status("user 8", "test/1/1", "peer-problem", "done") self._create_workflow_with_status("user 9", "test/1/1", "peer-problem", "done") self._create_workflow_with_status("user 10", "test/1/1", "peer-problem", "done") # Now the counts should be updated counts = workflow_api.get_status_counts("test/1/1", "peer-problem", ["peer", "self"]) self.assertEqual(counts, [ {"status": "peer", "count": 1}, {"status": "self", "count": 2}, {"status": "waiting", "count": 3}, {"status": "done", "count": 4}, ]) # Create a workflow in a different course, same user and item # Counts should be the same self._create_workflow_with_status("user 1", "other_course", "peer-problem", "peer") updated_counts = workflow_api.get_status_counts("test/1/1", "peer-problem", ["peer", "self"]) self.assertEqual(counts, updated_counts) # Create a workflow in the same course, different item # Counts should be the same self._create_workflow_with_status("user 1", "test/1/1", "other problem", "peer") updated_counts = workflow_api.get_status_counts("test/1/1", "peer-problem", ["peer", "self"]) self.assertEqual(counts, updated_counts)
def staff_notification(): """ To send ORA statactics to staff users of course """ try: course_data = CourseOverview.objects.all() for cid in course_data: assessment_data = AssessmentWorkflow.objects.filter( course_id=cid.id) item_data = [] for sid in assessment_data: if not bool(staff.get_latest_staff_assessment(sid.submission_uuid)): if sid.item_id not in item_data: item_data.append(sid.item_id) # item_data = AssessmentWorkflow.objects.filter( # course_id=cid.id).values_list('item_id', flat=True) # item_data = list(set(item_data)) for iid in item_data: statistics = api.get_status_counts(cid.id, iid, ["staff", "peer", "done", "waiting"]) modified_statistics = dict() for stat in statistics: modified_statistics[stat.get('status')] = stat.get('count') statistics = modified_statistics if (( statistics['staff'] == 0 ) and ( statistics['peer'] == 0 ) and ( statistics['waiting'] == 0 )): return course_struct = None chapter_name = None try: course_struct = CourseStructure.objects.get(course_id=cid.id) except Exception as e: print "Unexpected error {0}".format(e) if course_struct: block = json.loads(course_struct.structure_json)['blocks'][iid] chapter_name = block['display_name'] staff_users = CourseAccessRole.objects.filter(course_id=cid.id, role='staff') try: usage_key = UsageKey.from_string(iid).replace(course_key=cid.id) (course_key, chapter, section, vertical_unused, position, final_target_id ) = path_to_location(modulestore(), usage_key) current_site_domain = 'http://{0}'.format(settings.SITE_NAME) courseware_url = current_site_domain+"/courses/"+str(cid.id)+"/courseware/"+chapter+"/"+section for u in staff_users: html_message = render_to_string('peer_grading/ora_report.html', {'status_counts': modified_statistics, 'course': cid.display_name, 'chapter_name' : chapter_name, 'user': u.user, 'courseware_url':courseware_url }) email = EmailMessage( "LYNX Online-Training: Neue Aufgaben zur Bewertung", html_message, to=[u.user.email]) email.send() TASK_LOG.info("----------Email message sent to course admins----------") except Exception as e: TASK_LOG.info("----------Inner Exception while sending staff notification----------") import traceback print traceback.format_exc() print e,"Inner Exception<-------" pass except Exception as e: import traceback print traceback.format_exc() print e,"<--- Error"