From af17389b94279d1f6c92c73d1a3aa0990d6721a5 Mon Sep 17 00:00:00 2001 From: Ken Holstein Date: Sun, 23 Apr 2017 16:37:16 -0400 Subject: [PATCH] update template --- HTML/Assets/Detectors/bkt_models/BKT.js | 23 +++++++ HTML/Assets/Detectors/currentAttemptCount.js | 31 +++++++--- .../lynnette_error_category_frequency.js | 23 +++++++ .../Detectors/help_models/help_model.js | 23 +++++++ .../help_models/help_model_try_if_low.js | 24 ++++++++ HTML/Assets/Detectors/stagnation.js | 30 ++++++--- HTML/Assets/detector_template.js | 49 ++++++++++----- HTML/Assets/transaction_mailer_users.js | 61 +++++++++++++++++++ 8 files changed, 235 insertions(+), 29 deletions(-) create mode 100644 HTML/Assets/transaction_mailer_users.js diff --git a/HTML/Assets/Detectors/bkt_models/BKT.js b/HTML/Assets/Detectors/bkt_models/BKT.js index c1652dc..f46e2eb 100644 --- a/HTML/Assets/Detectors/bkt_models/BKT.js +++ b/HTML/Assets/Detectors/bkt_models/BKT.js @@ -144,6 +144,29 @@ self.onmessage = function ( e ) { mailer = e.ports[0]; mailer.onmessage = receive_transaction; break; + case "initialize": + for (initItem in e.data.initializer){ + if (e.data.initializer[initItem].name == variableName){ + detector_output.history = e.data.initializer[initItem].history; + detector_output.value = e.data.initializer[initItem].value; + } + } + + //optional: Below, specify conditions under which a detector + //should NOT remember their most recent value and history (using the variable "detectorForget"). + //(e.g., setting the condition to "true" will mean that the detector + // will always be reset between problems... and setting the condition to "false" + // means that the detector will never be reset between problems) + // + // + // + detectorForget = false; + + if (detectorForget){ + detector_output.history = ""; + detector_output.value = 0; + } + break; default: break; } diff --git a/HTML/Assets/Detectors/currentAttemptCount.js b/HTML/Assets/Detectors/currentAttemptCount.js index 50b89d0..99a8ed5 100644 --- a/HTML/Assets/Detectors/currentAttemptCount.js +++ b/HTML/Assets/Detectors/currentAttemptCount.js @@ -15,14 +15,6 @@ var mailer; //initialize any custom global variables for this detector here var prevStep = "" -//TO-DO: -// detector initialiization, and leave comment -// showing user how not to initialize (or, if we decide to -// initialize all detector variables by default, at startup... -// I suppose this would mean showing user how to clear initialized -// values upon the first transaction received?) - - function receive_transaction( e ){ //e is the data of the transaction from mailer from transaction assembler @@ -81,6 +73,29 @@ self.onmessage = function ( e ) { mailer = e.ports[0]; mailer.onmessage = receive_transaction; break; + case "initialize": + for (initItem in e.data.initializer){ + if (e.data.initializer[initItem].name == variableName){ + detector_output.history = e.data.initializer[initItem].history; + detector_output.value = e.data.initializer[initItem].value; + } + } + + //optional: Below, specify conditions under which a detector + //should NOT remember their most recent value and history (using the variable "detectorForget"). + //(e.g., setting the condition to "true" will mean that the detector + // will always be reset between problems... and setting the condition to "false" + // means that the detector will never be reset between problems) + // + // + // + detectorForget = true; + + if (detectorForget){ + detector_output.history = ""; + detector_output.value = 0; + } + break; default: break; } diff --git a/HTML/Assets/Detectors/error_categorizers/lynnette_error_category_frequency.js b/HTML/Assets/Detectors/error_categorizers/lynnette_error_category_frequency.js index 2324cfb..97876ca 100644 --- a/HTML/Assets/Detectors/error_categorizers/lynnette_error_category_frequency.js +++ b/HTML/Assets/Detectors/error_categorizers/lynnette_error_category_frequency.js @@ -273,6 +273,29 @@ self.onmessage = function ( e ) { mailer = e.ports[0]; mailer.onmessage = receive_transaction; break; + case "initialize": + for (initItem in e.data.initializer){ + if (e.data.initializer[initItem].name == variableName){ + detector_output.history = e.data.initializer[initItem].history; + detector_output.value = e.data.initializer[initItem].value; + } + } + + //optional: Below, specify conditions under which a detector + //should NOT remember their most recent value and history (using the variable "detectorForget"). + //(e.g., setting the condition to "true" will mean that the detector + // will always be reset between problems... and setting the condition to "false" + // means that the detector will never be reset between problems) + // + // + // + detectorForget = false; + + if (detectorForget){ + detector_output.history = ""; + detector_output.value = 0; + } + break; default: break; } diff --git a/HTML/Assets/Detectors/help_models/help_model.js b/HTML/Assets/Detectors/help_models/help_model.js index ce7ba34..9a5b420 100644 --- a/HTML/Assets/Detectors/help_models/help_model.js +++ b/HTML/Assets/Detectors/help_models/help_model.js @@ -245,6 +245,29 @@ self.onmessage = function ( e ) { mailer = e.ports[0]; mailer.onmessage = receive_transaction; break; + case "initialize": + for (initItem in e.data.initializer){ + if (e.data.initializer[initItem].name == variableName){ + detector_output.history = e.data.initializer[initItem].history; + detector_output.value = e.data.initializer[initItem].value; + } + } + + //optional: Below, specify conditions under which a detector + //should NOT remember their most recent value and history (using the variable "detectorForget"). + //(e.g., setting the condition to "true" will mean that the detector + // will always be reset between problems... and setting the condition to "false" + // means that the detector will never be reset between problems) + // + // + // + detectorForget = true; + + if (detectorForget){ + detector_output.history = ""; + detector_output.value = 0; + } + break; default: break; } diff --git a/HTML/Assets/Detectors/help_models/help_model_try_if_low.js b/HTML/Assets/Detectors/help_models/help_model_try_if_low.js index f7db13e..2357ecd 100644 --- a/HTML/Assets/Detectors/help_models/help_model_try_if_low.js +++ b/HTML/Assets/Detectors/help_models/help_model_try_if_low.js @@ -23,6 +23,7 @@ var help_variables = {"lastAction": "null", "lastHintLength": "", "lastSenseOfWhatToDo": false }; + //TUNABLE PARAMETERS var errorThreshold = 3; //currently arbitrary var newStepThreshold = 3; //currently arbitrary @@ -284,6 +285,29 @@ self.onmessage = function ( e ) { mailer = e.ports[0]; mailer.onmessage = receive_transaction; break; + case "initialize": + for (initItem in e.data.initializer){ + if (e.data.initializer[initItem].name == variableName){ + detector_output.history = e.data.initializer[initItem].history; + detector_output.value = e.data.initializer[initItem].value; + } + } + + //optional: Below, specify conditions under which a detector + //should NOT remember their most recent value and history (using the variable "detectorForget"). + //(e.g., setting the condition to "true" will mean that the detector + // will always be reset between problems... and setting the condition to "false" + // means that the detector will never be reset between problems) + // + // + // + detectorForget = true; + + if (detectorForget){ + detector_output.history = ""; + detector_output.value = 0; + } + break; default: break; } diff --git a/HTML/Assets/Detectors/stagnation.js b/HTML/Assets/Detectors/stagnation.js index c59ec0b..7e205f1 100644 --- a/HTML/Assets/Detectors/stagnation.js +++ b/HTML/Assets/Detectors/stagnation.js @@ -17,13 +17,6 @@ var timerId var timerId2 var timerId3 -//TO-DO: -// detector initialiization, and leave comment -// showing user how not to initialize (or, if we decide to -// initialize all detector variables by default, at startup... -// I suppose this would mean showing user how to clear initialized -// values upon the first transaction received?) - function receive_transaction( e ){ //e is the data of the transaction from mailer from transaction assembler @@ -93,6 +86,29 @@ self.onmessage = function ( e ) { mailer = e.ports[0]; mailer.onmessage = receive_transaction; break; + case "initialize": + for (initItem in e.data.initializer){ + if (e.data.initializer[initItem].name == variableName){ + detector_output.history = e.data.initializer[initItem].history; + detector_output.value = e.data.initializer[initItem].value; + } + } + + //optional: Below, specify conditions under which a detector + //should NOT remember their most recent value and history (using the variable "detectorForget"). + //(e.g., setting the condition to "true" will mean that the detector + // will always be reset between problems... and setting the condition to "false" + // means that the detector will never be reset between problems) + // + // + // + detectorForget = true; + + if (detectorForget){ + detector_output.history = ""; + detector_output.value = 0; + } + break; default: break; } diff --git a/HTML/Assets/detector_template.js b/HTML/Assets/detector_template.js index e9b456d..41d6078 100644 --- a/HTML/Assets/detector_template.js +++ b/HTML/Assets/detector_template.js @@ -18,21 +18,9 @@ var mailer; //initialize any custom global variables for this detector here var prevStep = "" -//TO-DO: -// detector initialiization, and leave comment -// showing user how not to initialize (or, if we decide to -// initialize all detector variables by default, at startup... -// I suppose this would mean showing user how to clear initialized -// values upon the first transaction received?) - - function receive_transaction( e ){ //e is the data of the transaction from mailer from transaction assembler - //TEST CODE - //console.log("in detector1 with data:"); - //console.log(e.data); - //set conditions under which transaction should be processed //(i.e., to update internal state and history, without //necessarily updating external state and history) @@ -62,6 +50,14 @@ function receive_transaction( e ){ if(e.data.actor == 'student' && e.data.tool_data.action != "UpdateVariable"){ detector_output.time = new Date(); detector_output.transaction_id = e.data.transaction_id; + + //custom processing (insert code here) + // + // + // + // + // + mailer.postMessage(detector_output); postMessage(detector_output); console.log("output_data = ", detector_output); @@ -74,10 +70,35 @@ self.onmessage = function ( e ) { switch( e.data.command ) { case "connectMailer": - mailer = e.ports[0]; - mailer.onmessage = receive_transaction; + mailer = e.ports[0]; + mailer.onmessage = receive_transaction; + break; + case "initialize": + for (initItem in e.data.initializer){ + if (e.data.initializer[initItem].name == variableName){ + detector_output.history = e.data.initializer[initItem].history; + detector_output.value = e.data.initializer[initItem].value; + } + } + + //optional: Below, specify conditions under which a detector + //should NOT remember their most recent value and history (using the variable "detectorForget"). + //(e.g., setting the condition to "true" will mean that the detector + // will always be reset between problems... and setting the condition to "false" + // means that the detector will never be reset between problems) + // + // + // + detectorForget = true; + + if (detectorForget){ + detector_output.history = ""; + detector_output.value = 0; + } break; default: break; + } + } \ No newline at end of file diff --git a/HTML/Assets/transaction_mailer_users.js b/HTML/Assets/transaction_mailer_users.js new file mode 100644 index 0000000..ac0c01d --- /dev/null +++ b/HTML/Assets/transaction_mailer_users.js @@ -0,0 +1,61 @@ +TransactionMailerUsers = +{ + process_transactions_url: "", + process_detectors_url: "", + authenticity_token: "", + mailerURL: "mail-worker.js", + mailer: null, + mailerPort: null, + scripts: ["currentAttemptCount.js", "help_model_try_if_low.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]); + } + 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); + } +};