From d2150cf0ed43abc8e496e9a95013028325057976 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 5 Oct 2015 17:37:49 +0200 Subject: Record all user activity in trace New generic actions: open(time), close plan hint(feedback), test(feedback) New Prolog actions: prolog_solve(query), prolog_next, prolog_end New Python actions: python_run(program), python_stop, python_input(text) New robot actions: robot_run(program), robot_stop(program) --- js/codeq/prolog.js | 12 ++++++++---- js/codeq/python.js | 8 ++++++++ js/codeq/robot.js | 14 ++++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js index 2aeede4..69523b0 100644 --- a/js/codeq/prolog.js +++ b/js/codeq/prolog.js @@ -166,7 +166,7 @@ 'step': 'run', 'program': editor.getDoc().getValue(), 'query': command, - 'trace': activityHandler.addAndPurge({'typ': 'slv', 'qry': command}) + 'trace': activityHandler.addAndPurge({'typ': 'prolog_solve', 'query': command}) }, problem_id).then(tcs, tcf); } else { @@ -176,7 +176,7 @@ return codeq.comms.sendQuery({ 'problem_id': problem_id, 'step': 'next', - 'trace': activityHandler.addAndPurge({'typ': 'nxt'}) + 'trace': activityHandler.addAndPurge({'typ': 'prolog_next'}) }, problem_id).then(tcs, tcf); } else { @@ -185,10 +185,9 @@ return codeq.comms.sendQuery({ 'problem_id': problem_id, 'step': 'end', - 'trace': activityHandler.addAndPurge({'typ': 'stp'}) + 'trace': activityHandler.addAndPurge({'typ': 'prolog_end'}) }, problem_id).then(tcs, tcf); } - } }; @@ -240,6 +239,7 @@ }); jqBtnPlan.on('click', function () { + activityHandler.queueTrace({'typ': 'plan'}); if (!hinter.planNext()) { jqBtnPlan.prop('disabled', true).blur(); } @@ -255,6 +255,7 @@ }) .then(function (data) { if (data.code === 0) { + activityHandler.queueTrace({'typ': 'hint', 'feedback': data.hints}); hinter.handle(data.hints); } else { @@ -279,6 +280,7 @@ }) .then(function (data) { if (data.code === 0) { + activityHandler.queueTrace({'typ': 'test', 'feedback': data.hints}); hinter.handle(data.hints); } else { @@ -294,6 +296,7 @@ }); codeq.comms.loadProblem(problemDef.id).done(); + activityHandler.queueTrace({'typ': 'open', 'time': Date.now()}); return { destroy: function () { @@ -301,6 +304,7 @@ $('#screen_prolog .title').text('');//empty the title text jqAllButtons.off(); editor.off('change'); + activityHandler.queueTrace({'typ': 'close'}); activityHandler.flush(); hinter.destroy(); terminal.destroy(); diff --git a/js/codeq/python.js b/js/codeq/python.js index 4d6ace3..236d947 100644 --- a/js/codeq/python.js +++ b/js/codeq/python.js @@ -139,6 +139,7 @@ terminal.onInput = function (text) { terminal.leftmostCol = 0; + activityHandler.queueTrace({'typ': 'python_input', 'txt': text + '\n'}); return codeq.comms.sendPythonPush({ 'text': text + '\n' }).then(tcs, tcf); @@ -198,6 +199,7 @@ }); jqBtnPlan.on('click', function () { + activityHandler.queueTrace({'typ': 'plan'}); if (!hinter.planNext()) { jqBtnPlan.prop('disabled', true).blur(); } @@ -211,6 +213,7 @@ }) .then(function (data) { if (data.code === 0) { + activityHandler.queueTrace({'typ': 'hint', 'feedback': data.hints}); hinter.handle(data.hints); } else { @@ -229,6 +232,7 @@ }) .then(function (data) { if (data.code === 0) { + activityHandler.queueTrace({'typ': 'test', 'feedback': data.hints}); hinter.handle(data.hints); } else { @@ -240,6 +244,7 @@ }); jqBtnRun.on('click', function () { var program = editor.getDoc().getValue(); + activityHandler.queueTrace({'typ': 'python_run', 'program': program}); codeq.comms.sendPythonStop({}) .then(function () { codeq.comms.sendPythonExec({ @@ -252,12 +257,14 @@ jqTerminal.click(); }); jqBtnStop.on('click', function () { + activityHandler.queueTrace({'typ': 'python_stop'}); codeq.comms.sendPythonStop({}) .fail(commError) .done(); }); codeq.comms.loadProblem(problemDef.id).done(); + activityHandler.queueTrace({'typ': 'open', 'time': Date.now()}); return { destroy: function () { @@ -266,6 +273,7 @@ jqAllButtons.off(); editor.off('change'); codeq.comms.off('terminal_output'); // stop listening for the terminal events from server + activityHandler.queueTrace({'typ': 'close'}); activityHandler.flush(); hinter.destroy(); terminal.destroy(); diff --git a/js/codeq/robot.js b/js/codeq/robot.js index 0a62a2a..c716be8 100644 --- a/js/codeq/robot.js +++ b/js/codeq/robot.js @@ -196,6 +196,7 @@ }); jqBtnPlan.on('click', function () { + activityHandler.queueTrace({'typ': 'plan'}); if (!hinter.planNext()) { jqBtnPlan.prop('disabled', true).blur(); } @@ -209,6 +210,7 @@ }) .then(function (data) { if (data.code === 0) { + activityHandler.queueTrace({'typ': 'hint', 'feedback': data.hints}); hinter.handle(data.hints); } else { @@ -219,18 +221,17 @@ .done(); }); jqBtnRun.on('click', function () { - var url = 'http://' + $('#robot_ip').val() + ':8000/run', - doc = editor.getDoc(); - - socket.send(JSON.stringify({action: 'run', program: doc.getValue()})); + var program = editor.getDoc().getValue(); + activityHandler.queueTrace({'typ': 'robot_run', 'program': program}); + socket.send(JSON.stringify({action: 'run', program: program})); }); jqBtnStop.on('click', function () { - var url = 'http://' + $('#robot_ip').val() + ':8000/stop'; - + activityHandler.queueTrace({'typ': 'robot_stop'}); socket.send(JSON.stringify({action: 'stop'})); }); codeq.comms.loadProblem(problemDef.id).done(); + activityHandler.queueTrace({'typ': 'open', 'time': Date.now()}); return { destroy: function () { @@ -250,6 +251,7 @@ $('#screen_robot .title').text('');//empty the title text jqAllButtons.off(); editor.off('change'); + activityHandler.queueTrace({'typ': 'close'}); activityHandler.flush(); hinter.destroy(); jqDescriptionContent.empty(); -- cgit v1.2.1 From 8f35e1e3c2ffc08b17cf76f8cf1d4944c20af440 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 5 Oct 2015 19:21:05 +0200 Subject: Save current program in trace with each 'open' action So we can resynchronize if something goes wrong. --- js/codeq/prolog.js | 6 +++++- js/codeq/python.js | 6 +++++- js/codeq/robot.js | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js index 69523b0..ce1865a 100644 --- a/js/codeq/prolog.js +++ b/js/codeq/prolog.js @@ -296,7 +296,11 @@ }); codeq.comms.loadProblem(problemDef.id).done(); - activityHandler.queueTrace({'typ': 'open', 'time': Date.now()}); + activityHandler.queueTrace({ + 'typ': 'open', + 'time': Date.now(), + 'content': editor.getDoc().getValue() + }); return { destroy: function () { diff --git a/js/codeq/python.js b/js/codeq/python.js index 236d947..c3a76b9 100644 --- a/js/codeq/python.js +++ b/js/codeq/python.js @@ -264,7 +264,11 @@ }); codeq.comms.loadProblem(problemDef.id).done(); - activityHandler.queueTrace({'typ': 'open', 'time': Date.now()}); + activityHandler.queueTrace({ + 'typ': 'open', + 'time': Date.now(), + 'content': editor.getDoc().getValue() + }); return { destroy: function () { diff --git a/js/codeq/robot.js b/js/codeq/robot.js index c716be8..5d86559 100644 --- a/js/codeq/robot.js +++ b/js/codeq/robot.js @@ -231,7 +231,11 @@ }); codeq.comms.loadProblem(problemDef.id).done(); - activityHandler.queueTrace({'typ': 'open', 'time': Date.now()}); + activityHandler.queueTrace({ + 'typ': 'open', + 'time': Date.now(), + 'content': editor.getDoc().getValue() + }); return { destroy: function () { -- cgit v1.2.1