Skip to content

Instantly share code, notes, and snippets.

@anujku
Last active August 29, 2015 14:08
Show Gist options
  • Save anujku/e288aee868ac8a0674d8 to your computer and use it in GitHub Desktop.
Save anujku/e288aee868ac8a0674d8 to your computer and use it in GitHub Desktop.
Sticky eyetack run test
/*
For the demo, this function simply return a random URL to be displayed in the study.
For Affinnova, it is very important to maintain a link between the participant id and the chosen image URL. All
eye tracking data will be keyed on the combination of the study id and the participant id.
*/
function getRandomImage() {
var urls = [
"http://www.psychologytoday.com/files/u736/86random-f1.1.gif",
"http://www.random.org/analysis/randbitmap-rdo.png"
];
return urls[Math.floor(Math.random() * urls.length)];
}
/* Parameters describing the setup for displaying the study */
var studyId = "ST25ASFh75";
// this comes from whatever script generates a study using the API
var participantId = "abc_" + (new Date()).getTime().toString(36);
// this will be used to tie together the data from the Affinnova user session with
// the data from the eye tracking session
// Generate a valid study file object which will be passed to the study controller using the "forceStudyFile" parameter
var forceStudyFile = {
"playlist": [
{
"params": {
"forceUrl": getRandomImage(),
"contentId": "M25ASTOQx",
"length": 7,
"advanceOnClick": false
},
"type": "image"
},
{
"params": {
"contentId": "M25ASTOQx",
"forceUrl" : "",
"length": 3,
"advanceOnClick": false
},
"type": "image"
},
{
"params": {
"forceUrl": getRandomImage(),
"contentId": "M25ASTOQx",
"length": 7,
"advanceOnClick": false
},
"type": "image"
}
]
};
/* The runStudy function is used in this demo so that we can only trigger the beginning of the study when a user clicks the "Run Study" button. */
function runStudy() {
//document.getElementById('run').style.visibility = 'hidden';
// Trigger the study controller to begin
$eye("study", {
"recorderType" : "webcam:flash",
"participant": participantId, // will be the user id
"study": studyId,
"forceStudyFile": forceStudyFile
})
// The jQuery Deferred promise returned by the study controller can be used to handle success.
.done(function() {
alert("Study succeeded. Affinnova controls user from this point on.");
})
// And can also be used to handle failures.
.fail(function(failCode) {
alert("Study failed with code:" + failCode + ". Affinnova controls user from this point on.");
});
} // For demo purposes, we must force the user to run from a server rather than their local hard disk.
$(document).ready(function() {
$("#studyIdButton").click(function() {
createStudy();
});
});
<!DOCTYPE html>
<meta content="text/html;charset=utf8" httpequiv="ContentType">
<meta content="utf8" httpequiv="encoding">
<html>
<head>
<title>Study</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript"
src="https://s3.amazonaws.com/distribution.gridgazer.com/cloud/sticky/release.js"></script>
<script src="app.js"></script>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div id="run">
<button onclick="runStudy()">Run study</button>
</div>
</body>
</html>
button {
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 200px;
height: 50pt;
padding: 0.5em;
fontsize: 24pt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment