Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXAMPLE PR with pseudo code for filtering submissions count based on teams #8

Draft
wants to merge 1 commit into
base: pedrovgp/master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions openassessment/assessment/api/staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,19 @@ def get_submission_to_assess(course_id, item_id, scorer_id):
return None


def get_staff_grading_statistics(course_id, item_id):
def get_staff_grading_statistics(course_id, item_id, from_teams=None):
"""
Returns the number of graded, ungraded, and in-progress submissions for staff grading.

Args:
course_id (str): The course that this problem belongs to
item_id (str): The student_item (problem) that we want to know statistics about.
from_teams(Teams QuerySet): A queryset of Teams to restricted the counting to

Returns:
dict: a dictionary that contains the following keys: 'graded', 'ungraded', and 'in-progress'
"""
return StaffWorkflow.get_workflow_statistics(course_id, item_id)
return StaffWorkflow.get_workflow_statistics(course_id, item_id, from_teams=from_teams)


def create_assessment(
Expand Down
12 changes: 8 additions & 4 deletions openassessment/assessment/models/staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ def identifying_uuid(self):
return self.submission_uuid

@classmethod
def get_workflow_statistics(cls, course_id, item_id):
def get_workflow_statistics(cls, course_id, item_id, from_teams=None):
"""
Returns the number of graded, ungraded, and in-progress submissions for staff grading.

Args:
course_id (str): The course that this problem belongs to
item_id (str): The student_item (problem) that we want to know statistics about.
from_teams(Teams QuerySet): A queryset of Teams to restricted the counting to

Returns:
dict: a dictionary that contains the following keys: 'graded', 'ungraded', and 'in-progress'
Expand All @@ -78,16 +79,19 @@ def get_workflow_statistics(cls, course_id, item_id):
timeout = (now() - cls.TIME_LIMIT).strftime("%Y-%m-%d %H:%M:%S")
ungraded = cls.objects.filter(
models.Q(grading_started_at=None) | models.Q(grading_started_at__lte=timeout),
course_id=course_id, item_id=item_id, grading_completed_at=None, cancelled_at=None
course_id=course_id, item_id=item_id, grading_completed_at=None, cancelled_at=None,
teams_in=from_teams
).count()

in_progress = cls.objects.filter(
course_id=course_id, item_id=item_id, grading_completed_at=None, cancelled_at=None,
grading_started_at__gt=timeout
grading_started_at__gt=timeout,
teams_in=from_teams
).count()

graded = cls.objects.filter(
course_id=course_id, item_id=item_id, cancelled_at=None
course_id=course_id, item_id=item_id, cancelled_at=None,
teams_in=from_teams
).exclude(grading_completed_at=None).count()

return {'ungraded': ungraded, 'in-progress': in_progress, 'graded': graded}
Expand Down
32 changes: 30 additions & 2 deletions openassessment/xblock/staff_area_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ def get_staff_path_and_context(self):
return path, context

@staticmethod
def get_staff_assessment_statistics_context(course_id, item_id):
def get_staff_assessment_statistics_context(course_id, item_id, from_teams=None):
"""
Returns a context with staff assessment "ungraded" and "in-progress" counts.
"""
# Import is placed here to avoid model import at project startup.
from openassessment.assessment.api import staff as staff_api
grading_stats = staff_api.get_staff_grading_statistics(course_id, item_id)

# if from_teams, get grading stats only for the given teams
grading_stats = staff_api.get_staff_grading_statistics(course_id, item_id, from_teams=from_teams)

return {
'staff_assessment_ungraded': grading_stats['ungraded'],
Expand Down Expand Up @@ -372,6 +374,32 @@ def render_staff_grade_counts(self, data, suffix=''): # pylint: disable=W0613
except PeerAssessmentInternalError:
return self.render_error(self._("Error getting staff grade ungraded and checked out counts."))

@XBlock.handler
@require_course_staff("STUDENT_GRADE")
def render_staff_grade_counts_filtered_by_teams(self, data, suffix=''): # pylint: disable=W0613
"""
Renders a form to show the number of ungraded and checked out assessments,
considering team affiliation.

Must be course staff to render this view.
"""
try:
student_item_dict = self.get_student_item_dict()

# get teams from staff member
from_teams = Teams.objects.filter(user_id=staff_id)

context = self.get_staff_assessment_statistics_context(
student_item_dict.get('course_id'), student_item_dict.get('item_id'), from_teams=from_teams
)

path = 'openassessmentblock/staff_area/oa_staff_grade_learners_count.html'
return self.render_assessment(path, context)

except PeerAssessmentInternalError:
return self.render_error(self._("Error getting staff grade ungraded and checked out counts."))


def get_student_submission_context(self, student_username, submission):
"""
Get a context dict for rendering a student submission and associated rubric (for staff grading).
Expand Down
25 changes: 25 additions & 0 deletions openassessment/xblock/static/js/src/oa_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class Server {
this.studentInfo = this.studentInfo.bind(this);
this.staffGradeForm = this.staffGradeForm.bind(this);
this.staffGradeCounts = this.staffGradeCounts.bind(this);
this.staffGradeCountsFilteredByTeams = this.staffGradeCountsFilteredByTeams.bind(this);
this.submit = this.submit.bind(this);
this.save = this.save.bind(this);
this.submitFeedbackOnAssessment = this.submitFeedbackOnAssessment.bind(this);
Expand Down Expand Up @@ -183,6 +184,30 @@ export class Server {
}).promise();
}

/**
* Renders the count of ungraded and checked out assessemtns,
* but counting only students in the same teams as the staff member requesting it
*
* @returns {promise} A JQuery promise, which resolves with the HTML of the rendered section
* fails with an error message.
*/
staffGradeCountsFilteredByTeams() {
const url = this.url('render_staff_grade_counts_filtered_by_teams');
return $.Deferred((defer) => {
$.ajax({
url,
type: 'POST',
dataType: 'html',
}).done(function (data) {
defer.resolveWith(this, [data]);
}).fail(function () {
defer.rejectWith(
this, [gettext('The display of ungraded and checked out responses could not be loaded.')],
);
});
}).promise();
}

/**
* Send a submission to the XBlock.
*
Expand Down