fix: answer on the session fix
This commit is contained in:
parent
a7483c3aaa
commit
f89a7646d8
|
@ -202,6 +202,7 @@ class SessionService:
|
||||||
|
|
||||||
is_correct = self._is_correct(question, answer)
|
is_correct = self._is_correct(question, answer)
|
||||||
|
|
||||||
|
print(answer)
|
||||||
self.answer_redis_repository.save_user_answer(
|
self.answer_redis_repository.save_user_answer(
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
|
@ -239,12 +240,30 @@ class SessionService:
|
||||||
return ranked
|
return ranked
|
||||||
|
|
||||||
def _is_correct(self, q, ans) -> bool:
|
def _is_correct(self, q, ans) -> bool:
|
||||||
if q.type in {"multiple_choice", "true_false"}:
|
result = False
|
||||||
return str(ans).strip().lower() == str(q.target_answer).strip().lower()
|
|
||||||
if q.type == "essay":
|
|
||||||
return str(q.target_answer).lower() in str(ans).lower()
|
|
||||||
|
|
||||||
return False
|
if q.type == "true_false":
|
||||||
|
result = str(ans).strip().lower() == str(q.target_answer).strip().lower()
|
||||||
|
|
||||||
|
elif q.type in ["multiple_choice", "option"]:
|
||||||
|
try:
|
||||||
|
result = int(ans) == int(q.target_answer)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
result = False
|
||||||
|
|
||||||
|
elif q.type == "fill_the_blank":
|
||||||
|
result = str(q.target_answer).strip().lower() in str(ans).strip().lower()
|
||||||
|
|
||||||
|
else:
|
||||||
|
result = False
|
||||||
|
|
||||||
|
# Print informasi evaluasi
|
||||||
|
print(f"Tipe Soal: {q.type}")
|
||||||
|
print(f"Jawaban User: {ans}")
|
||||||
|
print(f"Jawaban Benar: {q.target_answer}")
|
||||||
|
print(f"Hasil: {'Benar' if result else 'Salah'}\n")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def summaryAllSessionData(self, session_id: str, start_time):
|
def summaryAllSessionData(self, session_id: str, start_time):
|
||||||
session = self.session_redis_repository.get_session(session_id=session_id)
|
session = self.session_redis_repository.get_session(session_id=session_id)
|
||||||
|
|
Loading…
Reference in New Issue