mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
searchData is now using workers, fixed random question letter in question
This commit is contained in:
parent
63b08244dc
commit
6c781eba97
5 changed files with 52 additions and 95 deletions
src/utils
|
@ -4,9 +4,16 @@ const {
|
|||
parentPort,
|
||||
workerData,
|
||||
} = require('worker_threads')
|
||||
const searchDataWorkerFile = './src/utils/searchData.js'
|
||||
|
||||
const logger = require('../../utils/logger.js')
|
||||
const logger = require('./logger.js')
|
||||
|
||||
const searchDataWorkerFile = './src/utils/classes.js'
|
||||
|
||||
const assert = (val) => {
|
||||
if (!val) {
|
||||
throw new Error('Assertion failed')
|
||||
}
|
||||
}
|
||||
|
||||
const commonUselessAnswerParts = [
|
||||
'A helyes válasz az ',
|
||||
|
@ -18,17 +25,12 @@ const commonUselessAnswerParts = [
|
|||
'The correct answer is:',
|
||||
"'",
|
||||
]
|
||||
|
||||
const commonUselessStringParts = [',', '\\.', ':', '!', '\\+', '\\s*\\.']
|
||||
const specialChars = ['&', '\\+']
|
||||
const lengthDiffMultiplier = 10 /* Percent minus for length difference */
|
||||
const minMatchAmmount = 60 /* Minimum ammount to consider that two questions match during answering */
|
||||
|
||||
const assert = (val) => {
|
||||
if (!val) {
|
||||
throw new Error('Assertion failed')
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
// String Utils
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
@ -153,16 +155,22 @@ function simplifyAnswer(value) {
|
|||
}
|
||||
|
||||
function simplifyQuestion(question) {
|
||||
if (typeof q === 'string') {
|
||||
return simplifyQA(question, [removeSpecialChars, removeUnnecesarySpaces])
|
||||
if (typeof question === 'string') {
|
||||
return simplifyQA(question, [
|
||||
removeSpecialChars,
|
||||
removeUnnecesarySpaces,
|
||||
removeAnswerLetters,
|
||||
])
|
||||
} else {
|
||||
question.Q = simplifyQA(question.Q, [
|
||||
removeSpecialChars,
|
||||
removeUnnecesarySpaces,
|
||||
removeAnswerLetters,
|
||||
])
|
||||
question.A = simplifyQA(question.A, [
|
||||
removeSpecialChars,
|
||||
removeUnnecesarySpaces,
|
||||
removeAnswerLetters,
|
||||
])
|
||||
return question
|
||||
}
|
||||
|
@ -374,6 +382,7 @@ function searchData(data, question, subjName, questionData) {
|
|||
logger.DebugLog('No subject name as param!', 'qdb search', 1)
|
||||
}
|
||||
question = simplifyQuestion(question)
|
||||
console.log('RESULT: ' + question)
|
||||
|
||||
const worker = new Worker(searchDataWorkerFile, {
|
||||
workerData: { data, subjName, question, questionData },
|
||||
|
@ -443,6 +452,7 @@ function dataToString(data) {
|
|||
return result.join('\n\n')
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
if (!isMainThread) {
|
||||
const { data, subjName, question, questionData } = workerData
|
||||
let result = []
|
||||
|
@ -493,7 +503,9 @@ if (!isMainThread) {
|
|||
})
|
||||
|
||||
parentPort.postMessage(result)
|
||||
process.exit(0)
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
minMatchAmmount,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue