Using 2020.2
OS: Windows10
PsychoPy standalone through Pavlovia
I want to identify when individuals are looking at a video on screen. Every second, the code will identify if the predicted eye gaze (tracking square) is within the video stimulus. This results in an increase in offtask or ontask counts. I would like to provide feedback based on % of ontask every 2 minutes. Until I started using the for loop, I had good results.
However, I can’t figure out why I am getting 5 entries every second now. What am I missing? The last version of code that was working properly had no loop and without resetting the ontask and offtask at the end of intervals is:
window.webgazer.removeMouseEventListeners();
ontask = 0;
offtask = 0;
if (psychoJS.experiment.experimentEnded ==false || psychoJS.eventManager.getKeys({keyList:['escape']}).length < 1)
{
setInterval(function()
{
if (movie.contains(tracking_square) == true)
{
if (webgazer.checkEyesInValidationBox() === true)
{
// console.log("Prediction from tracking_square" + util.to_norm(
// tracking_square, 'height', psychoJS.window)));
//add parameters later
++ontask;
console.log('eyes detected' + " " + 'offtask:' + offtask + ", ontask:" + ontask);
psychoJS.experiment.addData('ontask', 1);
psychoJS.experiment.addData('offtask', 0);
psychoJS.experiment.nextEntry();
// Get position of object for data sheet
// getPositionFromObject(, _mouseXYs[0]);
}
else
{
++offtask;
console.log('eyes NOT detected' + " " + 'offtask:' + offtask + ", ontask:" + ontask);
psychoJS.experiment.addData('ontask', 0);
psychoJS.experiment.addData('offtask', 1);
psychoJS.experiment.nextEntry();
}
}
else
{
++offtask;
console.log('offtask:' + offtask + ", ontask:" + ontask);
psychoJS.experiment.addData('ontask', 0);
psychoJS.experiment.addData('offtask', 1);
psychoJS.experiment.nextEntry();
}
}, 1000);
}
else
{psychoJS.experiment.experimentEnded ==false;
console.log("experiment ended.");
Scheduler.Event.NEXT;}
When I add in the for loop and try to reset the ontask and offtask variables, I get 5 entries of offtask or ontask each time there is an increase and no instances of “eyes not detected.”
var headtowardscreen = 0;
var ontask = 0;
var offtask = 0;
//if (psychoJS.experiment.experimentEnded ==false || psychoJS.eventManager.getKeys({keyList:['escape']}).length < 1)
// {
// Intervals last 20 seconds. Once six 20 second intervals have passed, end loop)
for (var interval = 1; (ontask + offtask < 20) && (interval < 6); interval++)
{
//Check for offtask or ontask every second
setInterval(function()
{
//While eyes looking within video stimulus (tracking square is within video stimulus) and eyes are identified, increase ontask by 1
if (movie.contains(tracking_square) == true)
{
if (webgazer.checkEyesInValidationBox() === true)
{
++ontask;
console.log('eyes detected' + " " + 'offtask:' + offtask + ", ontask:" + ontask);
psychoJS.experiment.addData('interval', interval);
psychoJS.experiment.addData('ontask', 1);
psychoJS.experiment.addData('offtask', 0);
psychoJS.experiment.addData('head toward screen', 1);
psychoJS.experiment.nextEntry();
}
//If eyes cannot be detected, ignore location of tracking square, and increase offtask by 1)
else
{
++offtask;
console.log('eyes NOT detected' + " " + 'offtask:' + offtask + ", ontask:" + ontask);
psychoJS.experiment.addData('interval', interval);
psychoJS.experiment.addData('ontask', 0);
psychoJS.experiment.addData('offtask', 1);
psychoJS.experiment.addData('head AWAY from screen', 1);
psychoJS.experiment.nextEntry();
}
}
//If eyes are detected but tracking square is not in video stimulus, increase offtask by 1)
else
{
++offtask;
console.log('eyes detected' + ' ' + 'offtask:' + offtask + ", ontask:" + ontask);
psychoJS.experiment.addData('interval', interval);
psychoJS.experiment.addData('ontask', 0);
psychoJS.experiment.addData('offtask', 1);
psychoJS.experiment.addData('head toward screen', 1);
psychoJS.experiment.nextEntry();
}
}, 1000);
//Reset offtask and ontask counts to 0, and increase interval by 1
offtask = 0;
ontask = 0;
}
//else
// {
// psychoJS.experiment.experimentEnded ==false;
// console.log("experiment ended.");
// Scheduler.Event.NEXT;
// }
Any ideas? Any input would be greatly helpful.