Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
d19fe8 authored Feb 9, 2018
1 parent e2d2205 commit edc740e
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 215 deletions.
319 changes: 173 additions & 146 deletions HTML/Assets/detector_template.js
Original file line number Diff line number Diff line change
@@ -1,147 +1,174 @@
//detector template

//add output variable name below
var variableName = "insert_variable_name_here"

//initializations (do not touch)
var detector_output = {name: variableName,
category: "Dashboard",
value: 0,
history: "",
skill_names: "",
step_id: "",
transaction_id: "",
time: ""
};
var mailer;


//declare any custom global variables that will be initialized
//based on "remembered" values across problem boundaries, here
// (initialize these at the bottom of this file, inside of self.onmessage)
//
//
//
//
//


//declare and/or initialize any other custom global variables for this detector here...
//
//
//
//
//
//[optional] single out TUNABLE PARAMETERS below
//
//
//
//


function receive_transaction( e ){
//e is the data of the transaction from mailer from transaction assembler

//set conditions under which transaction should be processed
//(i.e., to update internal state and history, without
//necessarily updating external state and history)
if(e.data.actor == 'student' && e.data.tool_data.action != "UpdateVariable"){
//do not touch
rawSkills = e.data.tutor_data.skills
var currSkills = []
for (var property in rawSkills) {
if (rawSkills.hasOwnProperty(property)) {
currSkills.push(rawSkills[property].name + "/" + rawSkills[property].category)
}
}
detector_output.skill_names = currSkills;
detector_output.step_id = e.data.tutor_data.step_id;

//custom processing (insert code here)
//
//
//
//
//

}

//set conditions under which detector should update
//external state and history
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);
}
}


self.onmessage = function ( e ) {
console.log(variableName, " self.onmessage:", e, e.data, (e.data?e.data.commmand:null), (e.data?e.data.transaction:null), e.ports);
switch( e.data.command )
{
case "connectMailer":
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: In "detectorForget", 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;
}


//optional: If any global variables are based on remembered values across problem boundaries,
// these initializations should be written here
//
//
if (detector_output.history == "" || detector_output.history == null){
//in the event that the detector history is empty,
//initialize variables to your desired 'default' values
//
//
}
else{
//if the detector history is not empty, you can access it via:
// JSON.parse(detector_output.history);
//...and initialize your variables to your desired values, based on
//this history
//
//
}

break;
default:
break;

}

//detector template

//add output variable name below
var variableName = "insert_variable_name_here"

//initializations (do not touch)
var detector_output = {name: variableName,
category: "Dashboard",
value: 0,
history: "",
skill_names: "",
step_id: "",
transaction_id: "",
time: ""
};
var mailer;


//declare any custom global variables that will be initialized
//based on "remembered" values across problem boundaries, here
// (initialize these at the bottom of this file, inside of self.onmessage)
//
//
//
//
//


//declare and/or initialize any other custom global variables for this detector here...
//
//
//
//
//
//[optional] single out TUNABLE PARAMETERS below
//
//
//
//


function receive_transaction( e ){
//e is the data of the transaction from mailer from transaction assembler

//set conditions under which transaction should be processed
//(i.e., to update internal state and history, without
//necessarily updating external state and history)
if(e.data.actor == 'student' && e.data.tool_data.action != "UpdateVariable"){
//do not touch
rawSkills = e.data.tutor_data.skills
var currSkills = []
for (var property in rawSkills) {
if (rawSkills.hasOwnProperty(property)) {
currSkills.push(rawSkills[property].name + "/" + rawSkills[property].category)
}
}
detector_output.skill_names = currSkills;
detector_output.step_id = e.data.tutor_data.step_id;

//custom processing (insert code here)
//
//
//
//
//

}

//set conditions under which detector should update
//external state and history
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);
}
}

var numRowsReceived = 0;
var numRowsProcessed = 0;

self.onmessage = function ( e ) {
console.log(variableName, " self.onmessage:", e, e.data, (e.data?e.data.commmand:null), (e.data?e.data.transaction:null), e.ports);
switch( e.data.command )
{
case "offlineMode":
//console.log(event.data.message);
offlineMode = true;
numRowsReceived++;
receive_transaction({data: event.data.message});
numRowsProcessed++;
break;
case "offlineNewProblem":
console.log("new problem!");
initTime = "";
break;
case "offlineNewStudent":
console.log("new student!");
detector_output.category = event.data.studentId;
detector_output.history = "";
detector_output.value = "0, > 0 s";
initTime = "";
break;
case "endOfOfflineMessages":
setInterval(function() {
if (numRowsReceived === numRowsProcessed) {
postMessage("readyToTerminate");
}
},200);
break;
case "connectMailer":
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: In "detectorForget", 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;
}


//optional: If any global variables are based on remembered values across problem boundaries,
// these initializations should be written here
//
//
if (detector_output.history == "" || detector_output.history == null){
//in the event that the detector history is empty,
//initialize variables to your desired 'default' values
//
//
}
else{
//if the detector history is not empty, you can access it via:
// JSON.parse(detector_output.history);
//...and initialize your variables to your desired values, based on
//this history
//
//
}

break;
default:
break;

}

}
Loading

0 comments on commit edc740e

Please sign in to comment.