11/* global alertify, $ */
22
3- define ( [ 'jquery' , 'controllers/tableController' , 'helper/mpc' , 'alertify' , 'alertify_defaults' , 'controllers/confirmationCodes' ] , function ( $ , tableController , mpc , alertify , _ , confirmationCodes ) {
4-
5- console . log ( confirmationCodes ) ;
6- console . log ( confirmationCodes . get_confirmation_code ( ) ) ;
3+ define ( [ 'jquery' , 'controllers/tableController' , 'controllers/usabilityController' , 'helper/mpc' , 'alertify' , 'alertify_defaults' ] , function ( $ , tableController , usabilityController , mpc , alertify , _ ) {
74
85 var client = ( function ( ) {
96 var SESSION_KEY_ERROR = 'Invalid session number' ;
@@ -27,121 +24,16 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
2724 discrepancies : SEMANTIC_CELLS
2825 } ;
2926
30- // currently the client width:height ratio is ~ 0.45:1
31- var MOUSE_PRECISION_WIDTH = 90 ;
32- var MOUSE_PRECISION_HEIGHT = 200 ;
33-
34-
35- let analytics = {
36-
37- validation_errors : {
38-
39- SESSION_KEY_ERROR : 0 ,
40- PARTICIPATION_CODE_ERROR : 0 ,
41- SESSION_PARTICIPATION_CODE_SERVER_ERROR : 0 ,
42- UNCHECKED_ERR : 0 ,
43- ADD_QUESTIONS_ERR : 0 ,
44- GENERIC_TABLE_ERR : 0 ,
45- SERVER_ERR : 0 ,
46- GENERIC_SUBMISSION_ERR : 0 ,
47- NAN_EMPTY_CELLS : 0 ,
48- SEMANTIC_CELLS : 0 ,
49- } ,
50- mouse_positions : [ ] ,
51- mouse_clicks : [ ] ,
52- time_ms : 0 ,
53- } ;
54- /*
55- [ [ [], [], ..., [] ],
56- [ [], [], ..., [] ],
57- [ [], [], ..., [] ],
58- [ [], [], ..., [] ],
59- ]
60- */
6127
6228 // define mouse_positions as 100x1000 array
63- for ( var i = 0 ; i < MOUSE_PRECISION_WIDTH ; i ++ ) {
64- analytics . mouse_positions . push ( [ ] ) ;
65- analytics . mouse_clicks . push ( [ ] ) ;
66- for ( var k = 0 ; k < MOUSE_PRECISION_HEIGHT ; k ++ ) {
67- analytics . mouse_positions [ i ] . push ( 0 )
68- analytics . mouse_clicks [ i ] . push ( 0 )
69- }
70- }
7129
72- document . addEventListener ( 'mousemove' , handleMouseMove , false ) ;
73- document . addEventListener ( 'click' , handleMouseClick , false ) ;
74- function getPos ( event ) {
75-
76- // TODO: make sure this is consistent across browsers
77- var height ;
78- var width ;
79- if ( event . pageX === null && event . clientX !== null ) {
80- var doc = eventDoc . documentElement ;
81- var body = eventDoc . body ;
82-
83-
84- event . pageX = event . clientX +
85- ( doc && doc . scrollLeft || body && body . scrollLeft || 0 ) -
86- ( doc && doc . clientLeft || body && body . clientLeft || 0 ) ;
87- event . pageY = event . clientY +
88- ( doc && doc . scrollTop || body && body . scrollTop || 0 ) -
89- ( doc && doc . clientTop || body && body . clientTop || 0 ) ;
90- }
91- width = window . innerWidth
92- || document . documentElement . clientWidth
93- || document . body . clientWidth ;
94-
95- height = document . body . scrollHeight ;
96- return [ event . pageX / width , event . pageY / height ] ;
97- }
98-
99- function handleMouseClick ( event ) {
100- // y coord should potentially be mult. by 100
101- // to account for difference in x, y page size
102-
103- var pos = getPos ( event ) ;
104- var x = Math . floor ( pos [ 0 ] * MOUSE_PRECISION_WIDTH ) ;
105- var y = Math . floor ( pos [ 1 ] * MOUSE_PRECISION_HEIGHT ) ;
106- //each array stores # of hits at this area
107- analytics . mouse_clicks [ x ] [ y ] ++ ;
108- }
109- function handleMouseMove ( event ) {
110- // y coord should potentially be mult. by 100
111- // to account for difference in x, y page size
112-
113- var pos = getPos ( event ) ;
114- var x = Math . floor ( pos [ 0 ] * MOUSE_PRECISION_WIDTH ) ;
115- var y = Math . floor ( pos [ 1 ] * MOUSE_PRECISION_HEIGHT ) ;
116- //each array stores # of hits at this area
117- analytics . mouse_positions [ x ] [ y ] ++ ;
118- }
119-
120- let startDate = new Date ( ) ;
121- let elapsedTime = 0 ;
122-
123- const focus = function ( ) {
124- startDate = new Date ( ) ;
125- } ;
126-
127- const blur = function ( ) {
128- const endDate = new Date ( ) ;
129- const spentTime = endDate . getTime ( ) - startDate . getTime ( ) ;
130- elapsedTime += spentTime ;
131- } ;
132-
133- const beforeunload = function ( ) {
134- const endDate = new Date ( ) ;
135- const spentTime = endDate . getTime ( ) - startDate . getTime ( ) ;
136- elapsedTime += spentTime ;
137- analytics [ 'time_ms' ] = elapsedTime ;
138- // elapsedTime contains the time spent on page in milliseconds
139- } ;
30+ document . addEventListener ( 'mousemove' , usabilityController . handleMouseMove , false ) ;
31+ document . addEventListener ( 'click' , usabilityController . handleMouseClick , false ) ;
14032
14133 // TODO EventListeners prolly shouldn't be in this file
142- window . addEventListener ( 'focus' , focus ) ;
143- window . addEventListener ( 'blur' , blur ) ;
144- window . addEventListener ( 'beforeunload' , beforeunload ) ;
34+ window . addEventListener ( 'focus' , usabilityController . focus ) ;
35+ window . addEventListener ( 'blur' , usabilityController . blur ) ;
36+ window . addEventListener ( 'beforeunload' , usabilityController . beforeunload ) ;
14537
14638 // TODO: create new view for alerts
14739 function error ( msg ) {
@@ -295,22 +187,22 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
295187 var $participationCode = $ ( '#participation-code' ) ;
296188 if ( ! validateSessionInput ( $participationCode , false ) ) {
297189 errors = errors . concat ( PARTICIPATION_CODE_ERROR ) ;
298- analytics . validation_errors [ PARTICIPATION_CODE_ERROR ] ++ ;
190+ usabilityController . analytics . validation_errors [ PARTICIPATION_CODE_ERROR ] ++ ;
299191 }
300192
301193 // Validate the remaining components after session and
302194 // and participation code are validated with the server.
303195 var validateRemainingComponents = function ( result ) {
304196 if ( ! result ) {
305197 errors = errors . concat ( SESSION_PARTICIPATION_CODE_SERVER_ERROR ) ;
306- analytics . validation_errors [ SESSION_PARTICIPATION_CODE_SERVER_ERROR ] ++ ;
198+ usabilityController . analytics . validation_errors [ SESSION_PARTICIPATION_CODE_SERVER_ERROR ] ++ ;
307199 }
308200
309201 // Verify confirmation check box was checked
310202 var verifyChecked = $ ( '#verify' ) . is ( ':checked' ) ;
311203 if ( ! verifyChecked ) {
312204 errors = errors . concat ( UNCHECKED_ERR ) ;
313- analytics . validation_errors [ UNCHECKED_ERR ] ++ ;
205+ usabilityController . analytics . validation_errors [ UNCHECKED_ERR ] ++ ;
314206 }
315207
316208 // Verify additional questions
@@ -336,7 +228,7 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
336228
337229 if ( ! questionsValid ) {
338230 errors = errors . concat ( ADD_QUESTIONS_ERR ) ;
339- analytics . validation_errors [ ADD_QUESTIONS_ERR ] ++ ;
231+ usabilityController . analytics . validation_errors [ ADD_QUESTIONS_ERR ] ++ ;
340232 }
341233
342234 // Register semantic discrepancies validator.
@@ -448,10 +340,10 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
448340 // For now, keeping analytic data separate from submission data
449341 // analytics is a global var, probably not that chill
450342
451- beforeunload ( ) ; // updates time analytic
452- analytics . time_ms = Math . floor ( analytics . time_ms / 1000 ) ;
343+ usabilityController . beforeunload ( ) ; // updates time analytic
344+ usabilityController . analytics . time_ms = Math . floor ( usabilityController . analytics . time_ms / 1000 ) ;
453345
454- var analytic_shares = mpc . secretShareValues ( analytics ) ;
346+ var analytic_shares = mpc . secretShareValues ( usabilityController . analytics ) ;
455347 var analytic_data = analytic_shares [ 'data' ] ;
456348 var analytic_mask = analytic_shares [ 'mask' ] ;
457349
@@ -508,8 +400,6 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
508400
509401 success ( 'Submitted data.' ) ;
510402 convertToHTML ( submitEntries ) ;
511- // post confirmation or completion code for mturk users to submit to in aws/mturk site
512- alert ( confirmationCodes . get_confirmation_code ( ) ) ;
513403
514404 // Stop loading animation
515405 la . stop ( ) ;
0 commit comments