Skip to content

Commit acf7f80

Browse files
committed
Added mouse clicks and corected validation errors, added new fields to analytics schema so the server accepts the data.
Added confirmation codes for Mturk tests.
1 parent 9c8ca51 commit acf7f80

File tree

5 files changed

+10039
-5
lines changed

5 files changed

+10039
-5
lines changed

client/app/controllers/clientController.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* global alertify, $ */
22

3-
define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'alertify_defaults'], function ($, tableController, mpc, alertify) {
3+
define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'alertify_defaults', 'controllers/confirmationCodes'], function ($, tableController, mpc, alertify, _, confirmationCodes) {
44

5+
console.log(confirmationCodes);
6+
console.log(confirmationCodes.get_confirmation_code());
57

68
var client = (function () {
79
var SESSION_KEY_ERROR = 'Invalid session number';
@@ -46,6 +48,7 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
4648
SEMANTIC_CELLS: 0,
4749
},
4850
mouse_positions: [],
51+
mouse_clicks: [],
4952
time_ms: 0,
5053
};
5154
/*
@@ -59,12 +62,15 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
5962
// define mouse_positions as 100x1000 array
6063
for (var i = 0; i < MOUSE_PRECISION_WIDTH; i++) {
6164
analytics.mouse_positions.push([]);
65+
analytics.mouse_clicks.push([]);
6266
for (var k = 0; k < MOUSE_PRECISION_HEIGHT; k++) {
6367
analytics.mouse_positions[i].push(0)
68+
analytics.mouse_clicks[i].push(0)
6469
}
6570
}
6671

6772
document.addEventListener('mousemove', handleMouseMove, false);
73+
document.addEventListener('click', handleMouseClick, false);
6874
function getPos(event) {
6975

7076
// TODO: make sure this is consistent across browsers
@@ -90,6 +96,16 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
9096
return [event.pageX / width, event.pageY / height];
9197
}
9298

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+
}
93109
function handleMouseMove(event) {
94110
// y coord should potentially be mult. by 100
95111
// to account for difference in x, y page size
@@ -492,6 +508,8 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
492508

493509
success('Submitted data.');
494510
convertToHTML(submitEntries);
511+
// post confirmation or completion code for mturk users to submit to in aws/mturk site
512+
alert(confirmationCodes.get_confirmation_code());
495513

496514
// Stop loading animation
497515
la.stop();
@@ -587,6 +605,7 @@ define(['jquery', 'controllers/tableController', 'helper/mpc', 'alertify', 'aler
587605
callback(true);
588606
}
589607

608+
590609
return {
591610
errors: errors,
592611
submitEntries: submitEntries,

client/app/controllers/confirmationCodes.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/app/views/clientView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
define(['jquery', 'controllers/clientController', 'controllers/tableController', 'helper/drop_sheet', 'spin', 'Ladda', 'ResizeSensor', 'alertify', 'table_template', 'bootstrap'],
2-
function ($, clientController, tableController, DropSheet, Spinner, Ladda, ResizeSensor, alertify, table_template) {
1+
define(['jquery', 'controllers/clientController', 'controllers/tableController', 'helper/drop_sheet', 'spin', 'Ladda', 'ResizeSensor', 'alertify', 'table_template', 'bootstrap', 'controllers/confirmationCodes'],
2+
function ($, clientController, tableController, DropSheet, Spinner, Ladda, ResizeSensor, alertify, table_template, confirmationCodes) {
33

44
function clientControllerView() {
55

server/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ function genPairs(num) {
5858
const analyticsSchema = {
5959
validation_errors: joi.object().required(),
6060
mouse_positions: joi.object().required(),
61+
mouse_clicks: joi.object().required(),
6162
time_ms: joi.number().required()
63+
6264
}
6365
const maskSchema = templateToJoiSchema(template, joi.string().required());
6466
const dataSchema = templateToJoiSchema(template, joi.number().required());
@@ -141,7 +143,7 @@ createConnection();
141143

142144
var Analytics = mongoose.model('Analytics', {
143145
_id: String,
144-
fields: Object,
146+
fields: Object,
145147
date: Number,
146148
session: String,
147149
});
@@ -272,7 +274,7 @@ app.post('/', function (req, res) {
272274
// TODO: set length restrictions on session and user
273275
var bodySchema = {
274276
mask: maskSchema.required(),
275-
data: dataSchema.required(),
277+
data: dataSchema.required(),
276278
analytic_data: analyticsSchema,
277279
analytic_mask: analyticsSchema,
278280
questions_public: encryptedPublicQuestionsSchema.required(),

0 commit comments

Comments
 (0)