Skip to content

Commit

Permalink
fix: fix assessment schema
Browse files Browse the repository at this point in the history
  • Loading branch information
AmooHashem committed Aug 27, 2024
1 parent f27e523 commit 373fcf3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
6 changes: 5 additions & 1 deletion apps/fsm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,13 @@ class ProgramContactInfo(models.Model):
class Content():

@property
def solve_cost(self):
def solve_reward(self):
return self._get_performable_action_intrinsic_attribute_template_method('solve', 'reward')

@property
def solve_cost(self):
return self._get_performable_action_intrinsic_attribute_template_method('solve', 'cost')

@property
def submission_cost(self):
return self._get_performable_action_intrinsic_attribute_template_method('submit', 'cost')
Expand Down
6 changes: 3 additions & 3 deletions apps/response/views/answer_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def submit_answer(self, request, *args, **kwargs):

# assess the answer (is any correct answer is provided)
if question.correct_answer:
correctness_percentage, comment = assess_answer(
score, feedback, improvement_suggestion = assess_answer(
question=question, given_answer=given_answer_object)
if correctness_percentage >= question.correctness_threshold:
if score >= question.correctness_threshold:
given_answer_object.is_correct = True
given_answer_object.save()
_apply_solve_question_reward(
user=user, question=question, website=request.data.get('website'))
return Response(data={'correctness_percentage': correctness_percentage, 'comment': comment})
return Response(data={'score': score, 'feedback': feedback, 'improvement_suggestion': improvement_suggestion})

return Response(status=status.HTTP_202_ACCEPTED)

Expand Down
33 changes: 19 additions & 14 deletions proxies/assess_answer_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@

url = settings.ASSESS_ANSWER_SERVICE_URL

type_caster = {
"SmallAnswer": "Small",
"BigAnswer": "Long",
"MultiChoiceAnswer": "MultiChoiceAnswer",
"UploadFileAnswer": "UploadFile",
}


def assess_answer(question, given_answer):
correct_answer = question.correct_answer
if not question.correct_answer:
raise Exception("no correct answer provided")
body = {
'question': {
'question_type': question.widget_type,
},
'correct_answer': {
'answer_type': question.correct_answer.answer_type,
'string': correct_answer.string_answer,
'question': question.text,
'context': {
'correct_answer': correct_answer.string_answer,
},
'given_answer': {
'answer_type': given_answer.answer_type,
'string': given_answer.string_answer,
'proposed_answer': {
'type': type_caster[given_answer.answer_type],
'text': given_answer.string_answer,
}
}
correctness_percentage = -1
comment = 'not assessed'
score = -1
feedback = 'not assessed'
try:
response = requests.post(f'{url}facade/v1/assess/', json=body)
result = json.loads(response.text)
correctness_percentage = result.get('correctness_percentage')
comment = result.get('comment')
score = result.get('score')
feedback = result.get('feedback')
improvement_suggestion = result.get('improvement_suggestion')
except:
pass
return [correctness_percentage, comment]
return [score, feedback, improvement_suggestion]

0 comments on commit 373fcf3

Please sign in to comment.