@@ -55,7 +55,11 @@ function genPairs(num) {
5555 }
5656 return objPairs ;
5757}
58-
58+ const analyticsSchema = {
59+ validation_errors : joi . object ( ) . required ( ) ,
60+ mouse_positions : joi . object ( ) . required ( ) ,
61+ time_ms : joi . number ( ) . required ( )
62+ }
5963const maskSchema = templateToJoiSchema ( template , joi . string ( ) . required ( ) ) ;
6064const dataSchema = templateToJoiSchema ( template , joi . number ( ) . required ( ) ) ;
6165const encryptedPublicQuestionsSchema = templateToJoiSchema ( template . questions , joi . string ( ) . required ( ) ) ;
@@ -135,6 +139,20 @@ async function createConnection() {
135139
136140createConnection ( ) ;
137141
142+ var Analytics = mongoose . model ( 'Analytics' , {
143+ _id : String ,
144+ fields : Object ,
145+ date : Number ,
146+ session : String ,
147+ } ) ;
148+
149+ var AnalyticsMask = mongoose . model ( 'AnalyticsMask' , {
150+ _id : String ,
151+ fields : Object ,
152+ date : Number ,
153+ session : String
154+ } ) ;
155+
138156// model for aggregate data
139157var Aggregate = mongoose . model ( 'Aggregate' , {
140158 _id : String , // concat of session + user.
@@ -248,12 +266,15 @@ app.post('/', function (req, res) {
248266 console . log ( 'POST /' ) ;
249267
250268 var body = req . body ;
251- console . log ( body ) ;
269+ console . log ( body . data ) ;
252270
271+ // TODO: make this make sense
253272 // TODO: set length restrictions on session and user
254273 var bodySchema = {
255274 mask : maskSchema . required ( ) ,
256- data : dataSchema . required ( ) ,
275+ data : dataSchema . required ( ) ,
276+ analytic_data : analyticsSchema ,
277+ analytic_mask : analyticsSchema ,
257278 questions_public : encryptedPublicQuestionsSchema . required ( ) ,
258279 pairwise_hypercubes : pairwiseHyperCubeScheme . required ( ) ,
259280 session : joi . string ( ) . alphanum ( ) . required ( ) ,
@@ -280,7 +301,9 @@ app.post('/', function (req, res) {
280301 pairwise_hypercubes = body . pairwise_hypercubes ,
281302 session = body . session ,
282303 user = body . user ,
283- ID = session + user ; // will use concat of user + session for now
304+ ID = session + user , // will use concat of user + session for now
305+ analytics = body . analytic_data ,
306+ analyticsMask = body . analytics_mask ;
284307
285308 // Ensure user key exists.
286309 UserKey . findOne ( { _id : ID } , function ( err , data ) {
@@ -294,6 +317,21 @@ app.post('/', function (req, res) {
294317 res . status ( 500 ) . send ( 'Invalid participation code.' ) ;
295318 } else { // User Key Found.
296319 // save the mask and individual aggregate
320+
321+ var analyticsToSave = new Analytics ( {
322+ _id : ID ,
323+ fields : analytics ,
324+ date : Date . now ( ) ,
325+ session : session
326+ } ) ;
327+
328+ var analyticsMasksToSave = new AnalyticsMask ( {
329+ _id : ID ,
330+ fields : analyticsMask ,
331+ date : Date . now ( ) ,
332+ session : session
333+ } ) ;
334+
297335 var aggToSave = new Aggregate ( {
298336 _id : ID ,
299337 fields : req_data ,
@@ -331,10 +369,22 @@ app.post('/', function (req, res) {
331369 { _id : ID } ,
332370 cubeToSave . toObject ( ) ,
333371 { upsert : true }
372+ ) ,
373+ analyticsPromise = Analytics . update (
374+ { _id : ID } ,
375+ analyticsToSave . toObject ( ) ,
376+ { upsert : true }
377+ ) ,
378+ analyticsMaskPromise = AnalyticsMask . update (
379+ { _id : ID } ,
380+ analyticsMasksToSave . toObject ( ) ,
381+ { upsert : true }
334382 ) ;
335383
336- Promise . join ( aggPromise , maskPromise , cubePromise )
337- . then ( function ( aggStored , maskStored , cubeStored ) {
384+
385+
386+ Promise . join ( aggPromise , maskPromise , cubePromise , analyticsPromise , analyticsMaskPromise )
387+ . then ( function ( aggStored , maskStored , cubeStored , analyticsStored , analyticsMaskStored ) {
338388 res . send ( body ) ;
339389 return ;
340390 } )
0 commit comments