@@ -70,6 +70,8 @@ var pyInputAceEditor; // Ace editor object that contains the input code
7070var useCodeMirror = false ; // true -> use CodeMirror, false -> use Ace
7171
7272
73+ var loggingSocketIO ; // socket.io instance -- optional: not all frontends use it
74+
7375// From http://stackoverflow.com/a/8809472
7476function generateUUID ( ) {
7577 var d = new Date ( ) . getTime ( ) ;
@@ -137,6 +139,7 @@ function snapshotCodeDiff() {
137139 deltaObj . deltas . push ( delta ) ;
138140
139141 curCode = newCode ;
142+ logEvent ( { type : 'editCode' , delta : delta } ) ;
140143 }
141144}
142145
@@ -295,6 +298,11 @@ function initTogetherJS() {
295298 TogetherJS . send ( { type : "updateOutput" , step : args . myViz . curInstr } ) ;
296299 }
297300
301+ // debounce to compress a bit ... 250ms feels "right"
302+ $ . doTimeout ( 'updateOutputLogEvent' , 250 , function ( ) {
303+ logEvent ( { type : 'updateOutput' , step : args . myViz . curInstr } ) ;
304+ } ) ;
305+
298306 // 2014-05-25: implemented more detailed tracing for surveys
299307 if ( args . myViz . creationTime ) {
300308 var deltaMs = ( new Date ( ) ) - args . myViz . creationTime ;
@@ -1077,6 +1085,9 @@ function updateAppDisplay(newAppMode) {
10771085 }
10781086
10791087 $ ( '#urlOutput,#embedCodeOutput' ) . val ( '' ) ; // clear to avoid stale values
1088+
1089+ // log at the end after appMode gets canonicalized
1090+ logEvent ( { type : 'updateAppDisplay' , mode : appMode } ) ;
10801091}
10811092
10821093
@@ -1259,6 +1270,14 @@ function executePythonCode(pythonSourceCode,
12591270
12601271 doneExecutingCode ( ) ; // rain or shine, we're done executing!
12611272 // run this at the VERY END after all the dust has settled
1273+
1274+ // do logging at the VERY END after the dust settles ...
1275+ logEvent ( { type : 'doneExecutingCode' ,
1276+ appState : getAppState ( ) ,
1277+ // enough to reconstruct the ExecutionVisualizer object
1278+ backendDataJSON : JSON . stringify ( dataFromBackend ) , // for easier transport and compression
1279+ frontendOptionsObj : frontendOptionsObj ,
1280+ } ) ;
12621281 } ,
12631282 "json" ) ;
12641283
@@ -1674,3 +1693,16 @@ display a brief "Thanks!" note]
16741693 } ) ;
16751694 } ) ;
16761695}
1696+
1697+
1698+ // using socket.io:
1699+ function logEvent ( obj ) {
1700+ if ( loggingSocketIO ) {
1701+ if ( supports_html5_storage ( ) ) {
1702+ obj . user_uuid = localStorage . getItem ( 'opt_uuid' ) ;
1703+ }
1704+ // this probably won't match the server time due to time zones, etc.
1705+ obj . clientTime = new Date ( ) . getTime ( ) ;
1706+ loggingSocketIO . emit ( 'opt-client-event' , obj ) ;
1707+ }
1708+ }
0 commit comments