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); + } +};