X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=entities%2Fassessment.js;h=3dc19529666f820b81742416d02c4f0345c28ff2;hb=29c8b391bcdf6ffca53545178e2ad194287a1bdc;hp=a8a781b060596d0dc72923c83956d20bf79700b8;hpb=f03a2ad9e0b2fa36051def18d4c19c2f293cac1d;p=qomet.git diff --git a/entities/assessment.js b/entities/assessment.js index a8a781b..3dc1952 100644 --- a/entities/assessment.js +++ b/entities/assessment.js @@ -27,6 +27,8 @@ const AssessmentEntity = * 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 */ @@ -127,7 +129,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 +136,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 +145,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 +198,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); }