From 3ce8aea22025b719570b9443076b025970911e45 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Fri, 9 Apr 2021 10:52:09 -0400 Subject: [PATCH] improve timing in webgazer and utilize in jspsych --- examples/js/webgazer.js | 8 +++++--- extensions/jspsych-ext-webgazer.js | 6 ++++-- plugins/jspsych-webgazer-validate.js | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/js/webgazer.js b/examples/js/webgazer.js index 8a326b49..237ad22b 100644 --- a/examples/js/webgazer.js +++ b/examples/js/webgazer.js @@ -87839,7 +87839,6 @@ var defaults = { 'settings': {} }; - //PRIVATE FUNCTIONS /** @@ -87994,6 +87993,7 @@ async function getPrediction(regModelIndex) { if(paused){ paintCurrentFrame(videoElementCanvas, videoElementCanvas.width, videoElementCanvas.height); } + var time = performance.now(); var predictions = []; // [20200617 xk] TODO: this call should be made async somehow. will take some work. @@ -88010,14 +88010,16 @@ async function getPrediction(regModelIndex) { return predictions[regModelIndex] === null ? null : { 'x' : predictions[regModelIndex].x, 'y' : predictions[regModelIndex].y, - 'eyeFeatures': latestEyeFeatures + 'eyeFeatures': latestEyeFeatures, + 't' : time }; } else { return predictions.length === 0 || predictions[0] === null ? null : { 'x' : predictions[0].x, 'y' : predictions[0].y, 'eyeFeatures': latestEyeFeatures, - 'all' : predictions + 'all' : predictions, + 't' : time }; } } diff --git a/extensions/jspsych-ext-webgazer.js b/extensions/jspsych-ext-webgazer.js index bc4c6683..196a552f 100644 --- a/extensions/jspsych-ext-webgazer.js +++ b/extensions/jspsych-ext-webgazer.js @@ -226,10 +226,12 @@ jsPsych.extensions['webgazer'] = (function () { if (gazeData !== null){ var d = { x: state.round_predictions ? Math.round(gazeData.x) : gazeData.x, - y: state.round_predictions ? Math.round(gazeData.y) : gazeData.y + y: state.round_predictions ? Math.round(gazeData.y) : gazeData.y, + t: gazeData.t } if(state.activeTrial) { - d.t = Math.round(performance.now() - state.currentTrialStart) + console.log(`handleUpdate: t = ${Math.round(gazeData.t)}, now = ${Math.round(performance.now())}`); + d.t = Math.round(gazeData.t - state.currentTrialStart) state.currentTrialData.push(d); // add data to current trial's data } state.currentGaze = d; diff --git a/plugins/jspsych-webgazer-validate.js b/plugins/jspsych-webgazer-validate.js index d0e7ca5d..d9e58526 100644 --- a/plugins/jspsych-webgazer-validate.js +++ b/plugins/jspsych-webgazer-validate.js @@ -110,7 +110,7 @@ var cancelGazeUpdate = jsPsych.extensions['webgazer'].onGazeUpdate(function(prediction){ if(performance.now() > pt_start_val){ - pt_data.push({x: prediction.x, y: prediction.y, dx: prediction.x - x, dy: prediction.y - y, t: Math.round(performance.now()-start)}); + pt_data.push({x: prediction.x, y: prediction.y, dx: prediction.x - x, dy: prediction.y - y, t: Math.round(prediction.t-start)}); } });