Skip to content

Commit bf7eb34

Browse files
committed
added UUID tracking
1 parent bac0d76 commit bf7eb34

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎v3/js/opt-frontend-common.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ var pyInputAceEditor; // Ace editor object that contains the input code
7070
var useCodeMirror = false; // true -> use CodeMirror, false -> use Ace
7171

7272

73+
// From http://stackoverflow.com/a/8809472
74+
function generateUUID(){
75+
var d = new Date().getTime();
76+
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
77+
var r = (d + Math.random()*16)%16 | 0;
78+
d = Math.floor(d/16);
79+
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
80+
});
81+
return uuid;
82+
};
83+
84+
7385
var dmp = new diff_match_patch();
7486
var curCode = '';
7587
var deltaObj = undefined;
@@ -790,6 +802,15 @@ function genericOptFrontendReady() {
790802
localStorage.setItem(k, v);
791803
});
792804
});
805+
806+
// generate a unique UUID per "user" (as indicated by a single browser
807+
// instance on a user's machine, which can be more precise than IP
808+
// addresses due to sharing of IP addresses within, say, a school
809+
// computer lab)
810+
// added on 2015-01-27 for more precise user identification
811+
if (!localStorage.getItem('opt_uuid')) {
812+
localStorage.setItem('opt_uuid', generateUUID());
813+
}
793814
}
794815

795816
parseQueryString();
@@ -1184,6 +1205,7 @@ function executePythonCode(pythonSourceCode,
11841205
{user_script : pythonSourceCode,
11851206
raw_input_json: rawInputLst.length > 0 ? JSON.stringify(rawInputLst) : '',
11861207
options_json: JSON.stringify(backendOptionsObj),
1208+
user_uuid: supports_html5_storage() ? localStorage.getItem('opt_uuid') : undefined,
11871209
// if we don't have any deltas, then don't bother sending deltaObj:
11881210
diffs_json: deltaObj && (deltaObj.deltas.length > 0) ? JSON.stringify(deltaObj) : null},
11891211
function(dataFromBackend) {

‎v4-cokapi/frontends/js/opt-frontend-common.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ var appMode = 'edit'; // 'edit' or 'display'. also support
3535

3636
var pyInputAceEditor; // Ace editor object that contains the input code
3737

38+
// From http://stackoverflow.com/a/8809472
39+
function generateUUID(){
40+
var d = new Date().getTime();
41+
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
42+
var r = (d + Math.random()*16)%16 | 0;
43+
d = Math.floor(d/16);
44+
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
45+
});
46+
return uuid;
47+
};
48+
3849

3950
var dmp = new diff_match_patch();
4051
var curCode = '';
@@ -285,6 +296,15 @@ function genericOptFrontendReady() {
285296
localStorage.setItem(k, v);
286297
});
287298
});
299+
300+
// generate a unique UUID per "user" (as indicated by a single browser
301+
// instance on a user's machine, which can be more precise than IP
302+
// addresses due to sharing of IP addresses within, say, a school
303+
// computer lab)
304+
// added on 2015-01-27 for more precise user identification
305+
if (!localStorage.getItem('opt_uuid')) {
306+
localStorage.setItem('opt_uuid', generateUUID());
307+
}
288308
}
289309

290310
parseQueryString();
@@ -636,6 +656,7 @@ function executeUserCode(sourceCode,
636656
{user_script : sourceCode,
637657
raw_input_json: rawInputLst.length > 0 ? JSON.stringify(rawInputLst) : '',
638658
options_json: JSON.stringify(backendOptionsObj),
659+
user_uuid: supports_html5_storage() ? localStorage.getItem('opt_uuid') : undefined,
639660
// if we don't have any deltas, then don't bother sending deltaObj:
640661
diffs_json: deltaObj && (deltaObj.deltas.length > 0) ? JSON.stringify(deltaObj) : null},
641662
function(dataFromBackend) {

0 commit comments

Comments
 (0)