本文整理汇总了Python中submissions.api.set_score函数的典型用法代码示例。如果您正苦于以下问题:Python set_score函数的具体用法?Python set_score怎么用?Python set_score使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_score函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_student
def make_student(self, block, name, **state):
answer = {}
for key in ("sha1", "mimetype", "filename"):
if key in state:
answer[key] = state.pop(key)
score = state.pop("score", None)
user = User(username=name)
user.save()
profile = UserProfile(user=user, name=name)
profile.save()
module = StudentModule(
module_state_key=block.location, student=user, course_id=self.course_id, state=json.dumps(state)
)
module.save()
anonymous_id = anonymous_id_for_user(user, self.course_id)
item = StudentItem(student_id=anonymous_id, course_id=self.course_id, item_id=block.block_id, item_type="sga")
item.save()
if answer:
student_id = block.student_submission_id(anonymous_id)
submission = submissions_api.create_submission(student_id, answer)
if score is not None:
submissions_api.set_score(submission["uuid"], score, block.max_score())
else:
submission = None
self.addCleanup(item.delete)
self.addCleanup(profile.delete)
self.addCleanup(module.delete)
self.addCleanup(user.delete)
return {"module": module, "item": item, "submission": submission}
示例2: _check_if_finished_and_create_score
def _check_if_finished_and_create_score(student_item,
submission,
required_evaluations_for_student,
required_evaluations_for_submission):
"""Basic function for checking if a student is finished with peer workflow.
Checks if the student is finished with the peer evaluation workflow. If the
student already has a final grade calculated, there is no need to proceed.
If they do not have a grade, the student has a final grade calculated.
"""
if Score.objects.filter(student_item=student_item):
return
finished_evaluating = has_finished_required_evaluating(
student_item.student_id,
required_evaluations_for_student
)
evaluations = PeerEvaluation.objects.filter(submission=submission)
submission_finished = evaluations.count() >= required_evaluations_for_submission
scores = []
for evaluation in evaluations:
scores.append(evaluation.points_earned)
if finished_evaluating and submission_finished:
submission_api.set_score(
StudentItemSerializer(student_item).data,
SubmissionSerializer(submission).data,
_calculate_final_score(scores),
evaluations[0].points_possible
)
示例3: test_delete_submission_scores
def test_delete_submission_scores(self, _lti_mock):
user = UserFactory()
problem_location = self.course_key.make_usage_key("dummy", "module")
# Create a student module for the user
StudentModule.objects.create(
student=user, course_id=self.course_key, module_state_key=problem_location, state=json.dumps({})
)
# Create a submission and score for the student using the submissions API
student_item = {
"student_id": anonymous_id_for_user(user, self.course_key),
"course_id": self.course_key.to_deprecated_string(),
"item_id": problem_location.to_deprecated_string(),
"item_type": "openassessment",
}
submission = sub_api.create_submission(student_item, "test answer")
sub_api.set_score(submission["uuid"], 1, 2)
# Delete student state using the instructor dash
reset_student_attempts(self.course_key, user, problem_location, requesting_user=user, delete_module=True)
# Verify that the student's scores have been reset in the submissions API
score = sub_api.get_score(student_item)
self.assertIs(score, None)
示例4: enter_grade
def enter_grade(self, request, suffix=''):
# pylint: disable=unused-argument
"""
Persist a score for a student given by staff.
"""
require(self.is_course_staff())
module = StudentModule.objects.get(pk=request.params['module_id'])
state = json.loads(module.state)
score = int(request.params['grade'])
if self.is_instructor():
uuid = request.params['submission_id']
submissions_api.set_score(uuid, score, self.max_score())
else:
state['staff_score'] = score
state['comment'] = request.params.get('comment', '')
module.state = json.dumps(state)
module.save()
log.info(
"enter_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())
示例5: test_delete_student_state_resets_scores
def test_delete_student_state_resets_scores(self):
item_id = 'i4x://MITx/999/openassessment/b3dce2586c9c4876b73e7f390e42ef8f'
# Create a student module for the user
StudentModule.objects.create(
student=self.student, course_id=self.course.id, module_state_key=item_id, state=json.dumps({})
)
# Create a submission and score for the student using the submissions API
student_item = {
'student_id': anonymous_id_for_user(self.student, self.course.id),
'course_id': self.course.id,
'item_id': item_id,
'item_type': 'openassessment'
}
submission = sub_api.create_submission(student_item, 'test answer')
sub_api.set_score(submission['uuid'], 1, 2)
# Delete student state using the instructor dash
url = reverse('instructor_dashboard_legacy', kwargs={'course_id': self.course.id})
response = self.client.post(url, {
'action': 'Delete student state for module',
'unique_student_identifier': self.student.email,
'problem_for_student': 'openassessment/b3dce2586c9c4876b73e7f390e42ef8f',
})
self.assertEqual(response.status_code, 200)
# Verify that the student's scores have been reset in the submissions API
score = sub_api.get_score(student_item)
self.assertIs(score, None)
示例6: test_get_scores
def test_get_scores(self):
student_item = copy.deepcopy(STUDENT_ITEM)
student_item["course_id"] = "get_scores_course"
student_item["item_id"] = "i4x://a/b/c/s1"
s1 = api.create_submission(student_item, "Hello World")
student_item["item_id"] = "i4x://a/b/c/s2"
s2 = api.create_submission(student_item, "Hello World")
student_item["item_id"] = "i4x://a/b/c/s3"
s3 = api.create_submission(student_item, "Hello World")
api.set_score(s1['uuid'], 3, 5)
api.set_score(s1['uuid'], 4, 5)
api.set_score(s1['uuid'], 2, 5) # Should overwrite previous lines
api.set_score(s2['uuid'], 0, 10)
api.set_score(s3['uuid'], 4, 4)
# Getting the scores for a user should never take more than one query
with self.assertNumQueries(1):
scores = api.get_scores(
student_item["course_id"], student_item["student_id"]
)
self.assertEqual(
scores,
{
u"i4x://a/b/c/s1": (2, 5),
u"i4x://a/b/c/s2": (0, 10),
u"i4x://a/b/c/s3": (4, 4),
}
)
示例7: 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)
示例8: test_submissions_api_overrides_scores
def test_submissions_api_overrides_scores(self):
"""
Check that answering incorrectly is graded properly.
"""
self.basic_setup()
self.submit_question_answer('p1', {'2_1': 'Correct'})
self.submit_question_answer('p2', {'2_1': 'Correct'})
self.submit_question_answer('p3', {'2_1': 'Incorrect'})
self.check_grade_percent(0.67)
self.assertEqual(self.get_course_grade().letter_grade, 'B')
# But now, set the score with the submissions API and watch
# as it overrides the score read from StudentModule and our
# student gets an A instead.
self._stop_signal_patch()
student_item = {
'student_id': anonymous_id_for_user(self.student_user, self.course.id),
'course_id': unicode(self.course.id),
'item_id': unicode(self.problem_location('p3')),
'item_type': 'problem'
}
submission = submissions_api.create_submission(student_item, 'any answer')
submissions_api.set_score(submission['uuid'], 1, 1)
self.check_grade_percent(1.0)
self.assertEqual(self.get_course_grade().letter_grade, 'A')
示例9: test_delete_student_state_resets_scores
def test_delete_student_state_resets_scores(self):
problem_location = self.course.id.make_usage_key('dummy', 'module')
# Create a student module for the user
StudentModule.objects.create(
student=self.student,
course_id=self.course.id,
module_state_key=problem_location,
state=json.dumps({})
)
# Create a submission and score for the student using the submissions API
student_item = {
'student_id': anonymous_id_for_user(self.student, self.course.id),
'course_id': self.course.id.to_deprecated_string(),
'item_id': problem_location.to_deprecated_string(),
'item_type': 'openassessment'
}
submission = sub_api.create_submission(student_item, 'test answer')
sub_api.set_score(submission['uuid'], 1, 2)
# Delete student state using the instructor dash
url = reverse('instructor_dashboard_legacy', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(url, {
'action': 'Delete student state for module',
'unique_student_identifier': self.student.email,
'problem_for_student': problem_location.to_deprecated_string(),
})
self.assertEqual(response.status_code, 200)
# Verify that the student's scores have been reset in the submissions API
score = sub_api.get_score(student_item)
self.assertIs(score, None)
示例10: test_delete_submission_scores
def test_delete_submission_scores(self):
user = UserFactory()
problem_location = self.course_key.make_usage_key('dummy', 'module')
# Create a student module for the user
StudentModule.objects.create(
student=user,
course_id=self.course_key,
module_state_key=problem_location,
state=json.dumps({})
)
# Create a submission and score for the student using the submissions API
student_item = {
'student_id': anonymous_id_for_user(user, self.course_key),
'course_id': self.course_key.to_deprecated_string(),
'item_id': problem_location.to_deprecated_string(),
'item_type': 'openassessment'
}
submission = sub_api.create_submission(student_item, 'test answer')
sub_api.set_score(submission['uuid'], 1, 2)
# Delete student state using the instructor dash
reset_student_attempts(
self.course_key, user, problem_location,
delete_module=True
)
# Verify that the student's scores have been reset in the submissions API
score = sub_api.get_score(student_item)
self.assertIs(score, None)
示例11: set_score
def set_score(self, score):
"""
Set a score for the workflow.
Scores are persisted via the Submissions API, separate from the Workflow
Data. Score is associated with the same submission_uuid as this workflow
Args:
score (dict): A dict containing 'points_earned' and
'points_possible'.
"""
sub_api.set_score(
self.submission_uuid,
score["points_earned"],
score["points_possible"]
)
# This should be replaced by using the event tracking API, but
# that's not quite ready yet. So we're making this temp hack.
emit_event({
"context": {
"course_id": self.course_id
},
"event": {
"submission_uuid": self.submission_uuid,
"points_earned": score["points_earned"],
"points_possible": score["points_possible"],
},
"event_source": "server",
"event_type": "openassessment.workflow.score",
"time": datetime.utcnow(),
})
示例12: test_delete_submission_scores
def test_delete_submission_scores(self):
user = UserFactory()
course_id = 'ora2/1/1'
item_id = 'i4x://ora2/1/openassessment/b3dce2586c9c4876b73e7f390e42ef8f'
# Create a student module for the user
StudentModule.objects.create(
student=user, course_id=course_id, module_state_key=item_id, state=json.dumps({})
)
# Create a submission and score for the student using the submissions API
student_item = {
'student_id': anonymous_id_for_user(user, course_id),
'course_id': course_id,
'item_id': item_id,
'item_type': 'openassessment'
}
submission = sub_api.create_submission(student_item, 'test answer')
sub_api.set_score(submission['uuid'], 1, 2)
# Delete student state using the instructor dash
reset_student_attempts(course_id, user, item_id, delete_module=True)
# Verify that the student's scores have been reset in the submissions API
score = sub_api.get_score(student_item)
self.assertIs(score, None)
示例13: _create_submissions_and_scores
def _create_submissions_and_scores(
self, xblock, submissions_and_scores,
submission_key="text", points_possible=10
):
"""
Create submissions and scores that should be displayed by the leaderboard.
Args:
xblock (OpenAssessmentBlock)
submisions_and_scores (list): List of `(submission, score)` tuples, where
`submission` is the essay text (string) and `score` is the integer
number of points earned.
Keyword Args:
points_possible (int): The total number of points possible for this problem
submission_key (string): The key to use in the submission dict. If None, use
the submission value itself instead of embedding it in a dictionary.
"""
for num, (submission, points_earned) in enumerate(submissions_and_scores):
# Assign a unique student ID
# These aren't displayed by the leaderboard, so we can set them
# to anything without affecting the test.
student_item = xblock.get_student_item_dict()
# adding rand number to the student_id to make it unique.
student_item['student_id'] = "student {num} {num2}".format(num=num, num2=randint(2, 1000))
if submission_key is not None:
answer = {submission_key: submission}
else:
answer = submission
# Create a submission
sub = sub_api.create_submission(student_item, answer)
# Create a score for the submission
sub_api.set_score(sub['uuid'], points_earned, points_possible)
示例14: 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
)
示例15: test_create_score
def test_create_score(self):
submission = api.create_submission(STUDENT_ITEM, ANSWER_ONE)
student_item = self._get_student_item(STUDENT_ITEM)
self._assert_submission(submission, ANSWER_ONE, student_item.pk, 1)
api.set_score(submission["uuid"], 11, 12)
score = api.get_latest_score_for_submission(submission["uuid"])
self._assert_score(score, 11, 12)