Skip to content

Commit 4e2e4da

Browse files
committed
started adding socketio fine-grained logging support
1 parent 1e4ab69 commit 4e2e4da

5 files changed

Lines changed: 6970 additions & 0 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ var pyInputAceEditor; // Ace editor object that contains the input code
7070
var 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
7476
function 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+
}

‎v3/js/opt-frontend.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,6 @@ $(document).ready(function() {
469469
});
470470

471471
genericOptFrontendReady(); // initialize at the end
472+
473+
//loggingSocketIO = io.connect('http://104.237.139.253:5000/');
472474
});

‎v3/js/pytutor.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ var curVisualizerID = 1; // global to uniquely identify each ExecutionVisualizer
105105
// verticalStack - if true, then stack code display ON TOP of visualization
106106
// (else place side-by-side)
107107
// visualizerIdOverride - override visualizer ID instead of auto-assigning it
108+
// (BE CAREFUL ABOUT NOT HAVING DUPLICATE IDs ON THE SAME PAGE,
109+
// OR ELSE ARROWS AND OTHER STUFF WILL GO HAYWIRE!)
108110
// executeCodeWithRawInputFunc - function to call when you want to re-execute the given program
109111
// with some new user input (somewhat hacky!)
110112
// highlightLines - highlight current and previously executed lines (default: false)

0 commit comments

Comments
 (0)