Skip to content

Commit

Permalink
hope test does not fail anymore
Browse files Browse the repository at this point in the history
stylistic stuff
  • Loading branch information
khdebruijn committed May 2, 2024
1 parent 606b1dc commit 044b5a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion scripts/python/hash_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def process_questions(questions):
"""Process and hash answers within the questions dictionary based on question type."""
for _, q_data in questions.items():
print(1)
q_data["answer"] = cd.hash_answer(q_data.get("answer"), q_data.get("type"), sig_figs=q_data.get("sig_figs"))
q_data["answer"] = cd.hash_answer(
q_data.get("answer"), q_data.get("type"), sig_figs=q_data.get("sig_figs")
)
print(2)
return questions

Expand Down
21 changes: 16 additions & 5 deletions src/coastal_dynamics/numeric.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Literal

import numpy as np
import numpy as np
import panel as pn

import coastal_dynamics as cd
Expand Down Expand Up @@ -46,9 +46,13 @@ def check_answer(self, event) -> None:
user_answer = float(self.answer_input.value)

if self.sig_figs:
user_answer = np.format_float_positional(user_answer, precision=self.sig_figs, unique=False, fractional=False, trim='k')

if self.hash_answer(user_answer, "numeric", sig_figs=self.sig_figs) == self.correct_answer:
user_answer = np.format_float_positional(
user_answer, precision=self.sig_figs, unique=False, fractional=False, trim='k'
)

hashed_user_answer = self.hash_answer(user_answer, "numeric", sig_figs=self.sig_figs)

if hashed_user_answer == self.correct_answer:
self.feedback_widget.value = self.feedback["correct"]

else:
Expand Down Expand Up @@ -78,7 +82,14 @@ def serve(self) -> pn.Column:
question_name="Q3: Simple numeric question",
question_text=question_data["question"],
question_answer=cd.hash_answer(
np.format_float_positional(float(question_data["answer"]),precision=question_data["sig_figs"], unique=False, fractional=False, trim='k'), "numeric",
np.format_float_positional(
float(question_data["answer"]),
precision=question_data["sig_figs"],
unique=False,
fractional=False,
trim='k')
,
"numeric",
),
question_feedback={
"correct": "Correct!...",
Expand Down
8 changes: 7 additions & 1 deletion src/coastal_dynamics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def hash_answer(answer, question_type, sig_figs=None):
return hashlib.sha256(str(answer).encode()).hexdigest()
elif question_type == "numeric":
if sig_figs:
answer = np.format_float_positional(float(answer), precision=sig_figs, unique=False, fractional=False, trim='k')
answer = np.format_float_positional(
float(answer),
precision=sig_figs,
unique=False,
fractional=False,
trim='k'
)
return hashlib.sha256(str(answer).encode()).hexdigest()
else:
msg = f"Unsupported question type: {question_type}"
Expand Down

0 comments on commit 044b5a8

Please sign in to comment.