Skip to content

Commit b85efe1

Browse files
committed
bah
1 parent 0b1918a commit b85efe1

File tree

1 file changed

+45
-27
lines changed

1 file changed

+45
-27
lines changed

v3/js/opt-frontend-common.js

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,12 +1150,11 @@ function executePythonCode(pythonSourceCode,
11501150
} else {
11511151
myVisualizer = new ExecutionVisualizer(outputDiv, dataFromBackend, frontendOptionsObj);
11521152
}
1153-
1154-
handleSuccessFunc();
1155-
11561153
// SUPER HACK -- slip in backendOptionsObj as an extra field
11571154
myVisualizer.backendOptionsObj = backendOptionsObj;
11581155

1156+
handleSuccessFunc();
1157+
11591158
// VERY SUBTLE -- reinitialize TogetherJS so that it can detect
11601159
// and sync any new elements that are now inside myVisualizer
11611160
if (typeof TogetherJS !== 'undefined' && TogetherJS.running) {
@@ -1439,7 +1438,21 @@ display a brief "Thanks!" note]
14391438

14401439
/* Version 3 - deployed on 2014-07-13
14411440
1441+
Display one of 3 display-mode surveys, depending on the contents of
1442+
myVisualizer.backendOptionsObj.survey.testing_group
1443+
1444+
'a' / 'b' -- A/B testing of two kinds of surveys
1445+
1446+
'c' -- if the user has filled in an answer to 'What do you hope to
1447+
learn by visualizing this code?' when hitting "Visualize Execution",
1448+
then echo that phrase back to them and display a custom survey
1449+
14421450
*/
1451+
if (!myVisualizer || !myVisualizer.backendOptionsObj.survey) {
1452+
return;
1453+
}
1454+
1455+
var surveyObj = myVisualizer.backendOptionsObj.survey;
14431456

14441457
var display_mode_survey_v3a = '\n\
14451458
<div id="vizSurveyLabel">\n\
@@ -1478,47 +1491,57 @@ display a brief "Thanks!" note]
14781491
</div>\n\
14791492
</div>\n';
14801493

1494+
var testingGroup = surveyObj.testing_group;
14811495

1482-
var testCondition = 'a';
14831496
var display_mode_survey_HTML = '';
1484-
1485-
if (testCondition == 'a') {
1497+
if (testingGroup == 'a') {
14861498
display_mode_survey_HTML = display_mode_survey_v3a;
1487-
} else if (testCondition == 'b') {
1499+
} else if (testingGroup == 'b') {
14881500
display_mode_survey_HTML = display_mode_survey_v3b;
1489-
} else if (testCondition == 'c') {
1501+
} else if (testingGroup == 'c') {
14901502
display_mode_survey_HTML = display_mode_survey_v3c;
14911503
} else {
14921504
assert(false);
14931505
}
14941506

14951507
$("#surveyHeader").html(display_mode_survey_HTML);
1508+
14961509
$("#vizSurveyLabel").css('font-size', '8pt')
14971510
.css('color', '#666')
14981511
.css('margin-bottom', '5pt');
14991512
$(".surveyBtn").css('margin-right', '6px');
15001513

1514+
if (testingGroup == 'c') {
1515+
$("#userHopeLearn").html(htmlspecialchars(surveyObj.what_learn_Q));
1516+
}
1517+
1518+
1519+
// testingGroup == 'a' || testingGroup == 'c'
15011520
// use unbind first so that this function is idempotent
15021521
$('.surveyBtn').unbind().click(function(e) {
1503-
var myArgs = getAppState();
1504-
15051522
var buttonPrompt = $(this).html();
15061523
var res = prompt('You said, "' + buttonPrompt + '"' + '\nPlease describe what you just learned:');
15071524

1508-
if ($.trim(res)) {
1509-
myArgs.surveyQuestion = buttonPrompt;
1510-
myArgs.surveyResponse = res;
1511-
myArgs.surveyVersion = 'v3';
1525+
if (!$.trim(res)) {
1526+
return;
1527+
}
15121528

1513-
// 2014-05-25: implemented more detailed tracing for surveys
1514-
if (myVisualizer) {
1515-
myArgs.updateHistoryJSON = JSON.stringify(myVisualizer.updateHistory);
1516-
}
1529+
var myArgs = getAppState();
1530+
myArgs.surveyQuestion = buttonPrompt;
1531+
myArgs.surveyResponse = res;
1532+
myArgs.surveyVersion = 'v3';
1533+
myArgs.testing_group = testingGroup; // use underscore for consistency
15171534

1518-
$.get('survey.py', myArgs, function(dat) {});
1535+
myArgs.updateHistoryJSON = JSON.stringify(myVisualizer.updateHistory);
1536+
1537+
if (surveyObj.what_learn_Q) {
1538+
myArgs.what_learn_Q = surveyObj.what_learn_Q;
15191539
}
1540+
1541+
$.get('survey.py', myArgs, function(dat) {});
15201542
});
15211543

1544+
// testingGroup == 'b'
15221545
// use unbind first so that this function is idempotent
15231546
$('#iJustLearnedSubmission').unbind().click(function(e) {
15241547
var resp = $("#iJustLearnedInput").val();
@@ -1528,25 +1551,20 @@ display a brief "Thanks!" note]
15281551
}
15291552

15301553
var myArgs = getAppState();
1531-
15321554
myArgs.surveyQuestion = "What did you just learn?";
15331555
myArgs.surveyResponse = resp;
15341556
myArgs.surveyVersion = 'v3';
1557+
myArgs.testing_group = testingGroup; // use underscore for consistency
15351558

1536-
// 2014-05-25: implemented more detailed tracing for surveys
1537-
if (myVisualizer) {
1538-
myArgs.updateHistoryJSON = JSON.stringify(myVisualizer.updateHistory);
1539-
}
1559+
myArgs.updateHistoryJSON = JSON.stringify(myVisualizer.updateHistory);
15401560

15411561
$.get('survey.py', myArgs, function(dat) {});
15421562

1563+
15431564
$("#iJustLearnedInput").val('');
15441565
$("#iJustLearnedThanks").show();
15451566
$.doTimeout('iJustLearnedThanksFadeOut', 1200, function() {
15461567
$("#iJustLearnedThanks").fadeOut(1000);
15471568
});
15481569
});
1549-
1550-
1551-
15521570
}

0 commit comments

Comments
 (0)