Fixed bugs that came from declassifying classes.js

This commit is contained in:
mrfry
2020-10-02 18:16:19 +02:00
parent db1976ecf3
commit ecd3a9805f
6 changed files with 92 additions and 116 deletions
+5 -13
View File
@@ -1,18 +1,14 @@
const { isMainThread, parentPort, workerData } = require('worker_threads')
const logger = require('../utils/logger.js')
const actions = require('../utils/actions.js')
const classes = require('./classes.js')
classes.initLogger(logger.DebugLog)
const { createQuestion, searchData } = require('./classes.js')
const minMatchAmmountToAdd = 90 // FIXME: test this value
if (!isMainThread) {
logger.DebugLog('Starting worker thread', 'processdata', 1)
logger.DebugLog(workerData, 'processdata', 1)
logger.DebugLog(workerData, 'processdata', 3)
parentPort.postMessage(
ProcessData(workerData.data, actions.LoadJSONFromObject(workerData.qdb))
)
parentPort.postMessage(ProcessData(workerData.data, workerData.qdb))
} else {
logger.Log(
'Porcess data should not run on main thread!',
@@ -26,15 +22,11 @@ function ProcessData(data, qdb) {
data.quiz.forEach((question) => {
logger.DebugLog('Question:', 'actions', 2)
logger.DebugLog(question, 'actions', 2)
let currentQuestion = new classes.Question(
question.Q,
question.A,
question.data
)
let currentQuestion = createQuestion(question.Q, question.A, question.data)
logger.DebugLog('Searching for question in subj ' + data.subj, 'actions', 3)
logger.DebugLog(currentQuestion, 'actions', 3)
let sames = qdb.Search(currentQuestion, data.subj)
let sames = searchData(qdb, currentQuestion, data.subj)
logger.DebugLog('Same questions:', 'actions', 2)
logger.DebugLog('Length: ' + sames.length, 'actions', 2)
logger.DebugLog(sames, 'actions', 3)