X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=entities%2Fassessment.js;h=b4b6d8932811c33949d10eaf425971ac8b6900fb;hb=7a7dc732599b358b25b770cfc27036f4b403d1b4;hp=a8a781b060596d0dc72923c83956d20bf79700b8;hpb=f03a2ad9e0b2fa36051def18d4c19c2f293cac1d;p=qomet.git diff --git a/entities/assessment.js b/entities/assessment.js index a8a781b..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: [ ], @@ -127,7 +127,6 @@ const AssessmentEntity = startSession: function(aid, number, password, callback) { - // TODO: security, do not re-do tasks if already done db.assessments.update( { _id: aid }, { $push: { papers: { @@ -135,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 }}}, @@ -142,6 +143,47 @@ 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) { @@ -154,13 +196,11 @@ const AssessmentEntity = (err,a) => { if (!!err || !a) return cb(err,a); - for (let p of a.papers) + let papIdx = a.papers.findIndex( item => { return item.number == number; }); + for (let i of a.papers[papIdx].inputs) { - for (let i of p.inputs) - { - if (i.index == idx) - return cb(null,true); - } + if (i.index == idx) + return cb(null,true); } cb(null,false); } @@ -197,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(