Skip to content

Commit 129e7a8

Browse files
committed
set up submitUpdateHistory
1 parent f5e0d1d commit 129e7a8

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ function generateUUID(){
126126
return uuid;
127127
};
128128

129+
var sessionUUID = generateUUID(); // remains constant throughout one page load ("session")
130+
129131

130132
// OMG nasty wtf?!?
131133

@@ -961,6 +963,10 @@ function genericOptFrontendReady() {
961963
return; // get out early
962964
}
963965

966+
if (settings.url.indexOf('viz_interaction.py') > -1) {
967+
return; // get out early
968+
}
969+
964970
/*
965971
This jqxhr.responseText might be indicative of the URL being too
966972
long, since the error message returned by the server is something
@@ -1171,6 +1177,8 @@ function updateAppDisplay(newAppMode) {
11711177
// conceptual model but breaks the browser's expected Forward and
11721178
// Back button flow
11731179
$("#pyOutputPane").empty();
1180+
// right before destroying, submit the visualizer's updateHistory
1181+
submitUpdateHistory();
11741182
myVisualizer = null;
11751183

11761184
$(document).scrollTop(0); // scroll to top to make UX better on small monitors
@@ -1548,6 +1556,7 @@ function executeCodeAndCreateViz(codeToExec,
15481556
{user_script : codeToExec,
15491557
options_json: JSON.stringify(backendOptionsObj),
15501558
user_uuid: supports_html5_storage() ? localStorage.getItem('opt_uuid') : undefined,
1559+
session_uuid: sessionUUID,
15511560
// if we don't have any deltas, then don't bother sending deltaObj:
15521561
diffs_json: deltaObj && (deltaObj.deltas.length > 0) ? JSON.stringify(deltaObj) : null},
15531562
function(dat) {} /* don't do anything since this is a dummy call */, "text");
@@ -1571,6 +1580,7 @@ function executeCodeAndCreateViz(codeToExec,
15711580
raw_input_json: rawInputLst.length > 0 ? JSON.stringify(rawInputLst) : '',
15721581
options_json: JSON.stringify(backendOptionsObj),
15731582
user_uuid: supports_html5_storage() ? localStorage.getItem('opt_uuid') : undefined,
1583+
session_uuid: sessionUUID,
15741584
// if we don't have any deltas, then don't bother sending deltaObj:
15751585
diffs_json: deltaObj && (deltaObj.deltas.length > 0) ? JSON.stringify(deltaObj) : null},
15761586
execCallback, "json");
@@ -1580,6 +1590,40 @@ function executeCodeAndCreateViz(codeToExec,
15801590
}
15811591

15821592

1593+
function submitUpdateHistory() {
1594+
if (myVisualizer) {
1595+
// before submitting, append the FINAL entry to show the current time and position
1596+
var curTs = new Date().getTime();
1597+
myVisualizer.updateHistory.push([myVisualizer.curInstr, curTs]);
1598+
1599+
// Finally, compress updateHistory before encoding and sending to
1600+
// the server so that it takes up less room in the URL. Have each
1601+
// entry except for the first be a delta from the FIRST entry.
1602+
var uh = myVisualizer.updateHistory;
1603+
var encodedUh = [];
1604+
encodedUh.push(uh[0]);
1605+
1606+
var firstTs = uh[0][1];
1607+
for (var i = 1; i < uh.length; i++) {
1608+
var e = uh[i];
1609+
encodedUh.push([e[0], e[1] - firstTs]);
1610+
}
1611+
1612+
//var uhJSON = JSON.stringify(uh);
1613+
var encodedUhJSON = JSON.stringify(encodedUh);
1614+
1615+
console.log(encodedUhJSON);
1616+
1617+
//console.log(uhJSON.length);
1618+
//console.log(encodedUhJSON.length);
1619+
1620+
var myArgs = {session_uuid: sessionUUID,
1621+
updateHistoryJSON: encodedUhJSON};
1622+
$.get('viz_interaction.py', myArgs, function(dat) {});
1623+
}
1624+
}
1625+
1626+
15831627
/* For survey questions:
15841628
15851629
Versions of survey wording:

0 commit comments

Comments
 (0)