add round_predictions parameter

This commit is contained in:
Josh de Leeuw 2021-02-05 13:31:04 -05:00
parent d584faa71d
commit 7c7fda1959
2 changed files with 15 additions and 4 deletions

View File

@ -16,7 +16,8 @@ jsPsych.init({
Parameter | Type | Default Value | Description
----------|------|---------------|------------
webgazer | object | `undefined` | You can explicitly pass a reference to a loaded instance of the webgazer.js library. If no explicit reference is passed then the extension will look for a global `webgazer` object.
webgazer | object | `undefined` | You can explicitly pass a reference to a loaded instance of the webgazer.js library. If no explicit reference is passed then the extension will look for a global `webgazer` object. If you are loading webgazer.js via a `<script>` tag you do not need to set this parameter in most circumstances.
round_predictions | bool | true | Whether to round the `x`,`y` coordinates predicted by WebGazer to the nearest whole number. This *greatly* reduces the size of the data, as WebGazer records data to 15 decimal places by default. Given the noise of the system, there's really no need to record data to this level of precision.
## Data Generated

View File

@ -22,6 +22,12 @@ jsPsych.extensions['webgazer'] = (function () {
state.webgazer = params.webgazer;
}
if (typeof params.round_predictions === 'undefined'){
state.round_predictions = true;
} else {
state.round_predictions = params.round_predictions;
}
// sets up event handler for webgazer data
state.webgazer.setGazeListener(handleGazeDataUpdate);
@ -129,6 +135,10 @@ jsPsych.extensions['webgazer'] = (function () {
extension.getCurrentPrediction = async function () {
var prediction = await state.webgazer.getCurrentPrediction();
if(state.round_predictions){
prediction.x = Math.round(prediction.x);
prediction.y = Math.round(prediction.y);
}
return prediction;
}
@ -139,9 +149,9 @@ jsPsych.extensions['webgazer'] = (function () {
function handleGazeDataUpdate(gazeData, elapsedTime) {
if (gazeData !== null && state.activeTrial) {
var d = {
x: gazeData.x,
y: gazeData.y,
t: performance.now() - state.currentTrialStart
x: state.round_predictions ? Math.round(gazeData.x) : gazeData.x,
y: state.round_predictions ? Math.round(gazeData.y) : gazeData.y,
t: Math.round(performance.now() - state.currentTrialStart)
}
state.currentTrialData.push(d); // add data to current trial's data
}