* 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...
* 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
*/
display: "one",
time: 0,
introduction: "",
- conclusion: "",
coefficient: 1,
questions: [ ],
papers: [ ],
startSession: function(aid, number, password, callback)
{
- // TODO: security, do not re-do tasks if already done
db.assessments.update(
{ _id: aid },
{ $push: { papers: {
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
}}},
);
},
+ // 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)
{
(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);
}
);
},
- 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(