本文整理汇总了Python中submissions.api.reset_score函数的典型用法代码示例。如果您正苦于以下问题:Python reset_score函数的具体用法?Python reset_score怎么用?Python reset_score使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reset_score函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_grade
def remove_grade(self, request, suffix=''):
# pylint: disable=unused-argument
"""
Reset a students score request by staff.
"""
require(self.is_course_staff())
student_id = request.params['student_id']
submissions_api.reset_score(student_id, self.course_id, self.block_id)
module = StudentModule.objects.get(pk=request.params['module_id'])
state = json.loads(module.state)
state['staff_score'] = None
state['comment'] = ''
state['annotated_sha1'] = None
state['annotated_filename'] = None
state['annotated_mimetype'] = None
state['annotated_timestamp'] = None
module.state = json.dumps(state)
module.save()
log.info(
"remove_grade for course:%s module:%s student:%s",
module.course_id,
module.module_state_key,
module.student.username
)
return Response(json_body=self.staff_grading_data())
示例2: test_reset_different_student_item
def test_reset_different_student_item(self, changed):
# Create a submissions for two students
submission = sub_api.create_submission(self.STUDENT_ITEM, "test answer")
sub_api.set_score(submission["uuid"], 1, 2)
other_student = copy.copy(self.STUDENT_ITEM)
other_student.update(changed)
submission = sub_api.create_submission(other_student, "other test answer")
sub_api.set_score(submission["uuid"], 3, 4)
# Reset the score for the first student
sub_api.reset_score(
self.STUDENT_ITEM["student_id"], self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["item_id"]
)
# The first student's scores should be reset
self.assertIs(sub_api.get_score(self.STUDENT_ITEM), None)
scores = sub_api.get_scores(self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["student_id"])
self.assertNotIn(self.STUDENT_ITEM["item_id"], scores)
# But the second student should still have a score
score = sub_api.get_score(other_student)
self.assertEqual(score["points_earned"], 3)
self.assertEqual(score["points_possible"], 4)
scores = sub_api.get_scores(other_student["course_id"], other_student["student_id"])
self.assertIn(other_student["item_id"], scores)
示例3: set_staff_score
def set_staff_score(self, score, reason=None):
"""
Set a staff score for the workflow.
Allows for staff scores to be set on a submission, with annotations to provide an audit trail if needed.
This method can be used for both required staff grading, and staff overrides.
Args:
score (dict): A dict containing 'points_earned', 'points_possible', and 'staff_id'.
is_override (bool): Optionally True if staff is overriding a previous score.
reason (string): An optional parameter specifying the reason for the staff grade. A default value
will be used in the event that this parameter is not provided.
"""
if reason is None:
reason = "A staff member has defined the score for this submission"
sub_dict = sub_api.get_submission_and_student(self.submission_uuid)
sub_api.reset_score(
sub_dict['student_item']['student_id'],
self.course_id,
self.item_id,
emit_signal=False
)
sub_api.set_score(
self.submission_uuid,
score["points_earned"],
score["points_possible"],
annotation_creator=score["staff_id"],
annotation_type=self.STAFF_ANNOTATION_TYPE,
annotation_reason=reason
)
示例4: clear_student_state
def clear_student_state(self, user_id, course_id, item_id):
"""
This xblock method is called (from our LMS runtime, which defines this method signature) to clear student state
for a given problem. It will cancel the workflow using traditional methods to remove it from the grading pools,
and pass through to the submissions API to orphan the submission so that the user can create a new one.
"""
# Note that student_item cannot be constructed using get_student_item_dict, since we're in a staff context
student_item = {
'course_id': course_id,
'student_id': user_id,
'item_id': item_id,
'item_type': 'openassessment',
}
# There *should* only be one submission, but the logic is easy to extend for multiples so we may as well do it
submissions = submission_api.get_submissions(student_item)
for sub in submissions:
# Remove the submission from grading pools
self._cancel_workflow(sub['uuid'], "Student state cleared")
# Tell the submissions API to orphan the submission to prevent it from being accessed
submission_api.reset_score(
user_id,
course_id,
item_id,
clear_state=True # pylint: disable=unexpected-keyword-arg
)
示例5: test_reset_with_no_scores
def test_reset_with_no_scores(self):
sub_api.reset_score(
self.STUDENT_ITEM["student_id"], self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["item_id"]
)
self.assertIs(sub_api.get_score(self.STUDENT_ITEM), None)
scores = sub_api.get_scores(self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["student_id"])
self.assertEqual(len(scores), 0)
示例6: test_database_error
def test_database_error(self, create_mock):
# Create a submission for the student and score it
submission = sub_api.create_submission(self.STUDENT_ITEM, "test answer")
sub_api.set_score(submission["uuid"], 1, 2)
# Simulate a database error when creating the reset score
create_mock.side_effect = DatabaseError("Test error")
with self.assertRaises(sub_api.SubmissionInternalError):
sub_api.reset_score(
self.STUDENT_ITEM["student_id"], self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["item_id"]
)
示例7: reset_student_attempts
def reset_student_attempts(course_id, student, module_state_key, delete_module=False):
"""
Reset student attempts for a problem. Optionally deletes all student state for the specified problem.
In the previous instructor dashboard it was possible to modify/delete
modules that were not problems. That has been disabled for safety.
`student` is a User
`problem_to_reset` is the name of a problem e.g. 'L2Node1'.
To build the module_state_key 'problem/' and course information will be appended to `problem_to_reset`.
Raises:
ValueError: `problem_state` is invalid JSON.
StudentModule.DoesNotExist: could not load the student module.
submissions.SubmissionError: unexpected error occurred while resetting the score in the submissions API.
"""
user_id = anonymous_id_for_user(student, course_id)
submission_cleared = False
try:
# A block may have children. Clear state on children first.
block = modulestore().get_item(module_state_key)
if block.has_children:
for child in block.children:
try:
reset_student_attempts(course_id, student, child, delete_module=delete_module)
except StudentModule.DoesNotExist:
# If a particular child doesn't have any state, no big deal, as long as the parent does.
pass
if delete_module:
# Some blocks (openassessment) use StudentModule data as a key for internal submission data.
# Inform these blocks of the reset and allow them to handle their data.
clear_student_state = getattr(block, "clear_student_state", None)
if callable(clear_student_state):
clear_student_state(user_id=user_id, course_id=unicode(course_id), item_id=unicode(module_state_key))
submission_cleared = True
except ItemNotFoundError:
log.warning("Could not find %s in modulestore when attempting to reset attempts.", module_state_key)
# Reset the student's score in the submissions API, if xblock.clear_student_state has not done so already.
# TODO: Remove this once we've finalized and communicated how xblocks should handle clear_student_state
# and made sure that other xblocks relying on the submission api understand this is going away.
# We need to do this before retrieving the `StudentModule` model, because a score may exist with no student module.
if delete_module and not submission_cleared:
sub_api.reset_score(user_id, course_id.to_deprecated_string(), module_state_key.to_deprecated_string())
module_to_reset = StudentModule.objects.get(
student_id=student.id, course_id=course_id, module_state_key=module_state_key
)
if delete_module:
module_to_reset.delete()
else:
_reset_module_attempts(module_to_reset)
示例8: test_reset_then_get_score_for_submission
def test_reset_then_get_score_for_submission(self):
# Create a submission for the student and score it
submission = sub_api.create_submission(self.STUDENT_ITEM, "test answer")
sub_api.set_score(submission["uuid"], 1, 2)
# Reset scores
sub_api.reset_score(
self.STUDENT_ITEM["student_id"], self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["item_id"]
)
# If we're retrieving the score for a particular submission,
# instead of a student item, then we should STILL get a score.
self.assertIsNot(sub_api.get_latest_score_for_submission(submission["uuid"]), None)
示例9: reset_student_attempts
def reset_student_attempts(course_id, student, module_state_key, delete_module=False):
"""
Reset student attempts for a problem. Optionally deletes all student state for the specified problem.
In the previous instructor dashboard it was possible to modify/delete
modules that were not problems. That has been disabled for safety.
`student` is a User
`problem_to_reset` is the name of a problem e.g. 'L2Node1'.
To build the module_state_key 'problem/' and course information will be appended to `problem_to_reset`.
Raises:
ValueError: `problem_state` is invalid JSON.
StudentModule.DoesNotExist: could not load the student module.
submissions.SubmissionError: unexpected error occurred while resetting the score in the submissions API.
"""
try:
# A block may have children. Clear state on children first.
block = modulestore().get_item(module_state_key)
if block.has_children:
for child in block.children:
try:
reset_student_attempts(course_id, student, child, delete_module=delete_module)
except StudentModule.DoesNotExist:
# If a particular child doesn't have any state, no big deal, as long as the parent does.
pass
except ItemNotFoundError:
log.warning("Could not find %s in modulestore when attempting to reset attempts.", module_state_key)
# Reset the student's score in the submissions API
# Currently this is used only by open assessment (ORA 2)
# We need to do this *before* retrieving the `StudentModule` model,
# because it's possible for a score to exist even if no student module exists.
if delete_module:
sub_api.reset_score(
anonymous_id_for_user(student, course_id),
course_id.to_deprecated_string(),
module_state_key.to_deprecated_string(),
)
module_to_reset = StudentModule.objects.get(
student_id=student.id,
course_id=course_id,
module_state_key=module_state_key
)
if delete_module:
module_to_reset.delete()
else:
_reset_module_attempts(module_to_reset)
示例10: test_reset_with_one_score
def test_reset_with_one_score(self):
# Create a submission for the student and score it
submission = sub_api.create_submission(self.STUDENT_ITEM, "test answer")
sub_api.set_score(submission["uuid"], 1, 2)
# Reset scores
sub_api.reset_score(
self.STUDENT_ITEM["student_id"], self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["item_id"]
)
# Expect that no scores are available for the student
self.assertIs(sub_api.get_score(self.STUDENT_ITEM), None)
scores = sub_api.get_scores(self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["student_id"])
self.assertEqual(len(scores), 0)
示例11: remove_grade
def remove_grade(self, request, suffix=''):
require(self.is_course_staff())
student_id = request.params['student_id']
submissions_api.reset_score(student_id, self.course_id, self.block_id)
module = StudentModule.objects.get(pk=request.params['module_id'])
state = json.loads(module.state)
state['staff_score'] = None
state['comment'] = ''
state['annotated_sha1'] = None
state['annotated_filename'] = None
state['annotated_mimetype'] = None
state['annotated_timestamp'] = None
module.state = json.dumps(state)
module.save()
return Response(json_body=self.staff_grading_data())
示例12: test_reset_with_multiple_scores
def test_reset_with_multiple_scores(self):
# Create a submission for the student and score it
submission = sub_api.create_submission(self.STUDENT_ITEM, 'test answer')
sub_api.set_score(submission['uuid'], 1, 2)
sub_api.set_score(submission['uuid'], 2, 2)
# Reset scores
sub_api.reset_score(
self.STUDENT_ITEM['student_id'],
self.STUDENT_ITEM['course_id'],
self.STUDENT_ITEM['item_id'],
)
# Expect that no scores are available for the student
self.assertIs(sub_api.get_score(self.STUDENT_ITEM), None)
scores = sub_api.get_scores(self.STUDENT_ITEM['course_id'], self.STUDENT_ITEM['student_id'])
self.assertEqual(len(scores), 0)
示例13: test_reset_score_signal
def test_reset_score_signal(self, send_mock):
# Create a submission for the student and score it
submission = sub_api.create_submission(self.STUDENT_ITEM, 'test answer')
sub_api.set_score(submission['uuid'], 1, 2)
# Reset scores
sub_api.reset_score(
self.STUDENT_ITEM['student_id'],
self.STUDENT_ITEM['course_id'],
self.STUDENT_ITEM['item_id'],
)
# Verify that the send method was properly called
send_mock.assert_called_with(
sender = None,
anonymous_user_id=self.STUDENT_ITEM['student_id'],
course_id=self.STUDENT_ITEM['course_id'],
item_id=self.STUDENT_ITEM['item_id']
)
示例14: test_clear_state
def test_clear_state(self):
# Create a submission, give it a score, and verify that score exists
submission = api.create_submission(STUDENT_ITEM, ANSWER_ONE)
api.set_score(submission["uuid"], 11, 12)
score = api.get_score(STUDENT_ITEM)
self._assert_score(score, 11, 12)
self.assertEqual(score['submission_uuid'], submission['uuid'])
# Reset the score with clear_state=True
# This should set the submission's score to None, and make it unavailable to get_submissions
api.reset_score(
STUDENT_ITEM["student_id"],
STUDENT_ITEM["course_id"],
STUDENT_ITEM["item_id"],
clear_state=True,
)
score = api.get_score(STUDENT_ITEM)
self.assertIsNone(score)
subs = api.get_submissions(STUDENT_ITEM)
self.assertEqual(subs, [])
示例15: test_override_after_reset_score
def test_override_after_reset_score(self):
# Create a submission for the student and score it
submission = sub_api.create_submission(self.STUDENT_ITEM, 'test answer')
sub_api.set_score(submission['uuid'], 1, 10)
# Reset score
sub_api.reset_score(
self.STUDENT_ITEM['student_id'],
self.STUDENT_ITEM['course_id'],
self.STUDENT_ITEM['item_id'],
)
sub_api.score_override(
self.STUDENT_ITEM,
5,
10,
)
self.assertEqual(sub_api.get_score(self.STUDENT_ITEM)['points_earned'], 5)
self.assertEqual(sub_api.get_score(self.STUDENT_ITEM)['points_possible'], 10)