1 const db
= require("../utils/database");
3 const AssessmentEntity
=
10 * active: boolean true/false
11 * mode: secure | exam | open (decreasing security)
12 * fixed: bool (questions in fixed order; default: false)
13 * display: "one" or "all" (generally "all" for open questions, but...)
14 * time: 0, //<=0 means "untimed"; otherwise, time in seconds
16 * conclusion: "https://www.youtube.com/watch?v=6-9AjToJYuw",
17 * coefficient: number, default 1
19 * index: for paper test, like 2.1.a (?!); and quiz: 0, 1, 2, 3...
20 * wording: varchar (HTML)
21 * options: array of varchar --> if present, question type == quiz!
22 * fixed: bool, options in fixed order (default: false)
23 * answer: array of integers (for quiz) or html text (for paper); striped in exam mode
24 * active: boolean, is question in current assessment? --> striped if inactive!
25 * points: points for this question (default 1)
27 * number: student number
28 * inputs: array of indexed arrays of integers (or html text if not quiz)
30 * discoTime, totalDisco: last disconnect timestamp (if relevant) + total
31 * discoCount: total disconnections
32 * password: random string identifying student for exam session TEMPORARY
35 getById: function(aid
, callback
)
37 db
.assessments
.findOne(
43 getByPath: function(cid
, name
, callback
)
45 db
.assessments
.findOne(
54 insert: function(cid
, name
, callback
)
56 db
.assessments
.insert(
75 getByCourse: function(cid
, callback
)
83 // arg: full assessment without _id field
84 replace: function(aid
, assessment
, cb
)
86 // Should be: (but unsupported by mongojs)
87 // db.assessments.replaceOne(
92 // Temporary workaround:
93 db
.assessments
.update(
100 getQuestions: function(aid
, callback
)
102 db
.assessments
.findOne(
106 callback(err
, !!res
? res
.questions : null);
111 getPaperByNumber: function(aid
, number
, callback
)
113 db
.assessments
.findOne(
116 "papers.number": number
,
120 return callback(err
,a
);
121 for (let p
of a
.papers
)
123 if (p
.number
== number
)
124 return callback(null,p
); //reached for sure
130 startSession: function(aid
, number
, password
, callback
)
132 db
.assessments
.update(
136 startTime: Date
.now(),
141 inputs: [ ], //TODO: this is stage 1, stack indexed answers.
142 // then build JSON tree for easier access / correct
148 // NOTE: no callbacks for 2 next functions, failures are not so important
149 // (because monitored: teachers can see what's going on)
151 addDisco: function(aid
, number
, deltaTime
)
153 db
.assessments
.update(
156 "papers.number": number
,
159 "papers.$.discoCount": 1,
160 "papers.$.totalDisco": deltaTime
,
162 { $set: { "papers.$.discoTime": null } }
166 setDiscoTime: function(aid
, number
)
168 db
.assessments
.update(
171 "papers.number": number
,
173 { $set: { "papers.$.discoTime": Date
.now() } }
177 getDiscoTime: function(aid
, number
, cb
)
179 db
.assessments
.findOne(
183 return cb(err
, null);
184 const idx
= a
.papers
.findIndex( item
=> { return item
.number
== number
; });
185 cb(null, a
.papers
[idx
].discoTime
);
190 hasInput: function(aid
, number
, password
, idx
, cb
)
192 db
.assessments
.findOne(
195 "papers.number": number
,
196 "papers.password": password
,
201 let papIdx
= a
.papers
.findIndex( item
=> { return item
.number
== number
; });
202 for (let i
of a
.papers
[papIdx
].inputs
)
205 return cb(null,true);
212 // https://stackoverflow.com/questions/27874469/mongodb-push-in-nested-array
213 setInput: function(aid
, number
, password
, input
, callback
) //input: index + arrayOfInt (or txt)
215 db
.assessments
.update(
218 "papers.number": number
,
219 "papers.password": password
,
221 { $push: { "papers.$.inputs": input
} },
226 endAssessment: function(aid
, number
, password
, callback
)
228 db
.assessments
.update(
231 "papers.number": number
,
232 "papers.password": password
,
235 "papers.$.endTime": Date
.now(),
236 "papers.$.password": "",
242 getConclusion: function(aid
, callback
)
244 db
.assessments
.findOne(
248 callback(err
, !!res
? res
.conclusion : null);
253 remove: function(aid
, cb
)
255 db
.assessments
.remove(
261 removeGroup: function(cid
, cb
)
263 db
.assessments
.remove(
270 module
.exports
= AssessmentEntity
;