Skip to content

Commit 295fc7d

Browse files
committed
getting usability data and writing mouse positions to csv
1 parent aeabc1a commit 295fc7d

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

client/app/controllers/tableController.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,31 @@ define(['jquery', 'Handsontable', 'table_template', 'filesaver', 'alertify', 'qt
906906
}
907907

908908
tables_csv = tables_csv.join('\n\n\n');
909-
filesaver.saveAs(new Blob([tables_csv], {type: 'text/plain;charset=utf-8'}), 'Aggregate_Data_' + session + '.csv');
909+
// filesaver.saveAs(new Blob([tables_csv], {type: 'text/plain;charset=utf-8'}), 'Aggregate_Data_' + session + '.csv');
910+
}
911+
912+
function saveUsability(usability, session) {
913+
if (Object.keys(usability).length === 0) {
914+
return;
915+
}
916+
let mousePositions = usability.mouse_positions;
917+
918+
let results = [];
919+
920+
for (let row in mousePositions) {
921+
results[parseInt(row)] = [];
922+
for (let col in mousePositions[row]) {
923+
results[parseInt(row)].push(mousePositions[row][col]);
924+
}
925+
}
926+
927+
results = results.join('\n');
928+
929+
// let results = mousePositions.join('\n');
930+
// results = results.join()
931+
filesaver.saveAs(new Blob([results], {type: 'text/plain;charset=utf-8'}), 'Usability_' + session + '.csv');
932+
933+
910934
}
911935

912936
function saveQuestions(questions, session) {
@@ -944,7 +968,7 @@ define(['jquery', 'Handsontable', 'table_template', 'filesaver', 'alertify', 'qt
944968
}
945969

946970
results = results.join('\n');
947-
filesaver.saveAs(new Blob([results], {type: 'text/plain;charset=utf-8'}), 'Questions_' + session + '.csv');
971+
// filesaver.saveAs(new Blob([results], {type: 'text/plain;charset=utf-8'}), 'Questions_' + session + '.csv');
948972
}
949973

950974
return {
@@ -960,6 +984,7 @@ define(['jquery', 'Handsontable', 'table_template', 'filesaver', 'alertify', 'qt
960984
saveQuestions: saveQuestions,
961985
displayReadTable: displayReadTable,
962986
resetTableWidth: resetTableWidth,
963-
updateTableWidth: updateTableWidth
987+
updateTableWidth: updateTableWidth,
988+
saveUsability: saveUsability
964989
}
965990
});

client/app/controllers/unmaskController.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99
/*eslint no-console: ["error", { allow: ["warn", "error"] }] */
1010
define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc, tableController, filesaver) {
1111

12+
function parseWebShares(data) {
13+
let arr = [];
14+
for (var d of data) {
15+
arr.push(d.fields);
16+
}
17+
return arr;
18+
}
19+
1220
// Takes callback(true|false, data).
1321
function aggregate_and_unmask(mOut, analyticsMasks, privateKey, session, password, callback) {
1422

1523
aMOut = JSON.parse(analyticsMasks.data);
16-
17-
console.log('analytics mask',aMOut);
18-
1924
mOut = JSON.parse(mOut.data);
20-
// console.log(mOut);
2125
// Questions Public is the public answers to questions.
2226
var questions_public = [];
2327
for (var i = 0; i < mOut.length; i++) {
@@ -45,36 +49,36 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
4549
// decrypted is a list of promises, each promise
4650
// corresponding to a submission with decrypted
4751
// value fields
52+
// var decryptedLytics = decryptValueShares(sk, aMOut, true);
4853
var decrypted = decryptValueShares(sk, mOut, true);
49-
console.log(decrypted)
5054
questions_public = decryptValueShares(sk, questions_public, false);
5155

5256
// Aggregate decrypted values by key
5357
var analystResultShare = decrypted.then(function (analystShares) {
54-
// var invalidShareCount = mpc.countInvalidShares(analystShares);
55-
// TODO: we should set a threshold and abort if there are too
56-
// many invalid shares
57-
// console.log('Invalid share count:', invalidShareCount);
5858
return mpc.aggregateShares(analystShares);
5959
});
6060

61+
var webShares = parseWebShares(aMOut);
62+
var webCombinedShares = mpc.aggregateShares(webShares);
63+
6164
// Request service to aggregate its shares and send us the result
6265
var serviceResultShare = getServiceResultShare(session, password);
6366

64-
var analyticsShares = getAnalyticsShares(session, password);
67+
var webAggShares = getAnalyticsShares(session, password);
6568

66-
console.log(analyticsShares);
67-
68-
Promise.all([analystResultShare, serviceResultShare, questions_public])
69+
Promise.all([analystResultShare, serviceResultShare, questions_public, webAggShares])
6970
.then(function (resultShares) {
7071
var analystResult = resultShares[0],
7172
serviceResult = resultShares[1],
7273
finalResult = mpc.recombineValues(serviceResult, analystResult);
74+
75+
usabilityResults = mpc.recombineValues(resultShares[3], webCombinedShares);
76+
7377
if (!ensure_equal(finalResult.questions, mpc.aggregateShares(resultShares[2]))) {
7478
console.error('Secret-shared question answers do not aggregate to the same values as publicly collected answers.');
7579
}
7680
// generateQuestionsCSV(resultShares[2], session)
77-
callback(true, finalResult, resultShares[2], session);
81+
callback(true, finalResult, resultShares[2], usabilityResults, session);
7882

7983
})
8084
.catch(function (err) {
@@ -83,7 +87,7 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
8387
});
8488

8589
// Do the Hypercube
86-
// NOTE: do we need this?
90+
// // NOTE: do we need this?
8791
// var cubes = getCubes(session, password);
8892
// Promise.all([cubes, sk]).then(function (results) {
8993
// var cubes = results[0];
@@ -159,15 +163,13 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
159163
function _decryptWithKey(obj, importedKey) {
160164
// decrypt one level of obj, decrypt nested object recursively
161165
var resultTuples = [];
162-
163166
for (var key in obj) {
164167
if (obj.hasOwnProperty(key)) {
165168
var value = obj[key];
166169
if (typeof(value) === 'number' || typeof(value) === 'string') {
167170
// decrypt atomic value
168171
var resultTuple = window.crypto.subtle.decrypt({name: 'RSA-OAEP'}, importedKey, str2ab(value))
169172
.then(construct_tuple(key, true));
170-
171173
resultTuples.push(resultTuple);
172174
} else {
173175
resultTuples.push(_decryptWithKey(value, importedKey)
@@ -187,7 +189,7 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
187189
*/
188190
function decryptValueShares(sk, maskedData, fields) {
189191
return sk.then(function (importedKey) {
190-
// decrypt all masks
192+
191193
var all = [];
192194
for (var d = 0; d < maskedData.length; d++) {
193195
all.push(_decryptWithKey(fields ? maskedData[d].fields : maskedData[d], importedKey));

client/app/views/unmaskView.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define(['jquery', 'controllers/unmaskController', 'controllers/clientController'
88
}
99

1010

11-
function callb(e, d, questions, session) {
11+
function callb(e, d, questions, usability, session) {
1212
var tables = {};
1313
for (var name in d) {
1414
if (name !== 'questions') {
@@ -18,6 +18,7 @@ define(['jquery', 'controllers/unmaskController', 'controllers/clientController'
1818
}
1919
}
2020

21+
tableController.saveUsability(usability, session);
2122
tableController.saveTables(tables, session);
2223
tableController.saveQuestions(questions, session);
2324
tableController.displayReadTable(tables);

0 commit comments

Comments
 (0)