Added duplicate remover ( #5 ), saving subjects without year, file append now sync, minor logging improvements

This commit is contained in:
MrFry 2020-03-26 14:33:52 +01:00
parent be34113969
commit e6db0f9175
4 changed files with 284 additions and 8 deletions

View file

@ -65,6 +65,7 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
}
logger.DebugLog('recievedData JSON parsed', 'actions', 1)
logger.DebugLog(d, 'actions', 3)
let allQLength = d.quiz.length
let allQuestions = []
@ -72,6 +73,9 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
logger.DebugLog('Question:', 'actions', 2)
logger.DebugLog(question, 'actions', 2)
let q = new classes.Question(question.Q, question.A, question.data)
logger.DebugLog('Searching for question in subj ' + d.subj, 'actions', 3)
logger.DebugLog(q, 'actions', 3)
let sames = qdb.Search(q, d.subj)
logger.DebugLog('Same questions:', 'actions', 2)
logger.DebugLog('Length: ' + sames.length, 'actions', 2)
@ -89,10 +93,13 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
let color = logger.GetColor('green')
let msg = ''
if (allQuestions.length > 0) {
color = logger.GetColor('blue')
color = logger.GetColor('cyan')
msg += `New questions: ${allQuestions.length} ( All: ${allQLength} )`
allQuestions.forEach((q) => {
qdb.AddQuestion(d.subj, q)
const sName = classes.SUtils.GetSubjNameWithoutYear(d.subj)
logger.DebugLog('Adding question with subjName: ' + sName + ' :', 'actions', 3)
logger.DebugLog(q, 'actions', 3)
qdb.AddQuestion(sName, q)
})
currWrites++
@ -139,7 +146,7 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
function LoadJSON (dataFile) {
try {
var d = JSON.parse(utils.ReadFile(dataFile))
var r = new classes.QuestionDB((x) => true, (x, y) => console.log(x, y))
var r = new classes.QuestionDB()
var rt = []
for (var i = 0; i < d.Subjects.length; i++) {