Commit 7ca9b673 authored by au593919's avatar au593919
Browse files

project comleted

parent 02e7cd9d
var resetBox
var moleBox
var repetitions = 1 //number of repetitions
var results = [] //array including widths, distances and mts per trial
var standByTime = Math.random() * 2 + 0.7
var results = []
var standByTime
var inCalibrationPhase = true
var moleBoxHasBeenClicked = false
var roundCounter = 0
var points = 0
var meanTime
var clickWindowEnabled = false
var indexToGetCalibrationWidth = 0
var indexToGetCalibrationDistance = 0
var timerStart
......@@ -15,12 +17,70 @@ var mt = 0 //movement time
var width
var distance
var widths = [10, 30, 50]
var distances = [-200, 100, 500]
var distances = [-200, 300, -400]
var startedAtresetBox = true //trial starts at left box
var completedCombinations = [] //array including all combinations completed
var counter = -1
var numberOfConditions = 3 //number of total conditions
function calculateHitrate(points, numberOfRounds) {
return points / numberOfRounds * 100
}
function resetGameState() {
if (clickWindowEnabled) {
console.log("too late")
clickWindowEnabled = false
moleBoxHasBeenClicked = true
resetBox.classList.remove("disabledBox")
moleBox.classList.add("disabledBox")
initTarget(moleBox, resetBox)
displayMoleBox(false)
if (roundCounter > 10) {
quitExperiment()
}
}
}
function randomTimeGenerator() {
standByTime = Math.random() * 2 + 0.7
}
function generateVerticalMolePosition() {
let verticalPosition
verticalPosition = Math.random() * 660 + 0
if (verticalPosition > 317 && verticalPosition <= 384) {
return 317
} else if (verticalPosition > 384 && verticalPosition < 448) {
return 448
}
console.log(verticalPosition)
return verticalPosition
}
function generateHorizontalMolePosition() {
let horizontalPosition = 1
horizontalPosition *= Math.random() < 0.5 ? -1 : 1
horizontalPosition *= (Math.random() * 455 + 0)
if (horizontalPosition > -56 && horizontalPosition <= 0) {
return -56
} else if (horizontalPosition > 0 && horizontalPosition < 120) {
return 120
}
console.log(horizontalPosition)
return horizontalPosition
}
//get indices for calibration phase
function getFixedIndices() {
let indices = []
indices.push(indexToGetCalibrationWidth, indexToGetCalibrationDistance)
completedCombinations.push([indexToGetCalibrationWidth, indexToGetCalibrationDistance])
indexToGetCalibrationWidth += 1
indexToGetCalibrationDistance += 1
return indices
}
function displayMoleBox(state) {
if (!state) {
......@@ -32,15 +92,19 @@ function displayMoleBox(state) {
//your trials should be saved here.
function saveTrial(mt) {
let result = {
mt: mt
}
results.push(result)
results.push(mt)
}
//Arrow functions baby
function avgMt(resultsArray) {
return (resultsArray.reduce((a, b) => a + b, 0)) / resultsArray.length
}
function quitExperiment() {
moleBox.remove()
resetBox.remove()
document.getElementById("roundDisplay").innerHTML = "Final score: " + points
document.getElementById("pointsDisplay").innerHTML = "Hitrate: " + calculateHitrate(points, 10) + "%"
}
//check if condition is already completed. If so, true is returned, i.e. combination will not be tested again.
......@@ -54,49 +118,28 @@ function checkIfConditionAlreadyCompleted(currentCombination) {
}
/*get random indices from array to obtain random width and distance. If combination of width and distance already tested,
new indices are generated.
*/
function getIndices() {
let indexToGetWidth = 0
let indexToGetDistance = 0
let indices = []
indexToGetWidth = Math.floor((Math.random() * widths.length))
indexToGetDistance = Math.floor((Math.random() * distances.length))
completedCombinations.push([indexToGetWidth, indexToGetDistance])
indices.push(indexToGetWidth, indexToGetDistance)
return indices
}
//get indices for calibration phase
function getFixedIndices() {
let indices = []
indices.push(indexToGetCalibrationWidth, indexToGetCalibrationDistance)
completedCombinations.push([indexToGetCalibrationWidth, indexToGetCalibrationDistance])
indexToGetCalibrationWidth += 1
indexToGetCalibrationDistance += 1
return indices
}
//get width and distance and save in parameters array
function getParameters() {
let indices
if (inCalibrationPhase) {
indices = getFixedIndices()
} else if (!inCalibrationPhase) {
indices = getIndices()
}
let parameters = {
let parameters
let indices = getFixedIndices()
parameters = {
width: widths[indices[0]],
distance: distances[indices[1]]
}
return parameters
}
//sets the position of the target
function setTargetPosition(start, newTarget) {
newTarget.style.padding = width
newTarget.style.left = distance
if (inCalibrationPhase) {
newTarget.style.padding = width
newTarget.style.left = distance
} else if (!inCalibrationPhase) {
newTarget.style.top = generateVerticalMolePosition() + "px"
newTarget.style.left = generateHorizontalMolePosition() + "px"
newTarget.style.padding = widths[Math.floor((Math.random() * widths.length))]
}
start.style.width = width
}
......@@ -122,32 +165,46 @@ function calculateTrial() {
timerEnd = Date.now()
let mt = timerEnd - timerStart
if (inCalibrationPhase) {
console.log("time: " + mt)
saveTrial(mt)
}
else {
mt -= 2000
console.log("time: " + mt)
}
}
function onResetBoxClicked(event) {
if (!inCalibrationPhase) {
clickWindowEnabled = true
setTimeout("resetGameState()", meanTime + 300 + 2000)
roundCounter += 1
document.getElementById("roundDisplay").innerHTML = "Round #" + roundCounter
console.log("round number " + roundCounter)
setTimeout("displayMoleBox(true)", 2000)
} else {
displayMoleBox(true)
}
initTarget(resetBox, moleBox)
startButton.disabled = true
setTimeout("displayMoleBox(true)", standByTime * 1000)
resetBox.classList.add("disabledBox")
moleBox.classList.remove("disabledBox")
initTarget(resetBox, moleBox)
if (moleBoxHasBeenClicked) {
initCondition(resetBox, moleBox)
initTarget(resetBox, moleBox)
moleBoxHasBeenClicked = false
}
}
function onMoleBoxClicked(event) {
if (!inCalibrationPhase) {
clickWindowEnabled = false
points += 1
document.getElementById("pointsDisplay").innerHTML = "score: " + points
document.getElementById("pointsDisplay").innerHTML = "Score: " + points
console.log("score: " + points)
}
......@@ -163,9 +220,11 @@ function onMoleBoxClicked(event) {
inCalibrationPhase = false
startButton.disabled = false
resetBox.style.visibility = "hidden"
meanTime = avgMt(results)
console.log(meanTime)
}
if (!inCalibrationPhase && roundCounter == 60) {
if (!inCalibrationPhase && roundCounter == 10) {
quitExperiment()
}
}
......
......@@ -5,8 +5,10 @@
</head>
<body>
<h3 id="roundDisplay"></h3>
<h3 id="pointsDisplay"></h3>
<div class="display">
<h3 id="roundDisplay"></h3>
<h3 id="pointsDisplay"></h3>
</div>
<button id="start-button">Start calibration</button>
<div class="container">
<button class="start-box"></button>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment