From b5d5f20b79b9b14175fa81c252d6ee90f7ad4116 Mon Sep 17 00:00:00 2001 From: mrfry Date: Thu, 14 Jan 2021 17:10:30 +0100 Subject: [PATCH] Empty question fix --- devel/tests/testData/cantParseJSON.json | 48 ++++++++++ devel/tests/testData/emptyAnswer.json | 78 +++++++++++++++ devel/tests/testData/emptyQuestion.json | 96 +++++++++++++++++++ .../starInAnswerAddedMultipleTimes.json | 14 +++ src/utils/actions.ts | 73 ++++++++------ src/utils/classes.ts | 6 +- 6 files changed, 284 insertions(+), 31 deletions(-) create mode 100644 devel/tests/testData/cantParseJSON.json create mode 100644 devel/tests/testData/emptyAnswer.json create mode 100644 devel/tests/testData/emptyQuestion.json create mode 100644 devel/tests/testData/starInAnswerAddedMultipleTimes.json diff --git a/devel/tests/testData/cantParseJSON.json b/devel/tests/testData/cantParseJSON.json new file mode 100644 index 0000000..8e32c0c --- /dev/null +++ b/devel/tests/testData/cantParseJSON.json @@ -0,0 +1,48 @@ +{ + "subj": "2020/21/1 - Digitális rendszerek - NIXDR0HBNE/DR0_EA", + "version": "2.0.1.13", + "id": "0347000752702", + "quiz": [ + { + "Q": "\n", + "A": "A helyes válasz: Bináris lefele számláló.", + "data": { + "type": "image", + "images": [ + "wHFd9y6nWIHCAAAAABJRU5ErkJggg=" + ] + } + }, + { + "Q": "\n", + "A": "D.\n\njobbra létető regiszter\n", + "data": { + "type": "image", + "images": [ + "AcLnpIDsSgLsAAAAAElFTkSuQmCC" + ] + } + }, + { + "Q": "A regiszter feladata\n", + "A": "A.\n\nvezérlési feladatok\n", + "data": { + "type": "simple" + } + }, + { + "Q": "A regiszter feladata\n", + "A": "D.\n\nÁtmeneti tárolás\n", + "data": { + "type": "simple" + } + }, + { + "Q": "signal d : STD_LOGIC_VECTOR(3 downto 0);\n\nsignal q : STD_LOGIC_VECTOR(3 downto 0);\n\nsignal clk: STD_LOGIC;\n\n…\n\nprocess\n\nBegin\n\n  if (clear = ’1’) then\n\n  q <= ”0000”;\n\n  elsif (clk`event and clk = ’1’) then\n   q <= d;\nend if;\n\nend process;\n\n\n", + "A": "B.\n\ntároló regiszter\n", + "data": { + "type": "simple" + } + } + ] +} diff --git a/devel/tests/testData/emptyAnswer.json b/devel/tests/testData/emptyAnswer.json new file mode 100644 index 0000000..3a00d02 --- /dev/null +++ b/devel/tests/testData/emptyAnswer.json @@ -0,0 +1,78 @@ +{ + "subj": "2020/21/1 - Pénzügyek alapjai - GGEPU1GFNE/PA-GY2", + "version": "2.0.1.18", + "id": "0672665270899", + "location": "https://elearning.uni-obuda.hu/asd", + "quiz": [ + { + "Q": "540.000 Ft-ot elhelyezünk bankbetét formájában 30 napra 18%-os kamatláb mellett. Az év napjait 365-tel számolja. Mekkora lesz a kamatjövedelem, amit felvehetünk a betétünk után (kerekítve)?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "Önnek 3 év múlva 3.000.000 Ft-ra lesz szüksége. Mennyi pénzt helyezzen el ma ahhoz 12% kamatláb mellett, hogy ezt a tervét megvalósítsa, ha a bank a kamatokat négy havonta tőkésíti?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "Egy kereskedelmi bank évi 6% betéti kamatot ajánl, a kamatok félévenkénti tőkésítése mellett. Hány forintot kellene „ma” elhelyezni, ha azt szeretnénk, hogy 10 év múlva 20.000.000 Ft-unk legyen?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "Hány forinttal rendelkeznénk 2,5 év múlva, ha ma elhelyeznénk 500.000 Ft-ot és a bank a kamatokat havonta tőkésítené 12%-os kamatláb mellett?\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "Bankbetét formájában elhelyezünk 90.000 Ft-ot 3 évre, 14%-os kamatra. Mennyi pénzünk lesz három év múlva, ha a bank kamatos kamattal számol?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "300.000 Ft-ot helyezünk el a számlánkon lekötött betét formájában 16%-os kamatláb mellett két évre negyedéves tőkésítés mellett. Mekkora összeggel rendelkezünk a befektetés lejártakor?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "Mennyi pénz lesz 900.000 Ft-ból 3 év alatt 15%-os kamatláb esetén, ha a kamatok tőkésítésére nem kerül sor a futamidő alatt?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "200.000 Ft-ot szeretne elhelyezni 10%-os kamatláb mellett a bankba féléves tőkésítés mellett. Mekkora összeget vehet fel egy év múlva?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "Hány forintunk lenne a bankszámlán 25 év múlva, ha ma elhelyezünk 250.000 Ft-on a bankszámlán, és a bank évi 4%-os kamatot ígér, félévenkénti tőkésítéssel?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "Mennyi pénzt helyezzünk el ma bankbetét formájában, ha azt szeretnénk, hogy négy év múlva 220.000 Ft-unk legyen 8% kamatláb mellett?\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + } + ] +} diff --git a/devel/tests/testData/emptyQuestion.json b/devel/tests/testData/emptyQuestion.json new file mode 100644 index 0000000..2d3eb3e --- /dev/null +++ b/devel/tests/testData/emptyQuestion.json @@ -0,0 +1,96 @@ +{ + "subj": "2020/21/1 - Pénzügyek alapjai - GGEPU1GFNE/PA-GY2", + "version": "2.0.1.18", + "id": "0672665270899", + "location": "https://elearning.uni-obuda.hu/asd", + "quiz": [ + { + "Q": "", + "A": "", + "data": { + "type": "simple" + } + }, + { + "Q": "\n\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "", + "A": "\n\n\n\n", + "data": { + "type": "simple" + } + }, + { + "Q": "\n\n\n\n", + "A": "", + "data": { + "type": "simple" + } + }, + { + "Q": "", + "A": "", + "data": { + "type": "image", + "images": [ + "Cu_Ag.jpg" + ] + } + }, + { + "Q": "\n\n\n\n", + "A": "\n\n\n\n", + "data": { + "type": "image", + "images": [ + "Cu_Ag.jpg" + ] + } + }, + { + "Q": "", + "A": "\n\n\n\n", + "data": { + "type": "image", + "images": [ + "Cu_Ag.jpg" + ] + } + }, + { + "Q": "\n\n\n\n", + "A": "", + "data": { + "type": "image", + "images": [ + "Cu_Ag.jpg" + ] + } + }, + { + "Q": "This should be valid", + "A": "\n\n\n\n", + "data": { + "type": "image", + "images": [ + "Cu_Ag.jpg" + ] + } + }, + { + "Q": "This should be valid", + "A": "", + "data": { + "type": "image", + "images": [ + "Cu_Ag.jpg" + ] + } + } + ] +} diff --git a/devel/tests/testData/starInAnswerAddedMultipleTimes.json b/devel/tests/testData/starInAnswerAddedMultipleTimes.json new file mode 100644 index 0000000..ab17361 --- /dev/null +++ b/devel/tests/testData/starInAnswerAddedMultipleTimes.json @@ -0,0 +1,14 @@ +{ + "subj": "2020/21/1 - Digitális rendszerek - AMXDR0IBNE/E", + "version": "2.0.1.13", + "id": "1586202966729", + "quiz": [ + { + "Q": "Adott egy háromváltozós függvény, amely akkor 0 értékű, ha a 3 változóból legalább 2, 0 értékű. Válassza ki  a konjunktív kanonikus alakban szereplő maxtermeket amelyek ÉS kapcsolata adja az Y függvényt!", + "A": "A helyes válaszok: nC+B+A, C+nB+A, C+B+nA, C+B+A", + "data": { + "type": "simple" + } + } + ] +} diff --git a/src/utils/actions.ts b/src/utils/actions.ts index f259311..b072647 100755 --- a/src/utils/actions.ts +++ b/src/utils/actions.ts @@ -97,7 +97,7 @@ export function processIncomingRequest( dryRun: boolean, user: User ): Promise> { - logger.DebugLog('Processing incoming request', 'actions', 1) + logger.DebugLog('Processing incoming request', 'isadding', 1) if (recievedData === undefined) { logger.Log('\tRecieved data is undefined!', logger.GetColor('redbg')) @@ -116,7 +116,7 @@ export function processIncomingRequest( towrite += '\n------------------------------------------------------------------------------\n' utils.AppendToFile(towrite, recDataFile) - logger.DebugLog('recDataFile written', 'actions', 1) + logger.DebugLog('recDataFile written', 'isadding', 1) } catch (err) { logger.Log('Error writing recieved data.') } @@ -147,13 +147,13 @@ function processIncomingRequestUsingDb( try { const recievedQuestions = [] - logger.DebugLog('recievedData JSON parsed', 'actions', 1) - logger.DebugLog(recievedData, 'actions', 3) + logger.DebugLog('recievedData JSON parsed', 'isadding', 1) + logger.DebugLog(recievedData, 'isadding', 3) const allQLength = recievedData.quiz.length const questionSearchPromises = [] recievedData.quiz.forEach((question) => { - logger.DebugLog('Question:', 'actions', 2) - logger.DebugLog(question, 'actions', 2) + logger.DebugLog('Question:', 'isadding', 2) + logger.DebugLog(question, 'isadding', 2) const currentQuestion = createQuestion( question.Q, question.A, @@ -161,24 +161,29 @@ function processIncomingRequestUsingDb( ) logger.DebugLog( 'Searching for question in subj ' + recievedData.subj, - 'actions', + 'isadding', 3 ) - logger.DebugLog(currentQuestion, 'actions', 3) - recievedQuestions.push(currentQuestion) - // This here searches only in relevant subjects, and not all subjects - questionSearchPromises.push( - doALongTask({ - type: 'work', - data: { - searchIn: [qdb.index], - qdb: qdb.data, - question: currentQuestion, - subjName: recievedData.subj, - searchTillMatchPercent: minMatchAmmountToAdd, - }, - }) - ) + logger.DebugLog(currentQuestion, 'isadding', 3) + if (isQuestionValid(currentQuestion)) { + recievedQuestions.push(currentQuestion) + // This here searches only in relevant subjects, and not all subjects + questionSearchPromises.push( + doALongTask({ + type: 'work', + data: { + searchIn: [qdb.index], + qdb: qdb.data, + question: currentQuestion, + subjName: recievedData.subj, + searchTillMatchPercent: minMatchAmmountToAdd, + }, + }) + ) + } else { + logger.DebugLog('Question isnt valid', 'isadding', 1) + logger.DebugLog(currentQuestion, 'isadding', 1) + } }) Promise.all(questionSearchPromises) @@ -199,22 +204,22 @@ function processIncomingRequestUsingDb( const sName = getSubjNameWithoutYear(recievedData.subj) logger.DebugLog( 'Adding question with subjName: ' + sName + ' :', - 'actions', + 'isadding', 3 ) - logger.DebugLog(currentQuestion, 'actions', 3) + logger.DebugLog(currentQuestion, 'isadding', 3) addQuestion(qdb.data, sName, currentQuestion) }) currWrites++ logger.DebugLog( 'currWrites for data.json: ' + currWrites, - 'actions', + 'isadding', 1 ) if (currWrites >= writeAfter && !dryRun) { currWrites = 0 - logger.DebugLog('Writing data.json', 'actions', 1) + logger.DebugLog('Writing data.json', 'isadding', 1) utils.WriteFile(JSON.stringify(qdb.data), qdb.path) } } @@ -226,10 +231,10 @@ function processIncomingRequestUsingDb( allQLength ) - logger.DebugLog('New Questions:', 'actions', 2) - logger.DebugLog(allQuestions, 'actions', 2) + logger.DebugLog('New Questions:', 'isadding', 2) + logger.DebugLog(allQuestions, 'isadding', 2) - logger.DebugLog('ProcessIncomingRequest done', 'actions', 1) + logger.DebugLog('ProcessIncomingRequest done', 'isadding', 1) resolve({ newQuestions: allQuestions.length, qdbName: qdb.name, @@ -263,6 +268,16 @@ function processIncomingRequestUsingDb( }) } +function isQuestionValid(question: Question) { + if (!question.Q) { + return false + } + if (!question.Q && question.data.type !== 'image') { + return false + } + return true +} + export function shouldSearchDataFile(df: DataFile, testUrl: string): Boolean { if (typeof df.shouldSearch === 'string' && df.shouldSearch === 'always') { return true diff --git a/src/utils/classes.ts b/src/utils/classes.ts index 214dec6..893f8ee 100755 --- a/src/utils/classes.ts +++ b/src/utils/classes.ts @@ -126,7 +126,9 @@ function compareString(string1: string, string2: string) { } function answerPreProcessor(value: string) { - assert(value) + if (!value) { + return value + } return removeStuff(value, commonUselessAnswerParts) } @@ -208,7 +210,7 @@ function createQuestion( ): Question { return { Q: simplifyQuestion(question), - A: answer ? simplifyAnswer(answer) : null, + A: answer ? simplifyAnswer(answer) : undefined, data: data, } }