X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=entities%2Fassessment.js;h=b4b6d8932811c33949d10eaf425971ac8b6900fb;hb=db5571d67f6b6b3b841fa1eeaf2099cecf2bcffc;hp=2104193a309f92484ffceefbf61830904aec53f8;hpb=e99c53fb3be56eb4c685dd061eef0e5b5bf22b73;p=qomet.git diff --git a/entities/assessment.js b/entities/assessment.js index 2104193..b4b6d89 100644 --- a/entities/assessment.js +++ b/entities/assessment.js @@ -13,7 +13,6 @@ const AssessmentEntity = * display: "one" or "all" (generally "all" for open questions, but...) * time: 0, //<=0 means "untimed"; otherwise, time in seconds * introduction: "", - * conclusion: "https://www.youtube.com/watch?v=6-9AjToJYuw", * coefficient: number, default 1 * questions: array of * index: for paper test, like 2.1.a (?!); and quiz: 0, 1, 2, 3... @@ -21,12 +20,14 @@ const AssessmentEntity = * options: array of varchar --> if present, question type == quiz! * fixed: bool, options in fixed order (default: false) * answer: array of integers (for quiz) or html text (for paper); striped in exam mode - * active: boolean, is question in current assessment? --> striped if inactive! + * active: boolean, is question in current assessment? * points: points for this question (default 1) * papers : array of * number: student number * inputs: array of indexed arrays of integers (or html text if not quiz) * startTime, endTime + * discoTime, totalDisco: last disconnect timestamp (if relevant) + total + * discoCount: total disconnections * password: random string identifying student for exam session TEMPORARY */ @@ -61,7 +62,6 @@ const AssessmentEntity = display: "one", time: 0, introduction: "", - conclusion: "", coefficient: 1, questions: [ ], papers: [ ], @@ -106,9 +106,27 @@ const AssessmentEntity = ); }, + getPaperByNumber: function(aid, number, callback) + { + db.assessments.findOne( + { + _id: aid, + "papers.number": number, + }, + (err,a) => { + if (!!err || !a) + return callback(err,a); + for (let p of a.papers) + { + if (p.number == number) + return callback(null,p); //reached for sure + } + } + ); + }, + startSession: function(aid, number, password, callback) { - // TODO: security, do not re-do tasks if already done db.assessments.update( { _id: aid }, { $push: { papers: { @@ -116,6 +134,8 @@ const AssessmentEntity = startTime: Date.now(), endTime: undefined, password: password, + totalDisco: 0, + discoCount: 0, inputs: [ ], //TODO: this is stage 1, stack indexed answers. // then build JSON tree for easier access / correct }}}, @@ -123,6 +143,70 @@ const AssessmentEntity = ); }, + // NOTE: no callbacks for 2 next functions, failures are not so important + // (because monitored: teachers can see what's going on) + + addDisco: function(aid, number, deltaTime) + { + db.assessments.update( + { + _id: aid, + "papers.number": number, + }, + { $inc: { + "papers.$.discoCount": 1, + "papers.$.totalDisco": deltaTime, + } }, + { $set: { "papers.$.discoTime": null } } + ); + }, + + setDiscoTime: function(aid, number) + { + db.assessments.update( + { + _id: aid, + "papers.number": number, + }, + { $set: { "papers.$.discoTime": Date.now() } } + ); + }, + + getDiscoTime: function(aid, number, cb) + { + db.assessments.findOne( + { _id: aid }, + (err,a) => { + if (!!err) + return cb(err, null); + const idx = a.papers.findIndex( item => { return item.number == number; }); + cb(null, a.papers[idx].discoTime); + } + ); + }, + + hasInput: function(aid, number, password, idx, cb) + { + db.assessments.findOne( + { + _id: aid, + "papers.number": number, + "papers.password": password, + }, + (err,a) => { + if (!!err || !a) + return cb(err,a); + let papIdx = a.papers.findIndex( item => { return item.number == number; }); + for (let i of a.papers[papIdx].inputs) + { + if (i.index == idx) + return cb(null,true); + } + cb(null,false); + } + ); + }, + // https://stackoverflow.com/questions/27874469/mongodb-push-in-nested-array setInput: function(aid, number, password, input, callback) //input: index + arrayOfInt (or txt) { @@ -153,17 +237,6 @@ const AssessmentEntity = ); }, - getConclusion: function(aid, callback) - { - db.assessments.findOne( - { _id: aid }, - { conclusion: 1}, - (err,res) => { - callback(err, !!res ? res.conclusion : null); - } - ); - }, - remove: function(aid, cb) { db.assessments.remove(