Skip to content

Commit

Permalink
Merge pull request #162 from rwblair/testing
Browse files Browse the repository at this point in the history
Fixes for #56 #154 #156 #158
  • Loading branch information
rwblair authored Jul 15, 2016
2 parents da3e94f + b801bb9 commit 67c617f
Show file tree
Hide file tree
Showing 17 changed files with 554 additions and 143 deletions.
4 changes: 2 additions & 2 deletions expdj/apps/experiments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def __init__(self, *args, **kwargs):
class BatteryForm(ModelForm):

class Meta:
exclude = ('owner','contributors','experiments','bonus_active'
'blacklist_active','blacklist_threshold')
exclude = ('owner', 'contributors', 'experiments',' bonus_active'
'blacklist_active', 'blacklist_threshold')
model = Battery

def clean(self):
Expand Down
62 changes: 44 additions & 18 deletions expdj/apps/experiments/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import collections
import operator

from guardian.shortcuts import assign_perm, get_users_with_perms, remove_perm
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db.models.signals import m2m_changed
from jsonfield import JSONField
from polymorphic.models import PolymorphicModel
from django.core.urlresolvers import reverse

from django.contrib.auth.models import User
from django.db.models import Q, DO_NOTHING
from jsonfield import JSONField
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
import collections
import operator
from django.db.models import Q, DO_NOTHING
from django.db.models.signals import m2m_changed

# trying to import Result object directly from models was giving an import
# error here, even though the import matched views.py exactly.
from expdj.apps import turk

class CognitiveAtlasConcept(models.Model):
name = models.CharField(max_length=1000, null=False, blank=False)
Expand Down Expand Up @@ -133,6 +140,12 @@ def __str__(self):

class Battery(models.Model):
'''A battery is a collection of experiment templates'''

ORDER_CHOICES = (
("random", "random"),
("specified", "specified"),
)

# Name must be unique because anonymous link is generated from hash
name = models.CharField(max_length=200, unique = True, null=False, verbose_name="Name of battery")
description = models.TextField(blank=True, null=True)
Expand All @@ -150,19 +163,32 @@ class Battery(models.Model):
active = models.BooleanField(choices=((False, 'Inactive'),
(True, 'Active')),
default=True,verbose_name="Active")
ORDER_CHOICES = (
("random", "random"),
("specified", "specified"),
)

presentation_order = models.CharField("order function for presentation of experiments",max_length=200,choices=ORDER_CHOICES,default="random",help_text="Select experiments randomly, or in a custom specified order.")
blacklist_active = models.BooleanField(choices=((False, 'Off'),
(True, 'On')),
default=False,verbose_name="Blacklist based on rejection criteria")
blacklist_active = models.BooleanField(
choices=((False, 'Off'), (True, 'On')),
default=False,
verbose_name="Blacklist based on rejection criteria"
)
blacklist_threshold = models.PositiveIntegerField(null=True,blank=True,default=10,help_text="Number of experiments to fail reject condition to add participant to blacklist",validators = [MinValueValidator(0.0)])
bonus_active = models.BooleanField(choices=((False, 'Off'),
(True, 'On')),
default=False,verbose_name="Bonus based on reward criteria")
bonus_active = models.BooleanField(
choices=((False, 'Off'), (True, 'On')),
default=False,
verbose_name="Bonus based on reward criteria"
)
required_batteries = models.ManyToManyField(
"Battery",
blank=True,
related_name='required_batteries_mtm',
help_text=("Batteries which must be completed for this battery to be "
"attempted")
)
restricted_batteries = models.ManyToManyField(
"Battery",
blank=True,
related_name='restricted_batteries_mtm',
help_text=("Batteries that must not be completed in order for "
"this battery to be attempted")
)

def get_absolute_url(self):
return_cid = self.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2>{{ change_type }} Experiment <i style="font-size:12" data-toggle="tooltip" t
var selected_experiment = $("#experiment").find(":selected").val();
var experiment = allexperimentsjson[selected_experiment]
var selected_variable = parseInt($("#variable_selection").find(":selected").val());
if (selected_variable == experiment.performance_variable.id){
if (experiment.performance_variable != null && selected_variable == experiment.performance_variable.id) {
var selection = experiment.performance_variable
var color = "green"
var uid = selection.id
Expand Down
18 changes: 13 additions & 5 deletions expdj/apps/experiments/templates/experiments/battery_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,32 @@ <h4>Amazon Mechanical Turk HITS</h4>
<table class="table table-condensed table-striped table-hover" id="hits_table">
<thead>
<th>title</th>
<th>creation time</th>
<th>keywords</th>
<th>description</th>
<th>reward</th>
<th><i data-toggle="tooltip" title="EXPIRING a HIT means it will no longer appear on the Mechanical Turk web site, and no new Workers will be allowed to accept the HIT. The record will remain here. DELETING a hit means expiring it and removing the link to it from the Experiment Factory." style="padding-left:10px;padding-top:5px" class="fa fa-2x fa-question-circle"></i>
<th> <i data-toggle="tooltip" title="EXPIRING a HIT means it will no longer appear on the Mechanical Turk web site, and no new Workers will be allowed to accept the HIT. The record will remain here. DELETING a hit means expiring it and removing the link to it from the Experiment Factory." style="padding-left:10px;padding-top:5px" class="fa fa-2x fa-question-circle"></i>
</th>
</thead>
<tbody>
{% for hit in hits %}
<tr id="hit_info_{{ hit.id }}">
<td>
{% if hit.sandbox = True %}
<tr><td><a href="https://requestersandbox.mturk.com/mturk/manageHIT?viewableEditPane=manageHIT_downloadResults&HITId={{ hit.mturk_id }}" target="_blank">{{ hit.title }}</a></td>
<a href="https://requestersandbox.mturk.com/mturk/manageHIT?viewableEditPane=manageHIT_downloadResults&HITId={{ hit.mturk_id }}" target="_blank">{{ hit.title }}</a>
{% else %}
<tr><td><a href="https://requester.mturk.com/mturk/manageHIT?viewableEditPane=manageHIT_downloadResults&HITId={{ hit.mturk_id }}" target="_blank">{{ hit.title }}</a></td>
<a href="https://requester.mturk.com/mturk/manageHIT?viewableEditPane=manageHIT_downloadResults&HITId={{ hit.mturk_id }}" target="_blank">{{ hit.title }}</a>
{% endif %}
(<a href={% url 'hit_detail' hit.id %}>Details</a>)
</td>
<td>{{ hit.creation_time|date:"m/d/y G:H" }}</td>
<td>{{ hit.keywords }}</td>
<td>{{ hit.description }}</td>
<td>{{ hit.reward }}</td>
<td>
{% if edit_permission %}
<a class='btn btn-xs btn-default' href='{% url 'manage_hit' battery.id hit.id %}'> Manage Hit</a>
<a class='btn btn-xs btn-default' href='{% url 'clone_hit' battery.id hit.id %}'> Clone Hit</a>
<a class='btn btn-xs btn-default' href='{% url 'expire_hit' hit.id %}' id="expire_hit"> Expire Hit</a>
{% if hit.status = "D" %}
<button class='btn btn-xs btn-danger' href='{% url 'delete_hit' hit.id %}' id="delete_hit"> Delete Hit</button>
Expand All @@ -185,7 +192,7 @@ <h4>Amazon Mechanical Turk HITS</h4>
{% endif %}
</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
{% else %}
Expand Down Expand Up @@ -261,7 +268,8 @@ <h4 class="modal-title">Email Authenticated Battery Link</h4>
]
});
$('#hits_table').dataTable({
responsive: true
responsive: true,
"order": [[ 1, "desc" ]]
});
$('#delete_experiment').click(function(e) {
return confirm("This will remove the experiment from the battery, and not delete it from the application. Are you sure you want to do this?");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% extends "main/base.html" %}
{% load static %}
{% load crispy_forms_tags %}
{% block head %}
<link rel="stylesheet" href="{% static "css/select2.min.css" %}" />
{% endblock %}
{% block content %}

Expand All @@ -22,3 +24,10 @@ <h2>{{ header_text }}</h2>
</div>
</div>
{% endblock %}
{% block scripts %}
<script src="{% static "js/select2.min.js"%}" type="text/javascript"></script>
<script>
$("#id_required_batteries").select2();
$("#id_restricted_batteries").select2();
</script>
{% endblock %}
33 changes: 19 additions & 14 deletions expdj/apps/experiments/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from expdj.apps.experiments.views import experiments_view, edit_experiment_template, \
delete_experiment_template, add_experiment_template, save_experiment_template, \
view_experiment, preview_experiment, batteries_view, add_battery, \
edit_battery, view_battery, delete_battery, remove_experiment, \
add_experiment, edit_experiment, save_experiment, update_experiment_template, \
remove_condition, preview_battery, serve_battery, serve_battery_anon, \
generate_battery_user, sync, experiment_results_dashboard, \
battery_results_dashboard, dummy_battery ,modify_experiment, intro_battery, \
save_survey_template, add_survey_template, add_game_template, save_game_template, \
enable_cookie_view, change_experiment_order, serve_battery_gmail, subject_management
from expdj import settings
from django.views.generic.base import TemplateView
from django.conf.urls import patterns, url
from django.views.generic.base import TemplateView

from expdj import settings
from expdj.apps.experiments.views import (
experiments_view, edit_experiment_template, delete_experiment_template,
add_experiment_template, save_experiment_template, view_experiment,
preview_experiment, batteries_view, add_battery, edit_battery,
view_battery, delete_battery, remove_experiment, add_experiment,
edit_experiment, save_experiment, update_experiment_template,
remove_condition, preview_battery, serve_battery, serve_battery_anon,
generate_battery_user, sync, experiment_results_dashboard,
battery_results_dashboard, dummy_battery ,modify_experiment, intro_battery,
save_survey_template, add_survey_template, add_game_template,
save_game_template, enable_cookie_view, change_experiment_order,
serve_battery_gmail, subject_management
)

urlpatterns = patterns('',

Expand Down Expand Up @@ -66,11 +70,12 @@
url(r'^batteries/(?P<bid>\d+|[A-Z]{8})/serve/gmail$',serve_battery_gmail,name='serve_battery_gmail'),
url(r'^local/(?P<rid>\d+|[A-Z]{8})/$',sync,name='local'),
url(r'^local/$',sync,name='local'), # local sync of data
url(r'^cookie/$',enable_cookie_view,name='enable_cookie_view'))
url(r'^cookie/$',enable_cookie_view,name='enable_cookie_view')
)

if settings.DEBUG:
urlpatterns += patterns('',
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
)
Loading

0 comments on commit 67c617f

Please sign in to comment.