diff --git a/devel/tests/testData/jazz3.json b/devel/tests/testData/jazz3.json new file mode 100644 index 0000000..01572f5 --- /dev/null +++ b/devel/tests/testData/jazz3.json @@ -0,0 +1,77 @@ +{ + "subj": "2019/20/2 - A Jazz kultúrtörténete I.", + "version": "2.0.0.4", + "id": "1584179808101", + "quiz": [ + { + "Q": "Mikor és hol nyeri a világkiállítás nagydíját Bláthy Ottó?", + "A": "a. 1900-ban, Párizsban.", + "data": { + "type": "simple" + } + }, + { + "Q": "Hol és mikor születik a dixieland muzsika koronázatlan királya, LOUIS ARMSTRONG?", + "A": "b. 1901. augusztus 4-én született New-Orleansban.", + "data": { + "type": "simple" + } + }, + { + "Q": "Hogyan hívták Buddy Bolden, legendás New-Orleansi trombitás törzshelyét az 1910-es évek elején?", + "A": "a. New Orleans francia negyedében a még ma is működő Funky Butt Hall.", + "data": { + "type": "simple" + } + }, + { + "Q": "Mikor és kinek sikerült gépkocsival átlépni a 200 km/óra sebességhatárt?", + "A": "a. A hihetetlen 200 km/óra sebességhatárt már 1909-ben sikerült átlépnie Fred Marriot –nak. ", + "data": { + "type": "simple" + } + }, + { + "Q": "Párosítsa az alábbi évszámokat a hozzá tartozó eseményekkel.", + "A": "1901", + "data": { + "type": "simple" + } + }, + { + "Q": "Mikor festi Claude Monet a Waterloo Bridge elnevezésű festményét?", + "A": "a. 1902 –ben", + "data": { + "type": "simple" + } + }, + { + "Q": "Claude Debussy melyik műve van nagy hatással a jazz korai fejlődésére?", + "A": "b. A Párizsi Világkiállítás hatására írt „Cake Walk – gyermek kuckó” című műve.", + "data": { + "type": "simple" + } + }, + { + "Q": "Ki lehetett a „Nobody Knows” című számnak, a fekete spirituálék egyik gyöngyszemének szerzője?", + "A": "b. A feketék hagyományos vallási dalainak, a spirituáléknak eredete kideríthetetlen.", + "data": { + "type": "simple" + } + }, + { + "Q": "Mikor és hol nyeri a világkiállítás nagydíját Bláthy Ottó?", + "A": "b. 1900-ban, Párizsban, a Kultúra és Művészetek Világkiállításán.", + "data": { + "type": "simple" + } + }, + { + "Q": "Mikor és kinek sikerült gépkocsival átlépni a 200 km/óra sebességhatárt?", + "A": "a. 1909-ben, Fred Marriot –nak.", + "data": { + "type": "simple" + } + } + ] +} diff --git a/devel/tests/testData/jazz_Záróteszt.json b/devel/tests/testData/jazz_Záróteszt.json new file mode 100644 index 0000000..54d1cff --- /dev/null +++ b/devel/tests/testData/jazz_Záróteszt.json @@ -0,0 +1,77 @@ +{ + "subj": "2019/20/2 - A Jazz kultúrtörténete I.", + "version": "2.0.0.4", + "id": "1584988073137", + "quiz": [ + { + "Q": "Párosítsa az alábbi évszámokat a hozzá tartozó eseményekkel.", + "A": "A helyes válasz: Meg rendezik Budapesten az első könyvhetet. → 1929, Összeomlik a New York –i tőzsde. → 1929, Salvator DALI megfesti a „Vágy megsejtése” című alkotását. → 1929, Ravel megírja a BOLERÓ-t → 1928.", + "data": { + "type": "simple" + } + }, + { + "Q": "A 20-as évek végefelé erősödik Amerikában a bűnözés. Az egyik maffia banda, a „Buggs” Morgan csoport hét tagját végzik ki a Valentin-napon. Kik végeztek velük?", + "A": "b. A hírhedt rivális banda, Al Capone emberei.", + "data": { + "type": "simple" + } + }, + { + "Q": "Louis Armstrong  elkészíti a jazztörténelem egyik leghíresebb felvételét, King Oliver szerzeményét, a „ ” –t. ", + "A": "1929", + "data": { + "type": "simple" + } + }, + { + "Q": "1928 –as AMSTERDAMI Olimpián, ahol a magyar csapat 5 arany és 5 ezüstérmet szerez. az olimpián speciálisan meghírdetett Irodalom és Epika kategóriában nyer aranyérmet.   ", + "A": "1928", + "data": { + "type": "simple" + } + }, + { + "Q": " jelenik meg Ernest Hemingway „Búcsú a fegyverektől” című regénye, mellyel minden korábbi sikerét felülmúlja. ", + "A": "1928-ban, Chicago-ban", + "data": { + "type": "simple" + } + }, + { + "Q": "A kor egyik leghíresebb énekegyüttese a 20-as évek végén kezdte el pályafutását s rövid idő alatt rendkívül népszerűvé váltak az Egyesült Államokban. A négy testvér 1929-től 1936-ig több tucat hangfelvételt készített, sőt filmen is megörökítették csodálatos éneklésüket.\n\nMi volt a neve ennek a nagysikerű énekegyüttesnek?", + "A": "b. Mills Brothers énekegyüttes.", + "data": { + "type": "simple" + } + }, + { + "Q": "Ki és mikor fedezte fel a penicillint?", + "A": "a. Sir Alexander Fleming fedezte fel 1928-ban, ezzel az első antibiotikum előállításának szellemi atyja lett.", + "data": { + "type": "simple" + } + }, + { + "Q": "Megjelenik a mikrofon és a hangszóró a jazz előadásokon. Milyen hatással van ez a zenekarok hangszerösszetételére és stílusára?", + "A": "a. A tubát felváltja a bőgő, a bendzsót a gitár. Finomodik a kíséret, egyre swingesebb lesz. Nő az ének jelentősége, erősebben dominálnak a zenei elemek.", + "data": { + "type": "simple" + } + }, + { + "Q": "1929.október 24-én összeomlik a New York –i tőzsde. Hosszantartó gazdasági válság indul, amely számos befektetőt az öngyilkosságba kerget. Hogyan hívták azt a napot, amikor kirobbant a katasztrófa?", + "A": "b. „Fekete csütörtök”", + "data": { + "type": "simple" + } + }, + { + "Q": "1929-ben átadják a világ legmagasabb függőhídját, a colorádói Canon Cityben épített Royal Gorge hidat, amely 321 méter magasan ível át a folyó felett. Melyik folyón épült ez a technikai bravúr?", + "A": "c. Az Arkansas folyó felett.", + "data": { + "type": "simple" + } + } + ] +} diff --git a/devel/tests/testData/jezz.json b/devel/tests/testData/jezz.json new file mode 100644 index 0000000..582bd91 --- /dev/null +++ b/devel/tests/testData/jezz.json @@ -0,0 +1,77 @@ +{ + "subj": "2019/20/2 - A Jazz kultúrtörténete I.", + "version": "2.0.0.4", + "id": "1584990182513", + "quiz": [ + { + "Q": "1924-ben kinek a zenekárhoz csatlakozott Louis Armstrong?", + "A": "b. Fletcher Henderson", + "data": { + "type": "simple" + } + }, + { + "Q": "Kinek a vezényletével mutatták be a „Rhapsody in Blue” George Gershwin zeneművét?", + "A": "a. Paul Whiteman", + "data": { + "type": "simple" + } + }, + { + "Q": "Meghal Lenin. Hitler megírja a „Mein Kampf” –ot. Wladyslav Stanislav REYMONT lengyel regényíró, elbeszélő irodalmi Nobel-díjat kap „nagy nemzeti eposzáért – a Parasztok –ért”.  Melyik évben járunk?", + "A": "b. 1924", + "data": { + "type": "simple" + } + }, + { + "Q": "Kinek a tervei alapján elkészül el Izraelben a Minden Nemzetek Temploma az „olajsajtolók kertje” nevű szent helyen?", + "A": "a. Antonio Berluzzi tervei alapján. ", + "data": { + "type": "simple" + } + }, + { + "Q": "1923-ban Walter Gropius német építész megépíti a dessaui Állami Bauhaus épületét, amelyik a modern építészet szimbólumává vált.  Mit vallottak a „Bauhaus építészeti iskola” tagjai?", + "A": "a. Az épület van az emberért, meg kell ismerni a használót, és annak igényeit figyelembe véve kell tervezni az épületeket.", + "data": { + "type": "simple" + } + }, + { + "Q": "Mikor komponálta Gershwin egyik híres számát, a „Somebody Loves Me” című dalt?", + "A": "b. 1924-ben ", + "data": { + "type": "simple" + } + }, + { + "Q": "Párosítsa az alábbi évszámokat a hozzá tartozó eseményekkel.", + "A": "A helyes válasz: Meghal Lenin. → 1924, Megszületik George GERSHWIN, eredeti nevén Jacob Gershvin. → 1898, Wladyslav Stanislav REYMONT (1867-1925) lengyel regényíró, elbeszélő irodalmi Nobel-díjat kap „nagy nemzeti eposzáért – a Parasztok –ért”. → 1924, Meghal Wilhelm Conrad Röntgen. → 1923, Walter Gropius (1883-1969) német építész megépíti a dessaui Állami Bauhaus épületét. → 1923, Hitler megírja a „Mein Kampf” –ot. → 1924, Názáret közelében a Tábor hegyen befejezik Jézus színeváltozásának temploma építését. → 1923.", + "data": { + "type": "simple" + } + }, + { + "Q": "Kinek ajánlotta Bartók Béla egy a magyar népdalfeldolgozások műfajába sorolható művét, az 1. Rapszódiát?", + "A": "b. Szigeti József hegedűművésznek ajánlotta, aki Bartók műveinek egyik legismertebb interpretátora volt.", + "data": { + "type": "simple" + } + }, + { + "Q": "Hány évig játszott Louis Armstrong a King Oliver Creol Jazz Band-ben?", + "A": "a. Legalább két évig", + "data": { + "type": "simple" + } + }, + { + "Q": "Mikor és hol született George Gershwin (eredeti nevén Jacob Gershwin)?", + "A": "b. George Gershwin (eredeti nevén Jacob Gershwin) 1898. szeptember 26-án született a mai Brooklyn-ban.", + "data": { + "type": "simple" + } + } + ] +} diff --git a/modules/qmining/qmining-page b/modules/qmining/qmining-page index b22e101..25eb4ea 160000 --- a/modules/qmining/qmining-page +++ b/modules/qmining/qmining-page @@ -1 +1 @@ -Subproject commit b22e101477ef2ef87c844b91bd3c29863320bc29 +Subproject commit 25eb4ea7b6529c0bdb6e54c73346a18ddeebb599 diff --git a/utils/actions.js b/utils/actions.js index 87b790a..8b460f6 100755 --- a/utils/actions.js +++ b/utils/actions.js @@ -19,13 +19,11 @@ Question Server module.exports = { ProcessIncomingRequest: ProcessIncomingRequest, - LoadJSON: LoadJSON, - ProcessQA: ProcessQA + LoadJSON: LoadJSON } const dataFile = './public/data.json' const recDataFile = './stats/recdata' -const qaFile = './public/qa' const logger = require('../utils/logger.js') const idStats = require('../utils/ids.js') @@ -163,26 +161,3 @@ function LoadJSON (dataFile) { console.log(e) } } - -function ProcessQA () { - if (!utils.FileExists(qaFile)) { utils.WriteFile('', qaFile) } - - let a = utils.ReadFile(qaFile).split('\n') - let r = [] - let ind = 0 - for (let i = 0; i < a.length; i++) { - if (a[i] === '#') { ind++ } else { - if (r[ind] === undefined) { r[ind] = {} } - - if (r[ind].q === undefined) { - r[ind].q = a[i] - } else { - if (r[ind].a === undefined) { r[ind].a = [] } - - r[ind].a.push(a[i]) - } - } - } - - return r -} diff --git a/utils/dataUpdater.js b/utils/dataUpdater.js deleted file mode 100755 index be22220..0000000 --- a/utils/dataUpdater.js +++ /dev/null @@ -1,637 +0,0 @@ -/* ---------------------------------------------------------------------------- - - Question Server question file merger - GitLab: - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - - ------------------------------------------------------------------------- */ - -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 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') } -} - -class StringUtils { - RemoveStuff (value, removableStrings, toReplace) { - removableStrings.forEach((x) => { - var regex = new RegExp(x, 'g') - value = value.replace(regex, toReplace || '') - }) - return value - } - - SimplifyQuery (q) { - assert(q) - - var result = q.replace(/\n/g, ' ').replace(/\s/g, ' ') - return this.RemoveUnnecesarySpaces(result) - } - - ShortenString (toShorten, ammount) { - assert(toShorten) - - var result = '' - var i = 0 - while (i < toShorten.length && i < ammount) { - result += toShorten[i] - i++ - } - return result - } - - ReplaceCharsWithSpace (val, char) { - assert(val) - assert(char) - - var toremove = this.NormalizeSpaces(val) - - var regex = new RegExp(char, 'g') - toremove = toremove.replace(regex, ' ') - - return this.RemoveUnnecesarySpaces(toremove) - } - - // removes whitespace from begining and and, and replaces multiple spaces with one space - RemoveUnnecesarySpaces (toremove) { - assert(toremove) - - toremove = this.NormalizeSpaces(toremove) - while (toremove.includes(' ')) { - toremove = toremove.replace(/ {2}/g, ' ') - } - 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) { - assert(value) - - return this.RemoveStuff(value, specialChars, ' ') - } - - // if the value is empty, or whitespace - EmptyOrWhiteSpace (value) { - // replaces /n-s with "". then replaces spaces with "". if it equals "", then its empty, or only consists of white space - if (value === undefined) { return true } - return (value.replace(/\n/g, '').replace(/ /g, '').replace(/\s/g, ' ') === '') - } - - // damn nonbreaking space - NormalizeSpaces (input) { - assert(input) - - 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) { - return this.SimplifyQuery(stack) - } -} - -const SUtils = new StringUtils() - -class Question { - constructor (q, a, i) { - this.Q = SUtils.SimplifyQuestion(q) - this.A = SUtils.SimplifyAnswer(a) - this.I = i - } - - toString () { - var r = '?' + this.Q + '\n!' + this.A - if (this.I) { r += '\n>' + this.I } - return r - } - - HasQuestion () { - return this.Q !== undefined - } - - HasAnswer () { - return this.A !== undefined - } - - HasImage () { - return this.I !== undefined && (typeof this.I === 'string' || Array.isArray(this.I)) - } - - IsComplete () { - return this.HasQuestion() && this.HasAnswer() - } - - Compare (q2, i) { - assert(q2) - - if (typeof q2 === 'string') { - var qmatchpercent = SUtils.CompareString(this.Q, q2) - - if (i === undefined || i.length === 0) { return qmatchpercent } else { - if (this.HasImage()) { - const imatchpercent = this.HasImage() ? SUtils.CompareString(this.I.join(' '), i.join(' ')) - : 0 - return (qmatchpercent + imatchpercent) / 2 - } else { - qmatchpercent -= 30 - if (qmatchpercent < 0) { return 0 } else { return qmatchpercent } - } - } - } else { - const qmatchpercent = SUtils.CompareString(this.Q, q2.Q) - const amatchpercent = SUtils.CompareString(this.A, q2.A) - if (this.I !== undefined) { - const imatchpercent = this.I === undefined ? SUtils.CompareString(this.I.join(' '), q2.I.join( - ' ')) : 0 - return (qmatchpercent + amatchpercent + imatchpercent) / 3 - } else { - return (qmatchpercent + amatchpercent) / 2 - } - } - } -} - -class Subject { - constructor (n) { - assert(n) - - this.Name = n - this.Questions = [] - this.active = false - } - - setIndex (i) { - this.index = i - } - - getIndex () { - return this.index || -1 - } - - get length () { - return this.Questions.length - } - - markActive () { - this.active = true - } - - getIfActive () { - return this.active - } - - AddQuestion (q) { - assert(q) - - this.Questions.push(q) - } - - getSubjNameWithoutYear () { - let t = this.Name.split(' - ') - if (t[0].match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{1}$/i)) { - return t[1] || '' - } else { - return '' - } - } - - getYear () { - let t = this.Name.split(' - ')[0] - if (t.match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{1}$/i)) { - return t - } else { - return '' - } - } - - Search (q, img) { - assert(q) - - var r = [] - for (let i = 0; i < this.length; i++) { - let percent = this.Questions[i].Compare(q, img) - if (percent > minMatchAmmount) { - r.push({ - q: this.Questions[i], - match: percent - }) - } - } - - for (let i = 0; i < r.length; i++) { - for (var j = i; j < r.length; j++) { - if (r[i].match < r[j].match) { - var tmp = r[i] - r[i] = r[j] - r[j] = tmp - } - } - } - - return r - } - - toString () { - var r = [] - for (var i = 0; i < this.Questions.length; i++) { r.push(this.Questions[i].toString()) } - return '+' + this.Name + '\n' + r.join('\n') - } -} - -class QuestionDB { - constructor (getVal, setVal) { - this.Subjects = [] - this.getVal = getVal - this.setVal = setVal - } - - get length () { - return this.Subjects.length - } - - get activeIndexes () { - var r = [] - for (var i = 0; i < this.length; i++) { - if (this.getVal('Is' + i + 'Active')) { - r.push(i) - } - } - return r - } - - GetIfActive (ind) { - return this.getVal('Is' + ind + 'Active') - } - - ChangeActive (i, value) { - this.setVal('Is' + i + 'Active', !!value) - } - - AddQuestion (subj, q) { - assert(subj) - - var i = 0 - while (i < this.Subjects.length && this.Subjects[i].Name !== subj) { i++ } - if (i < this.Subjects.length) { this.Subjects[i].AddQuestion(q) } else { - const n = new Subject(subj) - n.AddQuestion(q) - this.Subjects.push(n) - } - } - - Search (q, img) { - assert(q) - - var r = [] - for (let i = 0; i < this.length; i++) { - if (this.GetIfActive(i)) { r = r.concat(this.Subjects[i].Search(q, img)) } - } - - for (let i = 0; i < r.length; i++) { - for (var j = i; j < r.length; j++) { - if (r[i].match < r[j].match) { - var tmp = r[i] - r[i] = r[j] - r[j] = tmp - } - } - } - - return r - } - - AddSubject (subj) { - assert(subj) - - var i = 0 - while (i < this.length && subj.Name !== this.Subjects[i].Name) { i++ } - - if (i < this.length) { - this.Subjects.concat(subj.Questions) - } else { - this.Subjects.push(subj) - } - } - - toString () { - var r = [] - for (var i = 0; i < this.Subjects.length; i++) { r.push(this.Subjects[i].toString()) } - return r.join('\n\n') - } -} - -module.exports.StringUtils = StringUtils -module.exports.Question = Question -module.exports.Subject = Subject -module.exports.QuestionDB = QuestionDB -const utils = require('./utils.js') - -Main() - -function Main () { - console.clear() - const params = GetParams() - console.log(params) - var db = [] - - PrintLN() - console.log(params[0] + ': ') - try { - db = ParseJSONData(utils.ReadFile(params[0])) - console.log('JSON data added') - } catch (e) { - console.log(e) - console.log('Trying with old format...') - db = ReadData(utils.ReadFile(params[0])).result - } - PrintLN() - - PrintDB(db) - - PrintLN() - - RefactorDb(db) - - utils.WriteFile(JSON.stringify(db), 'newData') -} - -function RefactorDb (db) { - db.Subjects.forEach((subj) => { - subj.Questions.forEach((question) => { - if (question.I) { - question.data = { - type: 'image', - images: typeof question.I === 'string' ? JSON.parse(question.I) : question.I - } - delete question.I - } else { - question.data = { - type: 'simple' - } - } - }) - }) -} - -// ----------------------------------------------------------------------------------------- - -function PrintLN () { - console.log('------------------------------------------------------') -} - -function PrintDB (r, olds) { - console.log('Data subject count: ' + r.length) - var maxLength = 0 - for (let i = 0; i < r.length; i++) { - if (maxLength < r.Subjects[i].Name.length) { maxLength = r.Subjects[i].Name.length } - } - - let qcount = 0 - - for (let i = 0; i < r.length; i++) { - let line = i - if (line < 10) { line += ' ' } - - line += ': ' - var currLength = line.length + maxLength + 4 - line += r.Subjects[i].Name - - while (line.length < currLength) { - if (i % 4 === 0) { line += '.' } else { line += ' ' } - } - - if (olds && olds.length > 0) { - // TODO: check if correct row! should be now, but well... - if (olds[i] < 10) { line += ' ' } - if (olds[i] < 100) { line += ' ' } - - line += olds[i] - line += ' -> ' - } - - if (r.Subjects[i].length < 10) { line += ' ' } - if (r.Subjects[i].length < 100) { line += ' ' } - - line += r.Subjects[i].length - qcount += r.Subjects[i].length - - line += ' db' - - console.log(line) - } - - console.log('Total questions: ' + qcount) - - PrintLN() -} - -function GetParams () { - return process.argv.splice(2) -} - -function ParseJSONData (data) { - var d = JSON.parse(data) - var r = new QuestionDB((x) => true, (x, y) => console.log(x, y)) - var rt = [] - - for (var i = 0; i < d.Subjects.length; i++) { - let s = new Subject(d.Subjects[i].Name) - var j = 0 - for (j = 0; j < d.Subjects[i].Questions.length; j++) { - var currQ = d.Subjects[i].Questions[j] - s.AddQuestion(new Question(currQ.Q, currQ.A, currQ.I)) - } - rt.push({ - name: d.Subjects[i].Name, - count: j - }) - r.AddSubject(s) - } - return r -} - -function ReadData (data) { - const d = data.split('\n') - const r = new QuestionDB((x) => true, (x, y) => console.log(x, y)) - var logs = [] - var currSubj = '' // the current subjects name - var ExpectedIdentifier = ['+', '?'] - let currQuestion = new Question() - - var i = -1 - while (i < d.length) { - let currIdentifier - let skipped = 0 - do { - if (skipped >= 1) { logs.push(i + ': ' + d[i]) } - i++ - if (i >= d.length) { - if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) } - return { - result: r, - logs: logs - } - } - currIdentifier = d[i][0] - skipped++ - } while (!ExpectedIdentifier.includes(currIdentifier) && i < d.length) - - let currData = d[i].substring(1).trim() - - if (currIdentifier === '+') { - if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) } - currQuestion = new Question() - currSubj = currData - ExpectedIdentifier = ['?'] - continue - } - - if (currIdentifier === '?') { - if (currQuestion.IsComplete()) { - r.AddQuestion(currSubj, currQuestion) - currQuestion = new Question() - } - // overwriting is allowed here, bcus: - // ?????!> - currQuestion.Q = currData - ExpectedIdentifier = ['!', '?'] - continue - } - - if (currIdentifier === '!') { - // if dont have question continue - if (!currQuestion.HasQuestion()) { throw new Error('No question! (A)') } - // dont allow overwriting - // ?!!!! - if (!currQuestion.HasAnswer()) { - currData = currData.replace('A helyes válaszok: ', '') - currData = currData.replace('A helyes válasz: ', '') - - currQuestion.A = currData - } - ExpectedIdentifier = ['?', '>', '+'] - continue - } - - if (currIdentifier === '>') { - // if dont have question or answer continue - if (!currQuestion.HasQuestion()) { throw new Error('No question! (I)') } - if (!currQuestion.HasAnswer()) { throw new Error('No asnwer! (I)') } - // dont allow overwriting - // ?!>>> - if (!currQuestion.HasImage()) { - try { - currQuestion.I = JSON.parse(currData) - } catch (e) { - currQuestion.I = currData.split(',') - } - } - ExpectedIdentifier = ['?', '+'] - continue - } - } - - return { - result: r, - logs: logs - } -} diff --git a/utils/dbcheck.js b/utils/dbcheck.js deleted file mode 100644 index e5fdbb9..0000000 --- a/utils/dbcheck.js +++ /dev/null @@ -1,64 +0,0 @@ -/* ---------------------------------------------------------------------------- - - Question Server question file merger - GitLab: - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - - ------------------------------------------------------------------------- */ - -const utils = require('./utils.js') - -Main() - -function Main () { - console.clear() - const params = GetParams() - console.log(params) - var db = [] - let errors = 0 - - PrintLN() - console.log(params[0] + ': ') - try { - db = JSON.parse(utils.ReadFile(params[0])) - db.Subjects.forEach((subj) => { - subj.Questions.forEach((question) => { - if (question.I) { - console.log('gebasz') - console.log(subj.Name) - console.log(question) - PrintLN() - errors++ - } - }) - }) - } catch (e) { - console.log(e) - } - PrintLN() - console.log(`done, ${errors} error`) - - // utils.WriteFile(JSON.stringify(db), 'newData') -} - -// ----------------------------------------------------------------------------------------- - -function PrintLN () { - console.log('------------------------------------------------------') -} - -function GetParams () { - return process.argv.splice(2) -} diff --git a/utils/merger.js b/utils/merger.js index a306e85..4a113df 100755 --- a/utils/merger.js +++ b/utils/merger.js @@ -96,13 +96,18 @@ function PrintDB (r, olds) { if (i % 4 === 0) { line += '.' } else { line += ' ' } } + let tolog = true if (olds && olds.length > 0) { - // TODO: check if correct row! should be now, but well... - if (olds[i] < 10) { line += ' ' } - if (olds[i] < 100) { line += ' ' } + if (r.Subjects[i].length !== olds[i]) { + // TODO: check if correct row! should be now, but well... + if (olds[i] < 10) { line += ' ' } + if (olds[i] < 100) { line += ' ' } - line += olds[i] - line += ' -> ' + line += olds[i] + line += ' -> ' + } else { + tolog = false + } } if (r.Subjects[i].length < 10) { line += ' ' } @@ -113,7 +118,9 @@ function PrintDB (r, olds) { line += ' db' - console.log(line) + if (tolog) { + console.log(line) + } } console.log('Total questions: ' + qcount) @@ -165,7 +172,7 @@ function RemoveDuplFromSubject (subj) { for (var i = 0; i < cp.length; i++) { var j = 0 // Only removes 100% match! - while (j < subj.length && cp[i].Compare(subj.Questions[j]) !== 100) { + while (j < subj.length && cp[i].Compare(subj.Questions[j]).avg <= 99) { j++ } if (j < subj.length) { diff --git a/utils/readme.md b/utils/readme.md new file mode 100644 index 0000000..6ddd567 --- /dev/null +++ b/utils/readme.md @@ -0,0 +1,86 @@ +# Contents + +Utils mappa tartalom + +## merger.js + +Törölve lesz + +## merge.sh + +Törölve lesz + +## rmDuplicates.js + +Tervezve + +Kitörli a két vagy többször szereplő kérdéseket + +Params: + +1. Elérési út a JSON adatbázishoz + +## actions.js + +Át lesz nevezve: `questionProcessor.js` + +JSON adatbázist betölti, és az új bejövő kérdéseket hozzáadja + +Exportált funkciók: + +1. ProcessIncomingRequest +2. LoadJSON + +## utils.js + +Általános eszközök + +Exportált funkciók: + +1. ReadFile +2. WriteFile +3. writeFileAsync +4. AppendToFile +5. Beep +6. WriteBackup +7. FileExists +8. CreatePath +9. WatchFile +10. ReadDir + +## logger.js + +Logolást kezeli + +Exportált funkciók: + +1. GetDateString +2. Log +3. DebugLog +4. GetColor +5. LogReq +6. LogStat +7. Load +8. logHashed +9. hr + +## motd.js + +Az adatbázis MOTD-ét változtatja meg. Elvileg már nem kell + +`node motd.js "new motd"` + +## changedataversion.js + +Az adatbázis jelenlegi legfrissebb kliens verzióját változtatja meg. Elvileg már nem kell + +`node motd.js "new version"` + +## ids.js + +`./stats/idstats` és `./stats/idvstats` ba írja a egyedi kliens ID statisztikákat + +Exportált funkciók: + +1. LogId +2. Load