mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Fixed bugs that came from declassifying classes.js
This commit is contained in:
parent
db1976ecf3
commit
ecd3a9805f
6 changed files with 92 additions and 116 deletions
|
@ -145,7 +145,6 @@ function simplifyQA(value, mods) {
|
|||
return mods.reduce(reducer, value)
|
||||
}
|
||||
|
||||
// TODO: simplify answer before setting
|
||||
function simplifyAnswer(value) {
|
||||
return simplifyQA(value, [
|
||||
removeSpecialChars.bind(this),
|
||||
|
@ -190,17 +189,17 @@ function compareImage(data, data2) {
|
|||
return compareString(data.images.join(' '), data2.images.join(' '))
|
||||
}
|
||||
|
||||
function compareData(data, qObj) {
|
||||
function compareData(q1, q2) {
|
||||
try {
|
||||
if (qObj.data.type === data.type) {
|
||||
let dataType = qObj.data.type
|
||||
if (q1.data.type === q2.data.type) {
|
||||
let dataType = q1.data.type
|
||||
if (dataType === 'simple') {
|
||||
return -1
|
||||
} else if (dataType === 'image') {
|
||||
return compareImage(qObj.data)
|
||||
return compareImage(q1.data, q2.data)
|
||||
} else {
|
||||
debugLog(`Unhandled data type ${dataType}`, 'Compare question data', 1)
|
||||
debugLog(qObj, 'Compare question data', 2)
|
||||
debugLog(q1, 'Compare question data', 2)
|
||||
}
|
||||
} else {
|
||||
return 0
|
||||
|
@ -221,11 +220,11 @@ function compareAnswer(q1, q2) {
|
|||
return compareString(q1.A, q2.A)
|
||||
}
|
||||
|
||||
function compareQuestionObj(q1, q2, data) {
|
||||
function compareQuestionObj(q1, q1subjName, q2, q2subjName, data) {
|
||||
assert(data)
|
||||
assert(q1)
|
||||
assert(typeof q1 === 'object')
|
||||
assert(q2)
|
||||
assert(typeof q2 === 'object')
|
||||
let qObj
|
||||
|
||||
if (typeof q2 === 'string') {
|
||||
|
@ -237,10 +236,10 @@ function compareQuestionObj(q1, q2, data) {
|
|||
qObj = q2
|
||||
}
|
||||
|
||||
const qMatch = compareQuestion(q1, qObj.Q)
|
||||
const aMatch = compareAnswer(q1.A, qObj.A)
|
||||
const qMatch = compareQuestion(q1, qObj)
|
||||
const aMatch = compareAnswer(q1, qObj)
|
||||
// -1 if botth questions are simple
|
||||
const dMatch = compareData(q1.data, qObj.data)
|
||||
const dMatch = compareData(q1, qObj)
|
||||
|
||||
let avg = -1
|
||||
if (qObj.A) {
|
||||
|
@ -261,6 +260,7 @@ function compareQuestionObj(q1, q2, data) {
|
|||
qMatch: qMatch,
|
||||
aMatch: aMatch,
|
||||
dMatch: dMatch,
|
||||
matchedSubjName: q2subjName,
|
||||
avg: avg,
|
||||
}
|
||||
}
|
||||
|
@ -278,12 +278,18 @@ function questionToString(question) {
|
|||
// ---------------------------------------------------------------------------------------------------------
|
||||
// Subject
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
function searchQuestion(questions, question, questionData) {
|
||||
function searchQuestion(subj, question, questionData, subjName) {
|
||||
assert(question)
|
||||
|
||||
var result = []
|
||||
questions.forEach((currentQuestion) => {
|
||||
let percent = compareQuestionObj(currentQuestion, question, questionData)
|
||||
subj.Questions.forEach((currentQuestion) => {
|
||||
let percent = compareQuestionObj(
|
||||
currentQuestion,
|
||||
subjName,
|
||||
question,
|
||||
subj.Name,
|
||||
questionData
|
||||
)
|
||||
if (percent.avg > minMatchAmmount) {
|
||||
result.push({
|
||||
question: currentQuestion,
|
||||
|
@ -294,7 +300,7 @@ function searchQuestion(questions, question, questionData) {
|
|||
})
|
||||
|
||||
// TODO: check if sorting is correct!
|
||||
result.sort((q1, q2) => {
|
||||
result = result.sort((q1, q2) => {
|
||||
return q1.match < q2.match
|
||||
})
|
||||
|
||||
|
@ -327,7 +333,9 @@ function addQuestion(data, subj, question) {
|
|||
var i = 0
|
||||
while (
|
||||
i < data.length &&
|
||||
!subj.toLowerCase().includes(getSubjNameWithoutYear(data[i]).toLowerCase())
|
||||
!subj
|
||||
.toLowerCase()
|
||||
.includes(getSubjNameWithoutYear(data[i].Name).toLowerCase())
|
||||
) {
|
||||
i++
|
||||
}
|
||||
|
@ -335,10 +343,7 @@ function addQuestion(data, subj, question) {
|
|||
if (i < data.length) {
|
||||
debugLog('Adding new question to existing subject', 'qdb add', 1)
|
||||
result = [...data]
|
||||
result[i].Questions = {
|
||||
...data[i].Questions,
|
||||
question,
|
||||
}
|
||||
result[i].Questions = [...data[i].Questions, question]
|
||||
} else {
|
||||
debugLog('Creating new subject for question', 'qdb add', 1)
|
||||
result = [
|
||||
|
@ -380,7 +385,9 @@ function searchData(data, question, subjName, questionData) {
|
|||
.includes(getSubjNameWithoutYear(subj.Name).toLowerCase())
|
||||
) {
|
||||
debugLog(`Searching in ${subj.Name} `, 2)
|
||||
result = result.concat(subj.Search(question, questionData))
|
||||
result = result.concat(
|
||||
searchQuestion(subj, question, questionData, subjName)
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -393,7 +400,7 @@ function searchData(data, question, subjName, questionData) {
|
|||
)
|
||||
data.forEach((subj) => {
|
||||
result = result.concat(
|
||||
searchQuestion(subj.Questions, question, questionData)
|
||||
searchQuestion(subj, question, questionData, subjName)
|
||||
)
|
||||
})
|
||||
if (result.length > 0) {
|
||||
|
@ -407,7 +414,7 @@ function searchData(data, question, subjName, questionData) {
|
|||
}
|
||||
|
||||
// TODO: check if sorting is correct!
|
||||
result.sort((q1, q2) => {
|
||||
result = result.sort((q1, q2) => {
|
||||
return q1.match < q2.match
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue