mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Removed question simplifying
This commit is contained in:
parent
c750261b12
commit
ccc6e849cf
1 changed files with 10 additions and 97 deletions
107
stable.user.js
107
stable.user.js
|
@ -63,7 +63,7 @@
|
|||
// forcing pages for testing. unless you test, do not set these to true!
|
||||
// only one of these should be true for testing
|
||||
const forceTestPage = false
|
||||
const forceResultPage = false
|
||||
const forceResultPage = true
|
||||
const forceDefaultPage = false
|
||||
const logElementGetting = false
|
||||
const log = true
|
||||
|
@ -101,25 +101,12 @@
|
|||
var texts = huTexts
|
||||
|
||||
// : question-classes {{{
|
||||
const commonUselessAnswerParts = [
|
||||
'A helyes válasz az ',
|
||||
'A helyes válasz a ',
|
||||
'A helyes válaszok: ',
|
||||
'A helyes válaszok:',
|
||||
'A helyes válasz: ',
|
||||
'A helyes válasz:',
|
||||
'The correct answer is:',
|
||||
'\''
|
||||
]
|
||||
const commonUselessStringParts = [',', '\\.', ':', '!', '\\+']
|
||||
const specialChars = [ '&', '\\+' ]
|
||||
const lengthDiffMultiplier = 10 /* Percent minus for length difference */
|
||||
|
||||
const assert = (val) => {
|
||||
if (!val) { throw new Error('Assertion failed') }
|
||||
}
|
||||
|
||||
// TODO: check if someting is not used
|
||||
class StringUtils {
|
||||
RemoveStuff (value, removableStrings, toReplace) {
|
||||
removableStrings.forEach((x) => {
|
||||
|
@ -171,14 +158,6 @@
|
|||
return toremove.trim()
|
||||
}
|
||||
|
||||
// simplifies a string for easier comparison
|
||||
SimplifyStringForComparison (value) {
|
||||
assert(value)
|
||||
|
||||
value = this.RemoveUnnecesarySpaces(value).toLowerCase()
|
||||
return this.RemoveStuff(value, commonUselessStringParts)
|
||||
}
|
||||
|
||||
RemoveSpecialChars (value) {
|
||||
assert(value)
|
||||
|
||||
|
@ -199,74 +178,6 @@
|
|||
return input.replace(/\s/g, ' ')
|
||||
}
|
||||
|
||||
CompareString (s1, s2) {
|
||||
if (!s1 || !s2) {
|
||||
return 0
|
||||
}
|
||||
|
||||
s1 = this.SimplifyStringForComparison(s1).split(' ')
|
||||
s2 = this.SimplifyStringForComparison(s2).split(' ')
|
||||
var match = 0
|
||||
for (var i = 0; i < s1.length; i++) {
|
||||
if (s2.includes(s1[i])) { match++ }
|
||||
}
|
||||
var percent = Math.round(((match / s1.length) * 100).toFixed(2)) // matched words percent
|
||||
var lengthDifference = Math.abs(s2.length - s1.length)
|
||||
percent -= lengthDifference * lengthDiffMultiplier
|
||||
if (percent < 0) { percent = 0 }
|
||||
return percent
|
||||
}
|
||||
|
||||
AnswerPreProcessor (value) {
|
||||
assert(value)
|
||||
|
||||
return this.RemoveStuff(
|
||||
value, commonUselessAnswerParts)
|
||||
}
|
||||
|
||||
// 'a. pécsi sör' -> 'pécsi sör'
|
||||
RemoveAnswerLetters (value) {
|
||||
assert(value)
|
||||
|
||||
let s = value.split('. ')
|
||||
if (s[0].length < 2 && s.length > 1) {
|
||||
s.shift()
|
||||
return s.join(' ')
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
SimplifyQA (value, mods) {
|
||||
if (!value) { return }
|
||||
|
||||
const reducer = (res, fn) => {
|
||||
return fn(res)
|
||||
}
|
||||
|
||||
return mods.reduce(reducer, value)
|
||||
}
|
||||
|
||||
SimplifyAnswer (value) {
|
||||
return this.SimplifyQA(
|
||||
value,
|
||||
[
|
||||
this.RemoveSpecialChars.bind(this),
|
||||
this.RemoveUnnecesarySpaces.bind(this),
|
||||
this.AnswerPreProcessor.bind(this),
|
||||
this.RemoveAnswerLetters.bind(this)
|
||||
])
|
||||
}
|
||||
|
||||
SimplifyQuestion (value) {
|
||||
return this.SimplifyQA(
|
||||
value,
|
||||
[
|
||||
this.RemoveSpecialChars.bind(this),
|
||||
this.RemoveUnnecesarySpaces.bind(this)
|
||||
])
|
||||
}
|
||||
|
||||
SimplifyStack (stack) {
|
||||
return this.SimplifyQuery(stack)
|
||||
}
|
||||
|
@ -963,9 +874,13 @@
|
|||
function ShowSaveQuizDialog (sendResult, sentData, newQuestions) {
|
||||
// FIXME: normal string building with localisation :/
|
||||
var msg = ''
|
||||
// TODO: '0 új kérdés'
|
||||
if (sendResult) {
|
||||
msg = 'Kérdések elküldve, katt az elküldött adatokért. ' + newQuestions + ' új kérdés'
|
||||
msg = 'Kérdések elküldve, katt az elküldött adatokért.'
|
||||
if (newQuestions > 0) {
|
||||
msg += ' ' + newQuestions + ' új kérdés'
|
||||
} else {
|
||||
msg += ' Nincs új kérdés'
|
||||
}
|
||||
} else {
|
||||
msg = 'Szerver nem elérhető, vagy egyéb hiba kérdések elküldésénél! (F12 -> Console)'
|
||||
}
|
||||
|
@ -1066,13 +981,11 @@
|
|||
for (var i = 0; i < results.length - 2; i++) {
|
||||
var question = {} // the current question
|
||||
// QUESTION --------------------------------------------------------------------------------------------------------------------
|
||||
var q = RPM.GetQuestionFromResult(i)
|
||||
if (q !== undefined) { question.Q = SUtils.SimplifyQuestion(q) }
|
||||
question.Q = RPM.GetQuestionFromResult(i)
|
||||
|
||||
// RIGHTANSWER ---------------------------------------------------------------------------------------------------------------------
|
||||
var a = RPM.GetRightAnswerFromResultv2(i)
|
||||
if (a === undefined) { a = RPM.GetRightAnswerFromResult(i) }
|
||||
if (a !== undefined) { question.A = SUtils.SimplifyAnswer(a) }
|
||||
question.A = RPM.GetRightAnswerFromResultv2(i)
|
||||
if (question.A === undefined) { question.A = RPM.GetRightAnswerFromResult(i) }
|
||||
// DATA ---------------------------------------------------------------------------------------------------------------------
|
||||
question.data = GetDataFormResult(i)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue