@@ -70,6 +70,18 @@ var pyInputAceEditor; // Ace editor object that contains the input code
7070var 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 ( / [ x y ] / 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+
7385var dmp = new diff_match_patch ( ) ;
7486var curCode = '' ;
7587var 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 ) {
0 commit comments