improve timing in webgazer and utilize in jspsych

This commit is contained in:
Josh de Leeuw 2021-04-09 10:52:09 -04:00
parent 346726ec44
commit 3ce8aea220
3 changed files with 10 additions and 6 deletions

View File

@ -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
};
}
}

View File

@ -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;

View File

@ -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)});
}
});