Skip to content

Commit

Permalink
update template
Browse files Browse the repository at this point in the history
  • Loading branch information
d19fe8 committed Apr 23, 2017
1 parent 779e380 commit af17389
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 29 deletions.
23 changes: 23 additions & 0 deletions HTML/Assets/Detectors/bkt_models/BKT.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
31 changes: 23 additions & 8 deletions HTML/Assets/Detectors/currentAttemptCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions HTML/Assets/Detectors/help_models/help_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions HTML/Assets/Detectors/help_models/help_model_try_if_low.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var help_variables = {"lastAction": "null",
"lastHintLength": "",
"lastSenseOfWhatToDo": false
};

//TUNABLE PARAMETERS
var errorThreshold = 3; //currently arbitrary
var newStepThreshold = 3; //currently arbitrary
Expand Down Expand Up @@ -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;
}
Expand Down
30 changes: 23 additions & 7 deletions HTML/Assets/Detectors/stagnation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
49 changes: 35 additions & 14 deletions HTML/Assets/detector_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;

}

}
61 changes: 61 additions & 0 deletions HTML/Assets/transaction_mailer_users.js
Original file line number Diff line number Diff line change
@@ -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);
}
};

0 comments on commit af17389

Please sign in to comment.