From 9826616a57ac97539ce7017c727ec08da2e2381f Mon Sep 17 00:00:00 2001 From: Ken Holstein Date: Sun, 18 Jun 2017 23:31:12 -0400 Subject: [PATCH] added student_doing_well__moving_average --- ... => student_doing_well__moving_average.js} | 30 ++++++++++--------- HTML/Assets/transaction_mailer_users.js | 7 ++++- 2 files changed, 22 insertions(+), 15 deletions(-) rename HTML/Assets/Detectors/Lumilo/{student_doing_well.js => student_doing_well__moving_average.js} (83%) diff --git a/HTML/Assets/Detectors/Lumilo/student_doing_well.js b/HTML/Assets/Detectors/Lumilo/student_doing_well__moving_average.js similarity index 83% rename from HTML/Assets/Detectors/Lumilo/student_doing_well.js rename to HTML/Assets/Detectors/Lumilo/student_doing_well__moving_average.js index c3d69f2..b0150b4 100644 --- a/HTML/Assets/Detectors/Lumilo/student_doing_well.js +++ b/HTML/Assets/Detectors/Lumilo/student_doing_well__moving_average.js @@ -17,6 +17,11 @@ var mailer; //initialize any custom global variables for this detector here var prevStep = "" +var attemptCorrect; +var windowSize = 7; +var threshold = 6; +var attemptWindow = Array.apply(null, Array(windowSize)).map(Number.prototype.valueOf,0); + function receive_transaction( e ){ //e is the data of the transaction from mailer from transaction assembler @@ -37,15 +42,11 @@ function receive_transaction( e ){ detector_output.step_id = e.data.tutor_data.step_id; //custom processing (insert code here) - // - // - // - // - // - var booleanValues = [0, 1]; - detector_output.value = String(booleanValues[Math.floor(Math.random() * booleanValues.length)]) ; - - + attemptCorrect = (e.data.tutor_data.action_evaluation.toLowerCase() == "correct") ? 1 : 0; + attemptWindow.shift(); + attemptWindow.push(attemptCorrect); + var sumCorrect = attemptWindow.reduce(function(pv, cv) { return pv + cv; }, 0); + console.log(attemptWindow); } //set conditions under which detector should update @@ -55,11 +56,12 @@ function receive_transaction( e ){ detector_output.transaction_id = e.data.transaction_id; //custom processing (insert code here) - // - // - // - // - // + if (sumCorrect >= threshold){ + detector_output.value = "1"; + } + else{ + detector_output.value = "0"; + } mailer.postMessage(detector_output); postMessage(detector_output); diff --git a/HTML/Assets/transaction_mailer_users.js b/HTML/Assets/transaction_mailer_users.js index 9f59811..a95c489 100644 --- a/HTML/Assets/transaction_mailer_users.js +++ b/HTML/Assets/transaction_mailer_users.js @@ -6,7 +6,12 @@ TransactionMailerUsers = mailerURL: "mail-worker.js", mailer: null, mailerPort: null, - scripts: ["Detectors/Lumilo/idle.js", "Detectors/Lumilo/system_misuse.js", "Detectors/Lumilo/struggle.js", "Detectors/Lumilo/student_doing_well.js", "Detectors/Lumilo/critical_struggle.js", "Detectors/Lumilo/invisible_hand_raise.js"], + scripts: ["Detectors/Lumilo/idle.js", + "Detectors/Lumilo/system_misuse.js", + "Detectors/Lumilo/struggle.js", + "Detectors/Lumilo/student_doing_well__moving_average.js", + "Detectors/Lumilo/critical_struggle.js", + "Detectors/Lumilo/invisible_hand_raise.js"], active: [] };