From 57846a83c9a9003842df401dd55180b16fc0506c Mon Sep 17 00:00:00 2001 From: Oskar Date: Wed, 13 Jan 2021 23:18:17 +0100 Subject: [PATCH] Implement most new Quiz modes (see #3) except proper overtime for FSA. Probably quite buggy --- res/sample-questions.tsv | 6 ++-- web/index.html | 15 ++++---- web/quiz.js | 78 +++++++++++++++++++++++++++++----------- web/util.js | 25 +++++++------ 4 files changed, 80 insertions(+), 44 deletions(-) diff --git a/res/sample-questions.tsv b/res/sample-questions.tsv index 324738e..36c7050 100644 --- a/res/sample-questions.tsv +++ b/res/sample-questions.tsv @@ -3,9 +3,9 @@ Aluminium Titanum All the above" "1 2" -ChooseOne What is depicted on the picture "7 speed double cluth transmission for AWD -8 speed double cluth transmission for AWD -7 speed double cluth transmission for 2WD +ChooseOne What is depicted on the picture "7 speed double clutch transmission for AWD +8 speed double clutch transmission for AWD +7 speed double clutch transmission for 2WD Automatic transmission with torque conventer" 1 FSCzech https://i.ibb.co/56LM89v/chiron-transmission.jpg Text Calculate the (1) torsional- and (2) bending-nominal stress at the critical cross section for the load case shown below. Answer in N / mm² and round to one decimal place. Given: P = 12kW; n = 980 1/min; F = 500 N; xkrit = 110 mm; 0 ≤ x0 ≤ 120mm "torsional-nominal stress bending-nominal stress" "17.1 diff --git a/web/index.html b/web/index.html index cd0e726..e503bc1 100644 --- a/web/index.html +++ b/web/index.html @@ -11,6 +11,10 @@ FS Quiz tool + + + + @@ -50,13 +54,13 @@ switch (drf_sf.value) { case 'FSG': case 'FSA': - drf_ef.innerHTML = 'Minutes per question:
' + drf_ef.innerHTML = 'Minutes per question:
' break case 'FSCzech': - drf_ef.innerHTML = 'Seconds Timeout after handin:
' + drf_ef.innerHTML = 'Seconds Timeout after handin:
' break case 'FSSpain': - drf_ef.innerHTML = 'Number of handin tries:
' + drf_ef.innerHTML = 'Number of handin tries:
' break default: drf_ef.innerHTML = '' @@ -87,7 +91,7 @@
- + @@ -107,9 +111,6 @@ · - - - diff --git a/web/quiz.js b/web/quiz.js index c056b37..bbdca0c 100644 --- a/web/quiz.js +++ b/web/quiz.js @@ -33,7 +33,14 @@ function updateSubmitButton() { var lastQuestion = (state.currentQuestion == (state.questions.length - 1)) - button.value = lastQuestion ? 'Submit Answers' : 'Next Question' + button.value = lastQuestion || !getRule('sequential') ? 'Submit Answers' : 'Next Question' + +} + +function resetSubmitButton() { + + updateSubmitButton() + document.getElementById('quizSubmitButton').disabled = false } @@ -43,16 +50,22 @@ function updateSubmitTimer() { if (state.submitTimer > 0) { - button.value = 'Wait ' + state.submitTimer + 's' + timetext = state.submitTimer > 60 ? + Math.floor(state.submitTimer/60)+':'+(('0' + (state.submitTimer%60)).slice(-2)) : + state.submitTimer + 's' + + button.value = 'Wait ' + timetext button.disabled = true state.submitTimer -= 1 } else { - updateSubmitButton() - button.disabled = false + resetSubmitButton() clearInterval(state.submitInterval) + if (getRule('sequential') && !getRule('allowQOvertime')) + submitQuiz() + } } @@ -97,6 +110,9 @@ function nextQuestion() { showSequentialQuestion() + if (state.currentQuestion !== null && getRule('questionTimeout')) + startSubmitTimer() + return state.currentQuestion } @@ -165,10 +181,13 @@ function startQuiz() { if (state.submitTimer > 0) startSubmitTimer(state.submitTimer) + else if (getRule('questionTimeout')) + startSubmitTimer() else - updateSubmitTimer() + resetSubmitButton() startTotalTimer() + state.running = true console.log('Quiz started/resumed') @@ -178,12 +197,15 @@ function reStartQuiz() { console.log('Restarting quiz'); - state.currentQuestion = 0 - state.totalTimer = 0 - state.submitTimer = 0 - state.success = false + state.currentQuestion = defaultState.currentQuestion + state.success = defaultState.success + state.submitTry = defaultState.submitTry + state.submitTimer = defaultState.submitTimer + state.submitInterval = defaultState.submitInterval + state.totalTimer = defaultState.totalTimer + state.totalInterval = defaultState.totalInterval - startQuiz() + changeView('prescreen') } @@ -226,6 +248,8 @@ function endQuiz() { console.log('Ending quiz') + state.running = false + localStorage.removeItem('state') document.querySelector('#quiz form').innerHTML = '' @@ -299,20 +323,31 @@ function submitQuiz() { } - var text = '' + correct + '/' + state.questions.length + ' questions answered correctly.\n' + var text = '' + correct + '/' + state.questions.length + ' questions answered correctly.' state.success = (correct == state.questions.length) - text += state.success ? 'Yay you did it!' : 'Try again!' - if (!state.success) { - renderQuiz() - startSubmitTimer() - alert(text) + state.submitTry++ + + if (getRule('submitTries') && state.submitTry < state.submitTries) { + alert(text + `\nThis was try ${state.submitTry}/${state.submitTries}\nClick OK to Try Again`) + renderQuiz() + if (getRule('sequential')) { + state.currentQuestion = 0 + showSequentialQuestion(state.currentQuestion) + } + + if (getRule('submitTimeout')) + startSubmitTimer() + } else { + document.querySelector('#postscreen h1').innerHTML = (text + '
Maybe next time :)') + endQuiz() + } } if (state.success) { - document.querySelector('#postscreen h1').innerHTML = `Yay, we're done!
Everything is correct :)` + document.querySelector('#postscreen h1').innerHTML = (text + '
Yay you did it!') endQuiz() } @@ -339,8 +374,6 @@ function abortQuiz() { window.onload = async function() { - console.log('onload') - var browserWarning = document.getElementById('browserwarning') // If arrow functions are supported, it's modern enough :P @@ -349,7 +382,7 @@ window.onload = async function() { var stateString = localStorage.getItem('state') var urlId = idFromUrl() - console.log('URL ID:' + urlId) + console.log('URL ID:', urlId) if (stateString) { @@ -378,7 +411,10 @@ window.onload = async function() { document.getElementById('meme').innerHTML = meme if (stateString && !useUrl) - startQuiz() + if (state.running) + startQuiz() + else + changeView('prescreen') if (!stateString && !useUrl) changeView('spreadsheet') diff --git a/web/util.js b/web/util.js index dcbc4eb..e3d6c5c 100644 --- a/web/util.js +++ b/web/util.js @@ -2,19 +2,17 @@ const defaultState = { style: 'FSCzech', // enum of { FSG, FSA, FSN, FSEast, FSCzech, FSSpain, FSSwitzerland } id: null, title: null, + running: false, questions: [], currentQuestion: 0, success: false, + submitTry: 0, submitTries: 1, - submits: 0, submitTime: null, submitTimer: 0, submitInterval: null, totalTimer: 0, totalInterval: null, - questionTime: null, - questionTimer: 0, - questionInterval: null, } var state @@ -38,13 +36,13 @@ function updateTitles() { var rules = { __default__: { sequential: false, - submitTries: 1, // NYI - submitTimeout: null, // NYI - timedQs: false, // NYI - allowQOvertime: false // NYI + questionTimeout: null, + allowQOvertime: false, // Not implemented correctly + submitTries: 1, + submitTimeout: null }, - 'FSG' : { sequential: true, timedQs: true }, - 'FSA' : { sequential: true, timedQs: true, allowQOvertime: true }, + 'FSG' : { sequential: true, questionTimeout: 5 }, + 'FSA' : { sequential: true, questionTimeout: 5, allowQOvertime: true }, 'FSN' : { sequential: true }, 'FSEast' : { sequential: false }, 'FSCzech' : { sequential: false, submitTries: Infinity, submitTimeout: 30 }, @@ -74,13 +72,14 @@ function applyRuleSettingsFromForm() { switch (state.style) { case 'FSG': case 'FSA': - state.questionTime = parseInt(document.getElementById('qTimeField').value) + state.submitTime = 60 * parseInt(document.getElementById('qTimeField').value) break case 'FSCzech': - state.submitTime = parseInt(document.getElementById('sTOutField').value) + state.submitTime = parseInt(document.getElementById('sTOutField').value) + state.submitTries = rules[state.style].submitTries break case 'FSSpain': - state.submitTries = parseInt(document.getElementById('sTriesField').value) + state.submitTries = parseInt(document.getElementById('sTriesField').value) break }