@@ -34,8 +34,6 @@ var pytutor = require('./pytutor.ts');
3434var 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:
4139const 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 ;
8784var executeCodeSignalFromRemote = false ;
8885var 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 }
0 commit comments