Skip to content

Commit

Permalink
Extend power UI to N=1 trials
Browse files Browse the repository at this point in the history
refs #66
  • Loading branch information
davidmiller committed Jun 6, 2013
1 parent 723ac30 commit 95b926f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
20 changes: 12 additions & 8 deletions rm/static/js/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,31 @@ var RM = {
},

// Bind the power calculation form to an ajax call
init_power: function(){

init_power: function(options){
var n1trial = options.n1trial;
if(n1trial){
var varname = 'observations';
var target_input = '#id_ending_reports'
}else{
var varname = 'participants';
var target_input = '#id_min_participants';
}
$('form#power-form').ajaxForm({

beforeSubmit: function(){
if(!$('form#power-form').parsley().validate()){
return false
}
$('#power-btn').attr('disabled', true).text(
'calculating required participants...')
'calculating required ' + varname + '...')
},

success: function(data){
var msg = 'You need ' + data + ' participant';
if(parseInt(data) > 1){
msg += 's'
}
var msg = 'You need ' + data + ' ' + varname;
$('#power-btn').attr('disabled', false).text(
'run the numbers');
$('#power-answer').text(msg);
$('#id_min_participants').attr('value', data);
$(target_input).attr('value', data);
$('#power-done').text('done')
},

Expand Down
10 changes: 7 additions & 3 deletions rm/templates/trials/_trial_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ <h2>
<div id="power" class="modal hide fade" tabindex="-1"
role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<h3 id="myModalLabel">How many people do you need?</h3>
<h3 id="myModalLabel">
How many {% if n1trial %}observations{% else %}people{% endif %} do you need?
</h3>
</div>
<div class="modal-body">
<form method="POST" action="{% url 'power-calc' %}"
Expand All @@ -136,7 +138,9 @@ <h3 id="myModalLabel">How many people do you need?</h3>
run the numbers
</button>
</p>
<h3 id="power-answer">How many participants do you need?</h3>
<h3 id="power-answer">
How many {% if n1trial %}observations{% else %}participants{% endif %} do you need?
</h3>
</form>

</div>
Expand All @@ -154,7 +158,7 @@ <h3 id="power-answer">How many participants do you need?</h3>
RM.forms.init_instruction_toggles();
RM.forms.init_enter_sliding();
RM.forms.init_focus();
RM.forms.init_power();
RM.forms.init_power({n1trial: {% if n1trial%}true{% else %}false{% endif %}});
if(window.location.search.search(/step=(\d+)/) != -1){
var step = (parseInt(window.location.search.match(/step=(\d+)/)[1]) -1);
$('.carousel').carousel(step, true).carousel('pause');
Expand Down
13 changes: 3 additions & 10 deletions rm/templates/trials/steps/step_sizing.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,24 @@
<h2>3. <span class="red bold">SIZE</span> <span class="light">OF YOUR TRIAL</span></h2>
{% if n1trial %}

<h3>Would you like help to decide how many observations you'll need?</h3>
<p class="muted">
IMPLEMENT THIS PLEASE.
</p>
<h3>No, you think you've got it?</h3>
<h3>Number of observations</h3>
{{ form.ending_reports|bootstrap }}

<h3>Would you like help to decide how many observations you'll need?</h3>
{% else %}

<h3>Minimum number of participants</h3>
{{ form.min_participants|bootstrap }}
<p class="muted">
This is the minimum number of people you need in your trial
in order to obtain statistically significant results
</p>


<h3>Would you like help to decide how many people you will need in your trial? </h3>
{% endif %}

<a href="#power" class="btn btn-warning" data-toggle="modal" role="button">
help me decide
</a>


{% endif %}



Expand Down

0 comments on commit 95b926f

Please sign in to comment.