Schätzfunktion( (mit Schieberegler) #148
This commit is contained in:
@@ -210,15 +210,43 @@ class GameConsumer(AsyncWebsocketConsumer):
|
||||
correct_sequence = sorted(question_data["options"], key=lambda x: x["order"])
|
||||
correct_values = [opt["value"] for opt in correct_sequence]
|
||||
is_correct = (answers_order == correct_values)
|
||||
|
||||
|
||||
elif question_type == "guess":
|
||||
try:
|
||||
user_val = float(answer)
|
||||
correct_val = float(question_data['options'][0].get('value', 0))
|
||||
tolerance = float(question_data.get('tolerance', 0))
|
||||
percentage = min(user_val, correct_val) / (max(user_val, correct_val) + 1e-5)
|
||||
|
||||
|
||||
score_percentage= min(round(percentage, 3), 1.0)
|
||||
if score_percentage>= abs(tolerance/100):
|
||||
is_correct=True
|
||||
else:
|
||||
is_correct=False
|
||||
|
||||
print(score_percentage)
|
||||
|
||||
|
||||
except ValueError:
|
||||
is_correct = False # falls keine Zahl eingegeben wurde
|
||||
answer_index = 0 if is_correct else 1
|
||||
|
||||
|
||||
# Score berechnen
|
||||
try:
|
||||
if score_percentage==None:
|
||||
score_percentage=1
|
||||
except:
|
||||
score_percentage=1
|
||||
|
||||
|
||||
score = 0
|
||||
if is_correct:
|
||||
base_score = 1000
|
||||
time_factor = time_remaining / int(current_question.time_per_question) / 1000
|
||||
score = int(base_score * (0.5 + 0.5 * time_factor))
|
||||
|
||||
score = int(base_score * (0.75 + 0.25 * time_factor))*score_percentage
|
||||
|
||||
# Antwort speichern oder aktualisieren
|
||||
answer_obj, created = QuizAnswer.objects.get_or_create(
|
||||
participant=participant,
|
||||
|
||||
Reference in New Issue
Block a user