From 431bab5de7c9b46d812fbaa5b5262a181a643203 Mon Sep 17 00:00:00 2001 From: Ken Holstein Date: Wed, 21 Jun 2017 00:08:12 -0400 Subject: [PATCH] added correct 'memory' code to student_doing_well detector; reverted detector adaptivity update temporarily - causes bug on TutorShop --- .../student_doing_well__moving_average.js | 12 ++- HTML/Assets/transaction_mailer_users.js | 14 ---- ...transaction_mailer_users_updateVarTable.js | 81 +++++++++++++++++++ 3 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 HTML/Assets/transaction_mailer_users_updateVarTable.js diff --git a/HTML/Assets/Detectors/Lumilo/student_doing_well__moving_average.js b/HTML/Assets/Detectors/Lumilo/student_doing_well__moving_average.js index 36f7ab0..0bd0118 100644 --- a/HTML/Assets/Detectors/Lumilo/student_doing_well__moving_average.js +++ b/HTML/Assets/Detectors/Lumilo/student_doing_well__moving_average.js @@ -20,7 +20,7 @@ var prevStep = "" var attemptCorrect; var windowSize = 7; var threshold = 6; -var attemptWindow = Array.apply(null, Array(windowSize)).map(Number.prototype.valueOf,0); +var attemptWindow; function receive_transaction( e ){ @@ -45,6 +45,8 @@ function receive_transaction( e ){ attemptCorrect = (e.data.tutor_data.action_evaluation.toLowerCase() == "correct") ? 1 : 0; attemptWindow.shift(); attemptWindow.push(attemptCorrect); + detector_output.history = JSON.stringify(attemptWindow); + var sumCorrect = attemptWindow.reduce(function(pv, cv) { return pv + cv; }, 0); console.log(attemptWindow); } @@ -100,6 +102,14 @@ self.onmessage = function ( e ) { detector_output.history = ""; detector_output.value = 0; } + + if (detector_output.history == "" || detector_output.history == null){ + attemptWindow = Array.apply(null, Array(windowSize)).map(Number.prototype.valueOf,0); + } + else{ + attemptWindow = JSON.parse(detector_output.history); + } + break; default: break; diff --git a/HTML/Assets/transaction_mailer_users.js b/HTML/Assets/transaction_mailer_users.js index 50b8a10..fc722a5 100644 --- a/HTML/Assets/transaction_mailer_users.js +++ b/HTML/Assets/transaction_mailer_users.js @@ -50,20 +50,6 @@ TransactionMailerUsers.create = function(path, txDestURL, scriptsDestURL, authTo } TransactionMailerUsers.active.push(detector); console.log("TransactionMailerUsers.create(): s, active["+i+"]=", s, TransactionMailerUsers.active[i]); - - detector.onmessage = function(e) - { - var sel = e.data.name; - var action = "UpdateVariable"; - var input = e.data.value; - - var sai = new CTATSAI(); - sai.setSelection(sel); - sai.setAction(action); - sai.setInput(input) - CTATCommShell.commShell.processComponentAction(sai=sai, tutorComponent=false, aTrigger="tutor") - }; - } return TransactionMailerUsers; diff --git a/HTML/Assets/transaction_mailer_users_updateVarTable.js b/HTML/Assets/transaction_mailer_users_updateVarTable.js new file mode 100644 index 0000000..50b8a10 --- /dev/null +++ b/HTML/Assets/transaction_mailer_users_updateVarTable.js @@ -0,0 +1,81 @@ +TransactionMailerUsers = +{ + process_transactions_url: "", + process_detectors_url: "", + authenticity_token: "", + mailerURL: "mail-worker.js", + mailer: null, + mailerPort: null, + scripts: ["Detectors/Lumilo/idle.js", + "Detectors/Lumilo/system_misuse.js", + "Detectors/Lumilo/struggle__moving_average.js", + "Detectors/Lumilo/student_doing_well__moving_average.js", + "Detectors/Lumilo/critical_struggle.js", + "Detectors/Lumilo/invisible_hand_raise.js"], + active: [] +}; + +TransactionMailerUsers.create = function(path, txDestURL, scriptsDestURL, authToken, scriptsInitzer) +{ + console.log("TransactionMailerUsers.create(): at entry, scriptsInitzer ", scriptsInitzer ); + + TransactionMailerUsers.mailer = new Worker(path+'/'+TransactionMailerUsers.mailerURL); + + TransactionMailerUsers.mailer.postMessage({ command: "process_transactions_url", "process_transactions_url": txDestURL, "process_detectors_url": scriptsDestURL, "authenticity_token": authToken}); + TransactionMailerUsers.process_transactions_url = txDestURL; + TransactionMailerUsers.authenticity_token = authToken; + TransactionMailerUsers.process_detectors_url = scriptsDestURL; + + var channel = new MessageChannel(); + TransactionMailerUsers.mailer.postMessage( + { command: "connectTransactionAssembler" }, + [ channel.port1 ] + ); + TransactionMailerUsers.mailerPort = channel.port2; + TransactionMailerUsers.mailerPort.onmessage = function(event) { + console.log("From mailer: "+event); + }; + + for(var i = 0; i < TransactionMailerUsers.scripts.length; ++i) + { + var s = path + '/' + TransactionMailerUsers.scripts[i]; + var detector = new Worker(s); + var mc = new MessageChannel(); + TransactionMailerUsers.mailer.postMessage({ command: "connectDetector" }, [ mc.port1 ]); + detector.postMessage({ command: "connectMailer" }, [ mc.port2 ]); + if(scriptsInitzer) + { + detector.postMessage({ command: "initialize", initializer: scriptsInitzer }); + console.log("TransactionMailerUsers.create(): sent command: initialize, scriptsInitzer ", scriptsInitzer ); + } + TransactionMailerUsers.active.push(detector); + console.log("TransactionMailerUsers.create(): s, active["+i+"]=", s, TransactionMailerUsers.active[i]); + + detector.onmessage = function(e) + { + var sel = e.data.name; + var action = "UpdateVariable"; + var input = e.data.value; + + var sai = new CTATSAI(); + sai.setSelection(sel); + sai.setAction(action); + sai.setInput(input) + CTATCommShell.commShell.processComponentAction(sai=sai, tutorComponent=false, aTrigger="tutor") + }; + + + } + return TransactionMailerUsers; +}; + +TransactionMailerUsers.sendTransaction = function(tx) +{ + TransactionMailerUsers.mailerPort.postMessage(tx); // post to listener in other thread + + var tmUsers = TransactionMailerUsers.active; + for(var i = 0; i < tmUsers; ++i) + { + tmUsers[i].postMessage(tx); + } +};