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

Fixed weight ignore issue on grade calculation #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions edx_sga/sga.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ def enter_grade(self, request, suffix=''):
state['staff_score'] = score
state['comment'] = request.params.get('comment', '')
module.state = json.dumps(state)
# to fix score on edx progress page
module.grade = score
module.max_grade = self.max_score()
module.save()
log.info(
"enter_grade for course:%s module:%s student:%s",
Expand All @@ -463,6 +466,7 @@ def remove_grade(self, request, suffix=''):
self.block_id
)
module = self.get_student_module(request.params['module_id'])
module.grade = 0
state = json.loads(module.state)
state['staff_score'] = None
state['comment'] = ''
Expand Down Expand Up @@ -790,6 +794,7 @@ def student_state(self):
"max_score": self.max_score(),
"upload_allowed": self.upload_allowed(submission_data=submission),
"solution": solution,
'weight': self.weight,
"base_asset_url": StaticContent.get_base_url_path_for_course_assets(self.location.course_key),
}

Expand Down Expand Up @@ -846,6 +851,7 @@ def get_student_data():
return {
'assignments': list(get_student_data()),
'max_score': self.max_score(),
'weight': self.weight,
'display_name': force_text(self.display_name)
}

Expand Down
13 changes: 10 additions & 3 deletions edx_sga/templates/staff_graded_assignment/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
</p>
<p>
<% if (graded) { %>
{% blocktrans %}Your score is <%= graded.score %> / <%= max_score %>{% endblocktrans %}<br/>
<% if (weight > 0) { %>
{% blocktrans %}Your score is <%= (graded.score / max_score) * weight %> / <%= weight %>{% endblocktrans %}<br/>
<% } else { %>
{% blocktrans %}Your score is <%= graded.score %> / <%= max_score %>{% endblocktrans %}<br/>
<% } %>
<% if (graded.comment) { %>
<b>{% trans "Instructor comment" %}</b> <%= graded.comment %><br/>
<% } %>
Expand Down Expand Up @@ -100,8 +104,11 @@
</td>
<td>
<% if (assignment.score !== null) { %>
<%= assignment.score %> /
<%= max_score %>
<% if (weight > 0) { %>
<%= (assignment.score / max_score) * weight %> / <%= weight %>
<% } else { %>
<%= assignment.score %> / <%= max_score %>
<% } %>
<% if (! assignment.approved) { %>
({% trans "Awaiting instructor approval" %})
<% } %>
Expand Down
20 changes: 14 additions & 6 deletions edx_sga/tests/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def make_one(self, display_name=None, **kw):
"""
Creates a XBlock SGA for testing purpose.
"""
weight = kw.get('weight', 0)
field_data = DictFieldData(kw)
block = StaffGradedAssignmentXBlock(self.runtime, field_data, self.scope_ids)
block.location = Location(
Expand All @@ -126,6 +127,7 @@ def make_one(self, display_name=None, **kw):
block.display_name = display_name

block.start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.utc)
block.weight = weight
modulestore().create_item(
self.staff.username, block.location.course_key, block.location.block_type, block.location.block_id
)
Expand Down Expand Up @@ -231,7 +233,7 @@ def test_student_view(self, fragment, render_template):
"""
Test student view renders correctly.
"""
block = self.make_one("Custom name")
block = self.make_one("Custom name", weight=12)
self.personalize(block, **self.make_student(block, 'fred'))
fragment = block.student_view()
render_template.assert_called_once()
Expand All @@ -254,6 +256,7 @@ def test_student_view(self, fragment, render_template):
self.assertEqual(student_state['upload_allowed'], True)
self.assertEqual(student_state['max_score'], 100)
self.assertEqual(student_state['graded'], None)
assert student_state['weight'] == 12
fragment.add_css.assert_called_once_with(
DummyResource("static/css/edx_sga.css"))
fragment.initialize_js.assert_called_once_with(
Expand Down Expand Up @@ -385,7 +388,7 @@ def point_positive_int_test():
block.save_sga(mock.Mock(body='{}'))
self.assertEqual(block.display_name, "Staff Graded Assignment")
self.assertEqual(block.points, 100)
self.assertEqual(block.weight, None)
self.assertEqual(block.weight, 0)
block.save_sga(mock.Mock(method="POST", body=json.dumps({
"display_name": "Test Block",
"points": str(orig_score),
Expand Down Expand Up @@ -661,7 +664,7 @@ def test_get_staff_grading_data(self):
"""
Test fetch grading data for staff members.
"""
block = self.make_one()
block = self.make_one(weight=15)
barney = self.make_student(
block, "barney",
filename="foo.txt",
Expand All @@ -672,6 +675,7 @@ def test_get_staff_grading_data(self):
block, "fred",
filename="bar.txt")
data = block.get_staff_grading_data(None).json_body # lint-amnesty, pylint: disable=redefined-outer-name
assert data['weight'] == 15
assignments = sorted(data['assignments'], key=lambda x: x['username'])

barney_assignment, fred_assignment = assignments
Expand Down Expand Up @@ -757,8 +761,10 @@ def test_enter_grade_staff(self):
'submission_id': fred['submission']['uuid'],
'grade': 9,
'comment': "Good!"}))
state = json.loads(StudentModule.objects.get(
pk=fred['module'].id).state)
student_module = StudentModule.objects.get(pk=fred['module'].id)
state = json.loads(student_module.state)
assert student_module.grade == 9
assert student_module.max_grade == block.max_score()
self.assertEqual(state['comment'], 'Good!')
self.assertEqual(state['staff_score'], 9)

Expand Down Expand Up @@ -802,7 +808,9 @@ def test_remove_grade(self):
'student_id': item.student_id,
})
block.remove_grade(request)
state = json.loads(StudentModule.objects.get(pk=module.id).state)
student_module = StudentModule.objects.get(pk=module.id)
state = json.loads(student_module.state)
assert student_module.grade == 0
self.assertEqual(block.get_score(item.student_id), None)
self.assertEqual(state['comment'], '')

Expand Down