Removed question simplifying

This commit is contained in:
MrFry 2020-01-27 10:51:16 +01:00
parent c750261b12
commit ccc6e849cf

View file

@ -63,7 +63,7 @@
// forcing pages for testing. unless you test, do not set these to true! // forcing pages for testing. unless you test, do not set these to true!
// only one of these should be true for testing // only one of these should be true for testing
const forceTestPage = false const forceTestPage = false
const forceResultPage = false const forceResultPage = true
const forceDefaultPage = false const forceDefaultPage = false
const logElementGetting = false const logElementGetting = false
const log = true const log = true
@ -101,25 +101,12 @@
var texts = huTexts var texts = huTexts
// : question-classes {{{ // : 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 specialChars = [ '&', '\\+' ]
const lengthDiffMultiplier = 10 /* Percent minus for length difference */
const assert = (val) => { const assert = (val) => {
if (!val) { throw new Error('Assertion failed') } if (!val) { throw new Error('Assertion failed') }
} }
// TODO: check if someting is not used
class StringUtils { class StringUtils {
RemoveStuff (value, removableStrings, toReplace) { RemoveStuff (value, removableStrings, toReplace) {
removableStrings.forEach((x) => { removableStrings.forEach((x) => {
@ -171,14 +158,6 @@
return toremove.trim() 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) { RemoveSpecialChars (value) {
assert(value) assert(value)
@ -199,74 +178,6 @@
return input.replace(/\s/g, ' ') 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) { SimplifyStack (stack) {
return this.SimplifyQuery(stack) return this.SimplifyQuery(stack)
} }
@ -963,9 +874,13 @@
function ShowSaveQuizDialog (sendResult, sentData, newQuestions) { function ShowSaveQuizDialog (sendResult, sentData, newQuestions) {
// FIXME: normal string building with localisation :/ // FIXME: normal string building with localisation :/
var msg = '' var msg = ''
// TODO: '0 új kérdés'
if (sendResult) { 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 { } else {
msg = 'Szerver nem elérhető, vagy egyéb hiba kérdések elküldésénél! (F12 -> Console)' 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++) { for (var i = 0; i < results.length - 2; i++) {
var question = {} // the current question var question = {} // the current question
// QUESTION -------------------------------------------------------------------------------------------------------------------- // QUESTION --------------------------------------------------------------------------------------------------------------------
var q = RPM.GetQuestionFromResult(i) question.Q = RPM.GetQuestionFromResult(i)
if (q !== undefined) { question.Q = SUtils.SimplifyQuestion(q) }
// RIGHTANSWER --------------------------------------------------------------------------------------------------------------------- // RIGHTANSWER ---------------------------------------------------------------------------------------------------------------------
var a = RPM.GetRightAnswerFromResultv2(i) question.A = RPM.GetRightAnswerFromResultv2(i)
if (a === undefined) { a = RPM.GetRightAnswerFromResult(i) } if (question.A === undefined) { question.A = RPM.GetRightAnswerFromResult(i) }
if (a !== undefined) { question.A = SUtils.SimplifyAnswer(a) }
// DATA --------------------------------------------------------------------------------------------------------------------- // DATA ---------------------------------------------------------------------------------------------------------------------
question.data = GetDataFormResult(i) question.data = GetDataFormResult(i)