Skip to content

Commit

Permalink
more work on rapidScan experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Mar 25, 2013
1 parent 506a5b4 commit dab6f72
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 150 deletions.
96 changes: 76 additions & 20 deletions app/assets/javascripts/angular/controllers/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
$scope.resultsSending = false;
$scope.resultsSentSuccessfully = undefined;

// todo: populate user information

// download experiment protocol
var experiment = $routeParams.experiment == "tour" ? '/experiment_assets/bird_tour.json' : '/experiment_assets/rapid_scan.json';
Expand All @@ -49,7 +48,7 @@

if ($routeParams.cheat) {
$scope.stage = $routeParams.cheat;
if ($scope.stage = $scope.EXPERIMENT_STAGE) {
if ($scope.stage == $scope.EXPERIMENT_STAGE) {
$scope.step = 1;
}
}
Expand Down Expand Up @@ -78,9 +77,9 @@
$scope.errors.push("You must consent to participate in this experiment.");
}

if ($scope.results.ethicsStatementViewed !== true) {
$scope.errors.push("You must view the ethics statement before continuing (click on the link please).")
}
// if ($scope.results.ethicsStatementViewed !== true) {
// $scope.errors.push("You must view the ethics statement before continuing (click on the link please).")
// }

if ($scope.loggedIn && $scope.userData) {
$scope.results.userData = angular.copy($scope.userData);
Expand Down Expand Up @@ -126,6 +125,8 @@
// send back results to server
$scope.resultsSending = true;
$scope.resultsSentSuccessfully = undefined;


$http.post('/experiments', $scope.results)
.success(function (data, status, headers, config) {

Expand Down Expand Up @@ -159,6 +160,40 @@

$scope.bigScope.results.steps = angular.copy($scope.bigScope.spec.experimentSteps);

// randomise data sets and speeds
angular.forEach($scope.bigScope.results.steps, function(value, index){
// pick a speed to use on this dataset
if (value.speed == "random") {
// randomise list
baw.shuffle($scope.bigScope.spec.speeds);

value.speed = $scope.bigScope.spec.speeds.pop();
value._random = "true";
}

});

// make sure datasets appear in decreasing exposure order
$scope.bigScope.results.steps.sort(function compare(a, b) {
if (a.speed === b.speed) {
return 0;
}
else if (a.speed >= b.speed) {
return -1;
}
else {
return 1;
}
});

// print order for sanity
var prettyString = "Experimental step order";
angular.forEach($scope.bigScope.results.steps, function(value, index) {
prettyString += String.format("\nIndex: {0}, Speed: {1}, Title: {2}", index, value.speed, value.name);
});
console.warn(prettyString);


$scope.stepResults = undefined;
var EXPERIMENT_STEPS = $scope.bigScope.results.steps.length;
$scope.$watch(function () {
Expand All @@ -169,10 +204,11 @@
$scope.showInstructions = true;

$scope.stepResults = $scope.bigScope.results.steps[$scope.bigScope.step - 1];
$scope.stepResults.hits = [];
$scope.stepResults.pauses = [];

$scope.flashes = calculateFlashes();
$scope.stepResults.flashes = calculateFlashes();
//$scope.stepResults.flashes.hits = [];
//$scope.stepResults.flashes.pauses = [];

}
});

Expand All @@ -182,7 +218,7 @@
$scope.showInstructions = false;
$scope.stepResults.preCountDownStartTimeStamp = ts();

$scope.flashes[0].show = true;
$scope.stepResults.flashes[0].show = true;
$scope.currentFlash = 0;

$scope.countDown = 5;
Expand All @@ -199,7 +235,7 @@
$scope.$apply(function () {
$scope.countDown = $scope.countDown - 1;

if ($scope.countDown == 0){
if ($scope.countDown == 0) {

// eventually start it!
$scope.stepResults.startTimeStamp = ts();
Expand Down Expand Up @@ -227,7 +263,7 @@

var diff = ($scope.stepResults.speed * 1000) - ($scope.pauseTick - $scope.lastTick);
$scope.pauseTick = 0;
$scope.stepResults.pauses.push({state: "resumed", card: $scope.currentFlash, timeStamp: ts()});
$scope.stepResults.flashes[$scope.currentFlash].pauses.push({state: "resumed", timeStamp: ts()});
// var tempTimer = $timeout(function () {
$scope.tick(diff);
//$timeout.cancel(tempTimer);
Expand All @@ -236,7 +272,7 @@
window.clearTimeout($scope.timeoutId);
$scope.paused = true;
$scope.pauseTick = Date.now();
$scope.stepResults.pauses.push({state: "paused", card: $scope.currentFlash, timeStamp: ts()});
$scope.stepResults.flashes[$scope.currentFlash].pauses.push({state: "paused", timeStamp: ts()});
}


Expand Down Expand Up @@ -267,21 +303,21 @@
return;
}

$scope.flashes[$scope.currentFlash].show = false;
$scope.stepResults.flashes[$scope.currentFlash].show = false;
$scope.currentFlash++;

$scope.focus();


if ($scope.currentFlash >= $scope.flashes.length) {
if ($scope.currentFlash >= $scope.stepResults.flashes.length) {
$scope.stepResults.endFlashesTimeStamp = (new Date()).toISOString();
$scope.showDoneButton = true;
return;
}

$scope.lastTick = Date.now();

$scope.flashes[$scope.currentFlash].show = true;
$scope.stepResults.flashes[$scope.currentFlash].show = true;

$scope.tick();
});
Expand Down Expand Up @@ -311,15 +347,16 @@
break;
}

if (positiveHit == undefined || $scope.currentFlash >= $scope.flashes.length) {
if (positiveHit == undefined || $scope.currentFlash >= $scope.stepResults.flashes.length) {
console.warn("ignored hit");
return;
}
var result = positiveHit ? "positive" : "negative";
console.log("HIT!", $event, result);

$scope.flashes[$scope.currentFlash].detected = result;
$scope.stepResults.hits.push({hit: result, card: $scope.currentFlash, timeStamp: ts()});
var f = $scope.stepResults.flashes[$scope.currentFlash];
f.detected = result;
f.hits.push({hit: result, timeStamp: ts()});
};


Expand All @@ -332,7 +369,7 @@

$scope.SPECTROGRAM_WIDTH = 1080;
var PPS = 45;
$scope.flashes = [];
//$scope.stepResults.flashes = [];

function calculateFlashes() {

Expand All @@ -353,10 +390,29 @@

var imageUrl = String.format(BASE_URL, segment.audioId, start * 1000, end * 1000);

segments.push({start: start, end: end, imageLink: imageUrl, show: false, detected: null});
segments.push({
start: start,
end: end,
imageLink: imageUrl,
show: false,
detected: null,
hits: [],
pauses: []
}
);
}
}

if ($scope.stepResults.randomiseOrder) {
baw.shuffle(segments);
}

// give flash cards index, so we always know order
// has to happen after shuffle
for (var counter = 0; counter < segments.length; counter++) {
segments[counter].index = counter;
}

return segments;
}
}]);
Expand Down
76 changes: 54 additions & 22 deletions app/assets/templates/experiment_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,35 @@
}

.progress {
position: relative;
float: right;
top: 0;
right: 0;
margin-top: -35px;
text-align: center;
}

#experimentConclusion textarea {
width: 800px;
height: 400px;
}

#content h2 {
margin-top: -14px;
}

.survey {
text-align: center;
font-size: x-large;
line-height: 150%;
width: -webkit-calc(800px - 2em);
padding: 1em;

border: 1px solid rgb(123, 144, 60);
border-radius: 5px;
background-color: rgb(212, 222, 184);
}

.survey a {
font-size: xx-large;
}


</style>

Expand All @@ -58,25 +76,30 @@ <h2>{{spec.experiment}} » {{stage}}</h2>

<h3>Instructions</h3>
<ul>
<li ng-repeat="step in spec.instructions">{{step}}</li>
<li ng-repeat="step in spec.instructions" ng-bind-html-unsafe="step"></li>
<li>Please do not leave this page, or close your browser during the experiment, your progress will be lost</li>
<li>
Ensure you have read the experiment <a href="" ng-click="popupEthics()" style="">ethics statement</a>. You will need to click the link.
<br/>
<label title="This checkbox will automatically check when the ethics statement has been read">
<input type="checkbox" ng-checked="results.ethicsStatementViewed" disabled/>
I have read the <a href="" ng-click="popupEthics()" style="">ethics statement</a>
</label>
<br/>
<label>
<input type="checkbox" ng-model="results.consented"/>
I consent to participating in this experiment and I understand I can leave at any time without penalty
</label>
<br/>
<label>
<input type="checkbox" ng-model="results.allowContact"/>
I consent to be contacted (via email) for follow up questions if it is required
</label>
Ensure you have read the experiment <a href="" ng-click="popupEthics()" style="">ethics statement</a>. <!-- You will need to click the link.-->
<ul>
<li>
<!--<label title="This checkbox will automatically check when the ethics statement has been read">-->
<!--<input type="checkbox" ng-checked="results.ethicsStatementViewed" disabled/>-->
I have read the <a href="" ng-click="popupEthics()" style="">ethics statement</a>
<!--</label>-->
</li>
<li>
<label>
<input type="checkbox" ng-model="results.consented"/>
I consent to participating in this experiment and I understand I can leave at any time without penalty
</label>
</li>
<li>
<label>
<input type="checkbox" ng-model="results.allowContact"/>
I consent to be contacted (via email) for follow up questions if it is required
</label>
</li>
</ul>
</li>
<li>
You need to be signed in to participate in this experiment. Registration is very easy.
Expand Down Expand Up @@ -109,6 +132,15 @@ <h3>Instructions</h3>
<div id="experimentConclusion" ng-show="stage == FINAL_STAGE">
<p>Thank you very much for participating.</p>


<p ng-show="spec.surveyLink" class="survey">
The experiment is over. However we would <em>really</em> appreciate it if you could complete this short survey.
<br/>
<a ng-href="{{spec.surveyLink}}" target="_blank">Click to go to the survey</a>
<br/>
Thanks so much!
</p>

<p class="isa_info" ng-show="resultsSending">Your results are being saved at the moment. <em>Please do not close the window or navigate away!</em>
<br/>
<progress></progress>
Expand All @@ -123,7 +155,7 @@ <h3>Instructions</h3>
<br/>
Copy this data:
<label>
<textarea readonly> {{prettyResults()}} </textarea>
<textarea readonly>{{prettyResults()}}</textarea>
</label>

<p>
Expand Down
Loading

0 comments on commit dab6f72

Please sign in to comment.