Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Boto upgrade #177

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions .dockerignore
@@ -0,0 +1,2 @@
expdj/experiment_repo
static/
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -26,3 +26,4 @@ compose/nginx/ssl*
*.cred

/expdj/experiment_repo/*
postgres-data/
3 changes: 2 additions & 1 deletion Dockerfile
Expand Up @@ -6,7 +6,8 @@ RUN apt-get update && apt-get install -y \
libhdf5-dev \
libgeos-dev \
openssl \
wget
wget\
git

RUN mkdir /code
WORKDIR /code
Expand Down
Expand Up @@ -8,7 +8,7 @@
btnCancelHtml: 'Cancel',
btnPreviousHtml: 'Previous',
btnNextHtml: 'Next',
btnLastStepHtml: 'Start Experiment',
btnLastStepHtml: 'Next',
disableNextButton: false,
completeCallback: function(){
$("#start_experiment_button").click();
Expand Down
4 changes: 2 additions & 2 deletions expdj/apps/experiments/views.py
Expand Up @@ -322,11 +322,11 @@ def get_battery_intro(battery, show_advertisement=True):
if battery.advertisement is not None:
instruction_forms.append(
{"title": "Advertisement", "html": battery.advertisement})
if battery.consent is not None:
instruction_forms.append({"title": "Consent", "html": battery.consent})
if battery.instructions is not None:
instruction_forms.append(
{"title": "Instructions", "html": battery.instructions})
if battery.consent is not None:
instruction_forms.append({"title": "Consent", "html": battery.consent})
return instruction_forms


Expand Down
39 changes: 36 additions & 3 deletions expdj/apps/turk/api_views.py
@@ -1,15 +1,48 @@
from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
from django.http.response import HttpResponseForbidden
from rest_framework import exceptions, generics, permissions, viewsets
from rest_framework import exceptions, generics, viewsets
from rest_framework.permissions import AllowAny
from rest_framework.views import APIView
from rest_framework.response import Response

from expdj.apps.experiments.models import Battery
from expdj.apps.turk.models import Result, Worker
from expdj.apps.turk.models import Assignment, Result, Worker, HIT
from expdj.apps.turk.serializers import ResultSerializer
from expdj.apps.turk.tasks import updated_assign_experiment_credit
from expdj.apps.turk.utils import get_worker_experiments, get_connection, get_credentials

class BatteryResultAPIList(generics.ListAPIView):
serializer_class = ResultSerializer

def get_queryset(self):
battery_id = self.kwargs.get('bid')
if (Battery.objects.get(pk=battery_id).owner is not self.request.user.pk):
if (Battery.objects.get(pk=battery_id).owner.id is not self.request.user.pk):
raise exceptions.PermissionDenied()
return Result.objects.filter(battery__id=battery_id)

class WorkerExperiments(APIView):
permission_classes = (AllowAny,)
def get(self, request, worker_id, hit_id):
try:
hit = HIT.objects.get(mturk_id=hit_id)
worker = Worker.objects.get(id=worker_id)
# assignment = Assignment.objects.get(hit__mturk_id=hit_id)
all_assignments = Assignment.objects.filter(worker_id=worker_id, hit__battery_id=hit.battery_id)
except ObjectDoesNotExist:
raise Http404
exps = list(get_worker_experiments(worker, hit.battery))
exps = [x.template.name for x in exps]
submit = False
status = 'Not Submitted'

marked_complete = all_assignments.filter(completed=True).count() > 0

if len(exps) == 0 and not marked_complete:
all_assignments.filter(completed=False).update(completed=True)
submit = True
updated_assign_experiment_credit.apply_async([worker_id, hit.battery_id, hit_id], countdown=60)
elif len(exps) == 0 and marked_complete:
status = 'Submit Attempted'

return Response({'experiments': exps, 'assignment_status': status, 'submit': submit})