Skip to content

Commit

Permalink
Автопроверка тестовых заданий работает корректно
Browse files Browse the repository at this point in the history
  • Loading branch information
codEnjoyer committed Dec 11, 2023
1 parent c54e90d commit e0bdad8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
11 changes: 1 addition & 10 deletions backend/src/game/units/tasks/questions/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,10 @@ async def autocheck_task_unit(map_id: UUID,
correct_answers_ids_on_question = set(correct_answers_ids_on_question)
question_read_answers = []
for answer in user_answers_on_question:
answer_was_selected_correct = (
# Был выбран правильный ответ: (1 и 1) != (0 и 0) => 1
# Был выбран неправильный ответ: (1 и 0) != (0 и 1) => 0
# Правильный ответ не был выбран: (0 и 1) != (1 и 0) => 0
# Неправильный ответ не был выбран: (0 и 0) != (1 и 1) => 1
(answer.is_selected and answer.id in correct_answers_ids_on_question) !=
(not answer.is_selected and answer.id not in correct_answers_ids_on_question)
)
correct_answer_selected = answer.is_selected and answer.id in correct_answers_ids_on_question
incorrect_answer_not_selected = not answer.is_selected and answer.id not in correct_answers_ids_on_question
answer_was_selected_correct = not (correct_answer_selected ^ incorrect_answer_not_selected)
answer_was_selected_correct = correct_answer_selected or incorrect_answer_not_selected
answer_read = EmployeeAnswerRead(answer=answer.answer, was_selected_correct=answer_was_selected_correct)
# TODO: невыбранные неправильные ответы помечаются false
question_read_answers.append(answer_read)
question_read = EmployeeQuestionRead(type=question_answer.type,
question=question_answer.question,
Expand Down
3 changes: 2 additions & 1 deletion backend/src/services/game/units/answer_option_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ def __init__(self, repository: type[AbstractRepository]):
async def get_all_correct(self, question_id: uuid.UUID) -> list[uuid.UUID]:
correct_answers_models = await (self.__answers_options_repo
.find_all_with_condition(Question.id == question_id,
AnswerOption.is_correct is True))
AnswerOption.is_correct.is_(True))
)
return [correct_answer.id for correct_answer in correct_answers_models]

0 comments on commit e0bdad8

Please sign in to comment.