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 * coefficient: number, default 1
18 * index: for paper test, like 2.1.a (?!); and quiz: 0, 1, 2, 3...
19 * wording: varchar (HTML)
20 * options: array of varchar --> if present, question type == quiz!
21 * fixed: bool, options in fixed order (default: false)
22 * answer: array of integers (for quiz) or html text (for paper); striped in exam mode
23 * active: boolean, is question in current assessment?
24 * points: points for this question (default 1)
26 * number: student number
27 * inputs: array of indexed arrays of integers (or html text if not quiz)
29 * discoTime, totalDisco: last disconnect timestamp (if relevant) + total
30 * discoCount: total disconnections
31 * password: random string identifying student for exam session TEMPORARY
34 getById: function(aid
, callback
)
36 db
.assessments
.findOne(
42 getByPath: function(cid
, name
, callback
)
44 db
.assessments
.findOne(
53 insert: function(cid
, name
, callback
)
55 db
.assessments
.insert(
73 getByCourse: function(cid
, callback
)
81 // arg: full assessment without _id field
82 replace: function(aid
, assessment
, cb
)
84 // Should be: (but unsupported by mongojs)
85 // db.assessments.replaceOne(
90 // Temporary workaround:
91 db
.assessments
.update(
98 getQuestions: function(aid
, callback
)
100 db
.assessments
.findOne(
104 callback(err
, !!res
? res
.questions : null);
109 getPaperByNumber: function(aid
, number
, callback
)
111 db
.assessments
.findOne(
114 "papers.number": number
,
118 return callback(err
,a
);
119 for (let p
of a
.papers
)
121 if (p
.number
== number
)
122 return callback(null,p
); //reached for sure
128 startSession: function(aid
, number
, password
, callback
)
130 db
.assessments
.update(
134 startTime: Date
.now(),
139 inputs: [ ], //TODO: this is stage 1, stack indexed answers.
140 // then build JSON tree for easier access / correct
146 // NOTE: no callbacks for 2 next functions, failures are not so important
147 // (because monitored: teachers can see what's going on)
149 addDisco: function(aid
, number
, deltaTime
)
151 db
.assessments
.update(
154 "papers.number": number
,
157 "papers.$.discoCount": 1,
158 "papers.$.totalDisco": deltaTime
,
160 { $set: { "papers.$.discoTime": null } }
164 setDiscoTime: function(aid
, number
)
166 db
.assessments
.update(
169 "papers.number": number
,
171 { $set: { "papers.$.discoTime": Date
.now() } }
175 getDiscoTime: function(aid
, number
, cb
)
177 db
.assessments
.findOne(
181 return cb(err
, null);
182 const idx
= a
.papers
.findIndex( item
=> { return item
.number
== number
; });
183 cb(null, a
.papers
[idx
].discoTime
);
188 hasInput: function(aid
, number
, password
, idx
, cb
)
190 db
.assessments
.findOne(
193 "papers.number": number
,
194 "papers.password": password
,
199 let papIdx
= a
.papers
.findIndex( item
=> { return item
.number
== number
; });
200 for (let i
of a
.papers
[papIdx
].inputs
)
203 return cb(null,true);
210 // https://stackoverflow.com/questions/27874469/mongodb-push-in-nested-array
211 setInput: function(aid
, number
, password
, input
, callback
) //input: index + arrayOfInt (or txt)
213 db
.assessments
.update(
216 "papers.number": number
,
217 "papers.password": password
,
219 { $push: { "papers.$.inputs": input
} },
224 endAssessment: function(aid
, number
, password
, callback
)
226 db
.assessments
.update(
229 "papers.number": number
,
230 "papers.password": password
,
233 "papers.$.endTime": Date
.now(),
234 "papers.$.password": "",
240 remove: function(aid
, cb
)
242 db
.assessments
.remove(
248 removeGroup: function(cid
, cb
)
250 db
.assessments
.remove(
257 module
.exports
= AssessmentEntity
;