fix: some adjustments for estimation questions
This commit is contained in:
@@ -184,21 +184,61 @@
|
||||
}
|
||||
],
|
||||
"Schätzen": [
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "Wie hoch ist der Eiffelturm?",
|
||||
"minValue": 0,
|
||||
"maxValue": 1000,
|
||||
"correctValue": 330,
|
||||
"unit": "m"
|
||||
},
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "In welchem Jahr begann der Bau des Kölner Doms?",
|
||||
"minValue": 1000,
|
||||
"maxValue": 2025,
|
||||
"correctValue": 1248,
|
||||
"unit": "Jahr"
|
||||
}
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "Wie hoch ist der Eiffelturm?",
|
||||
"minValue": 100,
|
||||
"maxValue": 350,
|
||||
"correctValue": 330,
|
||||
"unit": "m"
|
||||
},
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "In welchem Jahr begann der Bau des Kölner Doms?",
|
||||
"minValue": 1000,
|
||||
"maxValue": 1900,
|
||||
"correctValue": 1248,
|
||||
"unit": "Jahr"
|
||||
},
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "Wie weit ist die Entfernung zwischen Berlin und New York (Luftlinie)?",
|
||||
"minValue": 5000,
|
||||
"maxValue": 10000,
|
||||
"correctValue": 6380,
|
||||
"unit": "km"
|
||||
},
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "Wie hoch ist der Mount Everest?",
|
||||
"minValue": 2000,
|
||||
"maxValue": 10000,
|
||||
"correctValue": 8848,
|
||||
"unit": "m"
|
||||
},
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "Wie viele Kilometer beträgt der Äquatorumfang der Erde?",
|
||||
"minValue": 20000,
|
||||
"maxValue": 50000,
|
||||
"correctValue": 40075,
|
||||
"unit": "km"
|
||||
},
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "Wie tief ist der Marianengraben?",
|
||||
"minValue": 1000,
|
||||
"maxValue": 20000,
|
||||
"correctValue": 11000,
|
||||
"unit": "m"
|
||||
},
|
||||
{
|
||||
"type": "estimation",
|
||||
"question": "In welchem Jahr wurde die Glühbirne von Thomas Edison patentiert?",
|
||||
"minValue": 1700,
|
||||
"maxValue": 2000,
|
||||
"correctValue": 1879,
|
||||
"unit": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -79,20 +79,16 @@ class ViewModel: ObservableObject {
|
||||
func pointsForEstimation(
|
||||
guess: Double,
|
||||
correct: Double,
|
||||
minValue: Double,
|
||||
maxValue: Double,
|
||||
maxPoints: Int = 3,
|
||||
thresholdPercent: Double = 0.3
|
||||
maxPoints: Int = 1,
|
||||
|
||||
) -> Int {
|
||||
let span = maxValue - minValue
|
||||
guard span > 0 else { return 0 }
|
||||
let absError = abs(guess - correct) // Absolute Abweichung
|
||||
let relError = absError / abs(correct) // Relative Abweichung
|
||||
|
||||
let absError = abs(guess - correct)
|
||||
let relError = absError / span
|
||||
|
||||
if relError >= thresholdPercent { return 0 }
|
||||
|
||||
let ratio = 1.0 - (relError / thresholdPercent)
|
||||
return max(0, Int(round(Double(maxPoints) * ratio)))
|
||||
if relError <= 0.1 {
|
||||
return maxPoints
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import SwiftUI
|
||||
|
||||
struct EstimationQuestionView: View {
|
||||
let questionID: AnyHashable // <- neu
|
||||
let minValue: Double
|
||||
let maxValue: Double
|
||||
let correctValue: Double
|
||||
@@ -21,18 +22,11 @@ struct EstimationQuestionView: View {
|
||||
var body: some View {
|
||||
VStack(spacing: 16) {
|
||||
Slider(
|
||||
value: Binding(
|
||||
get: { value },
|
||||
set: { value = min(max($0, minValue), maxValue) } // clamp
|
||||
),
|
||||
value: $value,
|
||||
in: minValue...maxValue,
|
||||
step: (maxValue - minValue) > 200 ? 1 : 0.5
|
||||
)
|
||||
.onAppear {
|
||||
if value < minValue || value > maxValue {
|
||||
value = (minValue + maxValue) / 2
|
||||
}
|
||||
}
|
||||
.disabled(submitted)
|
||||
|
||||
HStack {
|
||||
Text("\(Int(minValue)) \(unit)")
|
||||
@@ -47,9 +41,7 @@ struct EstimationQuestionView: View {
|
||||
Button {
|
||||
gainedPoints = viewModel.pointsForEstimation(
|
||||
guess: value,
|
||||
correct: correctValue,
|
||||
minValue: minValue,
|
||||
maxValue: maxValue
|
||||
correct: correctValue
|
||||
)
|
||||
submitted = true
|
||||
onSubmit(gainedPoints)
|
||||
@@ -78,5 +70,12 @@ struct EstimationQuestionView: View {
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
// bei jedem Fragewechsel
|
||||
.task(id: questionID) {
|
||||
value = minValue
|
||||
submitted = false
|
||||
gainedPoints = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ struct QuizView: View {
|
||||
let correctV = frage.correctValue {
|
||||
// Estimation
|
||||
EstimationQuestionView(
|
||||
questionID: viewModel.currentQuestionIndex, // <- neu
|
||||
minValue: minV,
|
||||
maxValue: maxV,
|
||||
correctValue: correctV,
|
||||
@@ -85,7 +86,6 @@ struct QuizView: View {
|
||||
if estimationSubmitted {
|
||||
Button {
|
||||
viewModel.loadNextQuestion()
|
||||
// Reset für nächste Estimation
|
||||
estimationSubmitted = false
|
||||
isAnswered = false
|
||||
selectedAnswerIndex = nil
|
||||
|
||||
Reference in New Issue
Block a user