mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Handling old data
This commit is contained in:
parent
bb23853043
commit
2f6f39c294
34 changed files with 41 additions and 94 deletions
0
.gitmodules
vendored
Normal file → Executable file
0
.gitmodules
vendored
Normal file → Executable file
0
README.md
Normal file → Executable file
0
README.md
Normal file → Executable file
0
license
Normal file → Executable file
0
license
Normal file → Executable file
0
modules/main.js
Normal file → Executable file
0
modules/main.js
Normal file → Executable file
0
modules/old.js
Normal file → Executable file
0
modules/old.js
Normal file → Executable file
0
modules/qmining.js
Normal file → Executable file
0
modules/qmining.js
Normal file → Executable file
0
modules/sio.js
Normal file → Executable file
0
modules/sio.js
Normal file → Executable file
0
modules/stuff.js
Normal file → Executable file
0
modules/stuff.js
Normal file → Executable file
0
package.json
Normal file → Executable file
0
package.json
Normal file → Executable file
0
public/favicon.ico
Normal file → Executable file
0
public/favicon.ico
Normal file → Executable file
Before Width: | Height: | Size: 252 KiB After Width: | Height: | Size: 252 KiB |
0
server.js
Normal file → Executable file
0
server.js
Normal file → Executable file
40
utils/actions.js
Normal file → Executable file
40
utils/actions.js
Normal file → Executable file
|
@ -54,6 +54,9 @@ function ProcessIncomingRequest (data) {
|
||||||
try {
|
try {
|
||||||
var d = JSON.parse(data)
|
var d = JSON.parse(data)
|
||||||
var allQuestions = []
|
var allQuestions = []
|
||||||
|
|
||||||
|
d = ConvertToNewFormat(d)
|
||||||
|
|
||||||
for (let i = 0; i < d.allData.length; i++) {
|
for (let i = 0; i < d.allData.length; i++) {
|
||||||
allQuestions.push(new classes.Question(d.allData[i].Q, d.allData[i].A, d.allData[i].data))
|
allQuestions.push(new classes.Question(d.allData[i].Q, d.allData[i].A, d.allData[i].data))
|
||||||
}
|
}
|
||||||
|
@ -152,3 +155,40 @@ function ProcessQA () {
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ConvertToNewFormat (d) {
|
||||||
|
if (d.allData.length < 0) {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!d.allData[0].data) {
|
||||||
|
logger.Log('\tConverting old data to new...')
|
||||||
|
d.allData = d.allData.map((x) => {
|
||||||
|
if (x.I) {
|
||||||
|
x.data = {
|
||||||
|
type: 'image',
|
||||||
|
images: JSON.parse(x.I)
|
||||||
|
}
|
||||||
|
delete x.I
|
||||||
|
}
|
||||||
|
return x
|
||||||
|
})
|
||||||
|
d.data = d.data.map((x) => {
|
||||||
|
if (x.I) {
|
||||||
|
x.data = {
|
||||||
|
type: 'image',
|
||||||
|
images: JSON.parse(x.I)
|
||||||
|
}
|
||||||
|
delete x.I
|
||||||
|
}
|
||||||
|
return x
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
logger.Log('Couldnt convert old data to new!', logger.GetColor('redbg'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
0
utils/changedataversion.js
Normal file → Executable file
0
utils/changedataversion.js
Normal file → Executable file
0
utils/dataUpdater.js
Normal file → Executable file
0
utils/dataUpdater.js
Normal file → Executable file
0
utils/ids.js
Normal file → Executable file
0
utils/ids.js
Normal file → Executable file
0
utils/logger.js
Normal file → Executable file
0
utils/logger.js
Normal file → Executable file
95
utils/merger.js
Normal file → Executable file
95
utils/merger.js
Normal file → Executable file
|
@ -41,8 +41,7 @@ function Main () {
|
||||||
console.log('JSON data added')
|
console.log('JSON data added')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
console.log('Trying with old format...')
|
return
|
||||||
dbs.push(ReadData(utils.ReadFile(params[i])).result)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PrintLN()
|
PrintLN()
|
||||||
|
@ -155,98 +154,6 @@ function MergeDatabases (dbs) {
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns a question database from the given data.
|
|
||||||
* Parameter should be raw read file in string with "\n"-s
|
|
||||||
* TODO: ??? -s are not listed as errors, tho works correctly
|
|
||||||
* */
|
|
||||||
function ReadData (data) {
|
|
||||||
const d = data.split('\n')
|
|
||||||
const r = new classes.QuestionDB((x) => true, (x, y) => console.log(x, y))
|
|
||||||
var logs = []
|
|
||||||
var currSubj = '' // the current subjects name
|
|
||||||
var ExpectedIdentifier = ['+', '?']
|
|
||||||
let currQuestion = new classes.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 classes.Question()
|
|
||||||
currSubj = currData
|
|
||||||
ExpectedIdentifier = ['?']
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currIdentifier === '?') {
|
|
||||||
if (currQuestion.IsComplete()) {
|
|
||||||
r.AddQuestion(currSubj, currQuestion)
|
|
||||||
currQuestion = new classes.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function RemoveDuplicates (dataObj) {
|
function RemoveDuplicates (dataObj) {
|
||||||
for (var i = 0; i < dataObj.length; i++) { RemoveDuplFromSubject(dataObj.Subjects[i]) }
|
for (var i = 0; i < dataObj.length; i++) { RemoveDuplFromSubject(dataObj.Subjects[i]) }
|
||||||
return dataObj
|
return dataObj
|
||||||
|
|
0
utils/motd.js
Normal file → Executable file
0
utils/motd.js
Normal file → Executable file
0
utils/utils.js
Normal file → Executable file
0
utils/utils.js
Normal file → Executable file
0
views/main/main.ejs
Normal file → Executable file
0
views/main/main.ejs
Normal file → Executable file
0
views/qmining/alldata.ejs
Normal file → Executable file
0
views/qmining/alldata.ejs
Normal file → Executable file
0
views/qmining/allqr.ejs
Normal file → Executable file
0
views/qmining/allqr.ejs
Normal file → Executable file
0
views/qmining/aludni.ejs
Normal file → Executable file
0
views/qmining/aludni.ejs
Normal file → Executable file
0
views/qmining/b.ejs
Normal file → Executable file
0
views/qmining/b.ejs
Normal file → Executable file
0
views/qmining/main.ejs
Normal file → Executable file
0
views/qmining/main.ejs
Normal file → Executable file
0
views/qmining/man.ejs
Normal file → Executable file
0
views/qmining/man.ejs
Normal file → Executable file
0
views/qmining/qa.ejs
Normal file → Executable file
0
views/qmining/qa.ejs
Normal file → Executable file
0
views/qmining/uploaded.ejs
Normal file → Executable file
0
views/qmining/uploaded.ejs
Normal file → Executable file
0
views/shared/404.ejs
Normal file → Executable file
0
views/shared/404.ejs
Normal file → Executable file
0
views/sio/uload.ejs
Normal file → Executable file
0
views/sio/uload.ejs
Normal file → Executable file
0
views/stuff/audio.ejs
Normal file → Executable file
0
views/stuff/audio.ejs
Normal file → Executable file
0
views/stuff/folders.ejs
Normal file → Executable file
0
views/stuff/folders.ejs
Normal file → Executable file
0
views/stuff/nofile.ejs
Normal file → Executable file
0
views/stuff/nofile.ejs
Normal file → Executable file
0
views/stuff/video.ejs
Normal file → Executable file
0
views/stuff/video.ejs
Normal file → Executable file
Loading…
Add table
Add a link
Reference in a new issue