Skip to content

Commit fb1c407

Browse files
committed
moar
1 parent 61a9cf6 commit fb1c407

5 files changed

Lines changed: 150 additions & 146 deletions

File tree

‎v5-unity/js/iframe-embed.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
/* TODO
66
7+
- when you SLIDE the center vertical divider, visualizer arrows don't redraw :(
8+
79
- test the resizeContainer option
810
911
*/
@@ -83,7 +85,7 @@ class IframeEmbedFrontend extends AbstractBaseFrontend {
8385
'vizDiv');
8486
}
8587

86-
optFinishSuccessfulExecution() {
88+
finishSuccessfulExecution() {
8789
if (this.resizeContainer) {
8890
this.resizeContainerNow();
8991
}

‎v5-unity/js/opt-frontend-common.ts‎

Lines changed: 4 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ var pytutor = require('./pytutor.ts');
3434
var assert = pytutor.assert;
3535

3636

37-
const SUBMIT_UPDATE_HISTORY_INTERVAL_MS = 1000 * 60;
38-
3937
// these settings are all customized for my own server setup,
4038
// so you will need to customize for your server:
4139
const serverRoot = (window.location.protocol === 'https:') ?
@@ -83,7 +81,6 @@ const langSettingToJsonpEndpoint = {
8381

8482

8583
// for shared sessions ... put back in later
86-
var updateOutputSignalFromRemote = false;
8784
var executeCodeSignalFromRemote = false;
8885
var togetherjsSyncRequested = false;
8986

@@ -118,6 +115,7 @@ export abstract class AbstractBaseFrontend {
118115
num414Tries = 0;
119116

120117
abstract executeCode(forceStartingInstr?: number, forceRawInputLst?: string[]) : any;
118+
abstract finishSuccessfulExecution() : any;
121119
abstract handleUncaughtExceptionFunc(trace: any[]) : any;
122120

123121
constructor(params: any = {}) {
@@ -195,35 +193,6 @@ export abstract class AbstractBaseFrontend {
195193
$("#executeBtn").attr('disabled', false);
196194
$("#executeBtn").click(this.executeCodeFromScratch.bind(this));
197195

198-
// when you leave or reload the page, submit an updateHistoryJSON if you
199-
// have one. beforeunload seems to work better than unload(), but it's
200-
// still a bit flaky ... TODO: investigate :(
201-
$(window).on('beforeunload', () => {
202-
this.submitUpdateHistory('beforeunload');
203-
// don't return anything, or a modal dialog box might pop up
204-
});
205-
206-
// just do this as well, even though it might be hella redundant
207-
$(window).on('unload', () => {
208-
this.submitUpdateHistory('unload');
209-
// don't return anything, or a modal dialog box might pop up
210-
});
211-
212-
// periodically do submitUpdateHistory() to handle the case when
213-
// someone is simply idle on the page without reloading it or
214-
// re-editing code; that way, we can still get some signals rather
215-
// than nothing.
216-
var lastSubmittedUpdateHistoryLength = 0;
217-
setInterval(function() {
218-
if (this.myVisualizer) {
219-
var uh = this.myVisualizer.updateHistory;
220-
// don't submit identical entries repeatedly since that's redundant
221-
if (uh && (uh.length != lastSubmittedUpdateHistoryLength)) {
222-
lastSubmittedUpdateHistoryLength = uh.length;
223-
this.submitUpdateHistory('periodic');
224-
}
225-
}
226-
}, SUBMIT_UPDATE_HISTORY_INTERVAL_MS);
227196
}
228197

229198
// empty stub so that our code doesn't crash.
@@ -316,26 +285,6 @@ export abstract class AbstractBaseFrontend {
316285
this.isExecutingCode = false;
317286
}
318287

319-
optFinishSuccessfulExecution() {
320-
// 2014-05-25: implemented more detailed tracing for surveys
321-
this.myVisualizer.creationTime = new Date().getTime();
322-
// each element will be a two-element list consisting of:
323-
// [step number, timestamp]
324-
// (debounce entries that are less than 1 second apart to
325-
// compress the logs a bit when there's rapid scrubbing or scrolling)
326-
//
327-
// the first entry has a THIRD field:
328-
// [step number, timestamp, total # steps]
329-
//
330-
// subsequent entries don't need it since it will always be the same.
331-
// the invariant is that step number < total # steps (since it's
332-
// zero-indexed
333-
this.myVisualizer.updateHistory = [];
334-
this.myVisualizer.updateHistory.push([this.myVisualizer.curInstr,
335-
this.myVisualizer.creationTime,
336-
this.myVisualizer.curTrace.length]);
337-
}
338-
339288
executeCodeAndCreateViz(codeToExec,
340289
pyState,
341290
backendOptionsObj, frontendOptionsObj,
@@ -382,59 +331,12 @@ export abstract class AbstractBaseFrontend {
382331
} else {
383332
// success!
384333
this.myVisualizer = new pytutor.ExecutionVisualizer(outputDiv, dataFromBackend, frontendOptionsObj);
385-
386-
this.myVisualizer.add_pytutor_hook("end_updateOutput", function(args) {
387-
if (updateOutputSignalFromRemote) {
388-
return;
389-
}
390-
if (typeof TogetherJS !== 'undefined' && TogetherJS.running && !this.isExecutingCode) {
391-
TogetherJS.send({type: "updateOutput", step: args.myViz.curInstr});
392-
}
393-
394-
// debounce to compress a bit ... 250ms feels "right"
395-
$.doTimeout('updateOutputLogEvent', 250, () => {
396-
var obj: any = {type: 'updateOutput', step: args.myViz.curInstr,
397-
curline: args.myViz.curLineNumber,
398-
prevline: args.myViz.prevLineNumber};
399-
// optional fields
400-
if (args.myViz.curLineExceptionMsg) {
401-
obj.exception = args.myViz.curLineExceptionMsg;
402-
}
403-
if (args.myViz.curLineIsReturn) {
404-
obj.curLineIsReturn = true;
405-
}
406-
if (args.myViz.prevLineIsReturn) {
407-
obj.prevLineIsReturn = true;
408-
}
409-
_me.logEventCodeopticon(obj);
410-
});
411-
412-
// 2014-05-25: implemented more detailed tracing for surveys
413-
if (args.myViz.creationTime) {
414-
var curTs = new Date().getTime();
415-
416-
var uh = args.myViz.updateHistory;
417-
assert(uh.length > 0); // should already be seeded with an initial value
418-
if (uh.length > 1) { // don't try to "compress" the very first entry
419-
var lastTs = uh[uh.length - 1][1];
420-
// (debounce entries that are less than 1 second apart to
421-
// compress the logs a bit when there's rapid scrubbing or scrolling)
422-
if ((curTs - lastTs) < 1000) {
423-
uh.pop(); // get rid of last entry before pushing a new entry
424-
}
425-
}
426-
uh.push([args.myViz.curInstr, curTs]);
427-
}
428-
return [false]; // pass through to let other hooks keep handling
429-
});
430-
}
431-
// SUPER HACK -- slip in backendOptionsObj as an extra field
432-
if (this.myVisualizer) {
334+
// SUPER HACK -- slip in backendOptionsObj as an extra field
335+
// NB: why do we do this? for more detailed logging?
433336
this.myVisualizer.backendOptionsObj = backendOptionsObj;
337+
this.finishSuccessfulExecution(); // TODO: should we do this even if we're calling runTestCaseCallback?
434338
}
435339

436-
this.optFinishSuccessfulExecution();
437-
438340
// VERY SUBTLE -- reinitialize TogetherJS so that it can detect
439341
// and sync any new elements that are now inside myVisualizer
440342
if (typeof TogetherJS !== 'undefined' && TogetherJS.running) {
@@ -555,45 +457,6 @@ export abstract class AbstractBaseFrontend {
555457
}
556458
}
557459

558-
// Compress updateHistory before encoding and sending to
559-
// the server so that it takes up less room in the URL. Have each
560-
// entry except for the first be a delta from the FIRST entry.
561-
compressUpdateHistoryList() {
562-
assert(this.myVisualizer);
563-
var uh = this.myVisualizer.updateHistory;
564-
var encodedUh = [];
565-
if (uh) {
566-
encodedUh.push(uh[0]);
567-
568-
var firstTs = uh[0][1];
569-
for (var i = 1; i < uh.length; i++) {
570-
var e = uh[i];
571-
encodedUh.push([e[0], e[1] - firstTs]);
572-
}
573-
574-
// finally push a final entry with the current timestamp delta
575-
var curTs = new Date().getTime();
576-
encodedUh.push([this.myVisualizer.curInstr, curTs - firstTs]);
577-
}
578-
return encodedUh;
579-
}
580-
581-
// this feature was deployed on 2015-09-17, so check logs for
582-
// viz_interaction.py
583-
submitUpdateHistory(why) {
584-
if (this.myVisualizer) {
585-
var encodedUh = this.compressUpdateHistoryList();
586-
var encodedUhJSON = JSON.stringify(encodedUh);
587-
588-
var myArgs: any = {session_uuid: this.sessionUUID,
589-
updateHistoryJSON: encodedUhJSON};
590-
if (why) {
591-
myArgs.why = why;
592-
}
593-
$.get('viz_interaction.py', myArgs, function(dat) {});
594-
}
595-
}
596-
597460
setSurveyHTML() {
598461
$('#surveyPane').html(survey_v8);
599462
}

‎v5-unity/js/opt-frontend.ts‎

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ require('../css/opt-frontend.css');
5757

5858
// TODO: add Codeopticon dependencies later
5959

60-
var pendingCodeOutputScrollTop = null; // for shared sessions; put back later
60+
// for shared sessions; put back later
61+
var pendingCodeOutputScrollTop = null;
62+
var updateOutputSignalFromRemote = false;
6163

6264
const JAVA_BLANK_TEMPLATE = 'public class YourClassNameHere {\n\
6365
public static void main(String[] args) {\n\
@@ -71,7 +73,7 @@ const CPP_BLANK_TEMPLATE = 'int main() {\n\
7173
}'
7274

7375
const CODE_SNAPSHOT_DEBOUNCE_MS = 1000;
74-
76+
const SUBMIT_UPDATE_HISTORY_INTERVAL_MS = 1000 * 60;
7577

7678
var optFrontend; // singleton OptFrontend object
7779

@@ -387,9 +389,78 @@ class OptFrontend extends AbstractBaseFrontend {
387389
}
388390
}
389391

392+
// when you leave or reload the page, submit an updateHistoryJSON if you
393+
// have one. beforeunload seems to work better than unload(), but it's
394+
// still a bit flaky ... TODO: investigate :(
395+
$(window).on('beforeunload', () => {
396+
this.submitUpdateHistory('beforeunload');
397+
// don't return anything, or a modal dialog box might pop up
398+
});
399+
400+
// just do this as well, even though it might be hella redundant
401+
$(window).on('unload', () => {
402+
this.submitUpdateHistory('unload');
403+
// don't return anything, or a modal dialog box might pop up
404+
});
405+
406+
// periodically do submitUpdateHistory() to handle the case when
407+
// someone is simply idle on the page without reloading it or
408+
// re-editing code; that way, we can still get some signals rather
409+
// than nothing.
410+
var lastSubmittedUpdateHistoryLength = 0;
411+
setInterval(function() {
412+
if (this.myVisualizer) {
413+
var uh = this.myVisualizer.updateHistory;
414+
// don't submit identical entries repeatedly since that's redundant
415+
if (uh && (uh.length != lastSubmittedUpdateHistoryLength)) {
416+
lastSubmittedUpdateHistoryLength = uh.length;
417+
this.submitUpdateHistory('periodic');
418+
}
419+
}
420+
}, SUBMIT_UPDATE_HISTORY_INTERVAL_MS);
421+
390422
this.parseQueryString(); // do this at the end after Ace editor initialized
391423
}
392424

425+
// Compress updateHistory before encoding and sending to
426+
// the server so that it takes up less room in the URL. Have each
427+
// entry except for the first be a delta from the FIRST entry.
428+
compressUpdateHistoryList() {
429+
assert(this.myVisualizer);
430+
var uh = this.myVisualizer.updateHistory;
431+
var encodedUh = [];
432+
if (uh) {
433+
encodedUh.push(uh[0]);
434+
435+
var firstTs = uh[0][1];
436+
for (var i = 1; i < uh.length; i++) {
437+
var e = uh[i];
438+
encodedUh.push([e[0], e[1] - firstTs]);
439+
}
440+
441+
// finally push a final entry with the current timestamp delta
442+
var curTs = new Date().getTime();
443+
encodedUh.push([this.myVisualizer.curInstr, curTs - firstTs]);
444+
}
445+
return encodedUh;
446+
}
447+
448+
// this feature was deployed on 2015-09-17, so check logs for
449+
// viz_interaction.py
450+
submitUpdateHistory(why) {
451+
if (this.myVisualizer) {
452+
var encodedUh = this.compressUpdateHistoryList();
453+
var encodedUhJSON = JSON.stringify(encodedUh);
454+
455+
var myArgs: any = {session_uuid: this.sessionUUID,
456+
updateHistoryJSON: encodedUhJSON};
457+
if (why) {
458+
myArgs.why = why;
459+
}
460+
$.get('viz_interaction.py', myArgs, function(dat) {});
461+
}
462+
}
463+
393464
initAceEditor(height: number) {
394465
this.pyInputAceEditor = ace.edit('codeInputPane');
395466
var s = this.pyInputAceEditor.getSession();
@@ -531,9 +602,73 @@ class OptFrontend extends AbstractBaseFrontend {
531602
this.initDeltaObj(); // clear deltaObj to start counting over again
532603
}
533604

534-
optFinishSuccessfulExecution() {
605+
finishSuccessfulExecution() {
535606
this.enterDisplayMode(); // do this first!
536-
super.optFinishSuccessfulExecution();
607+
608+
if (this.myVisualizer) {
609+
this.myVisualizer.add_pytutor_hook("end_updateOutput", (args) => {
610+
if (updateOutputSignalFromRemote) {
611+
return;
612+
}
613+
if (typeof TogetherJS !== 'undefined' && TogetherJS.running && !this.isExecutingCode) {
614+
TogetherJS.send({type: "updateOutput", step: args.myViz.curInstr});
615+
}
616+
617+
// debounce to compress a bit ... 250ms feels "right"
618+
$.doTimeout('updateOutputLogEvent', 250, () => {
619+
var obj: any = {type: 'updateOutput', step: args.myViz.curInstr,
620+
curline: args.myViz.curLineNumber,
621+
prevline: args.myViz.prevLineNumber};
622+
// optional fields
623+
if (args.myViz.curLineExceptionMsg) {
624+
obj.exception = args.myViz.curLineExceptionMsg;
625+
}
626+
if (args.myViz.curLineIsReturn) {
627+
obj.curLineIsReturn = true;
628+
}
629+
if (args.myViz.prevLineIsReturn) {
630+
obj.prevLineIsReturn = true;
631+
}
632+
this.logEventCodeopticon(obj);
633+
});
634+
635+
// 2014-05-25: implemented more detailed tracing for surveys
636+
if (args.myViz.creationTime) {
637+
var curTs = new Date().getTime();
638+
639+
var uh = args.myViz.updateHistory;
640+
assert(uh.length > 0); // should already be seeded with an initial value
641+
if (uh.length > 1) { // don't try to "compress" the very first entry
642+
var lastTs = uh[uh.length - 1][1];
643+
// (debounce entries that are less than 1 second apart to
644+
// compress the logs a bit when there's rapid scrubbing or scrolling)
645+
if ((curTs - lastTs) < 1000) {
646+
uh.pop(); // get rid of last entry before pushing a new entry
647+
}
648+
}
649+
uh.push([args.myViz.curInstr, curTs]);
650+
}
651+
return [false]; // pass through to let other hooks keep handling
652+
});
653+
}
654+
655+
// 2014-05-25: implemented more detailed tracing for surveys
656+
this.myVisualizer.creationTime = new Date().getTime();
657+
// each element will be a two-element list consisting of:
658+
// [step number, timestamp]
659+
// (debounce entries that are less than 1 second apart to
660+
// compress the logs a bit when there's rapid scrubbing or scrolling)
661+
//
662+
// the first entry has a THIRD field:
663+
// [step number, timestamp, total # steps]
664+
//
665+
// subsequent entries don't need it since it will always be the same.
666+
// the invariant is that step number < total # steps (since it's
667+
// zero-indexed
668+
this.myVisualizer.updateHistory = [];
669+
this.myVisualizer.updateHistory.push([this.myVisualizer.curInstr,
670+
this.myVisualizer.creationTime,
671+
this.myVisualizer.curTrace.length]);
537672
/*
538673
if (typeof(activateSyntaxErrorSurvey) !== 'undefined' &&
539674
activateSyntaxErrorSurvey &&

‎v5-unity/js/opt-live.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright (C) Philip Guo (philip@pgbovine.net)
33
// LICENSE: https://github.com/pgbovine/OnlinePythonTutor/blob/master/LICENSE.txt
44

5+
// TODO: refactor to work with new opt-frontend-common.ts and opt-frontend.ts
6+
57
// TODO: using myVisualizer here borrowed from opt-frontend-common.js is
68
// very dicey and dangerous due to scoping issues!
79

0 commit comments

Comments
 (0)