def report_button_press(request):
    try:
        session = get_session(request)
        current_lightset = session.get_current_lightset()
        code = get_event_code_from_request(request)
        Event.objects.create(combination=current_lightset, eventtype=code)
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
    return Response('OK')
def report_begin_display(request):
    try:
        session = get_session(request)
        current_lightset = session.get_current_lightset()
        Event.objects.create(combination=current_lightset,
                             eventtype=Event.TYPE_COMBINATION_STARTED)
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)

    return Response('OK')
Beispiel #3
0
def report_training_finished(request):
    try:
        session = get_session(request)
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
    if not session.showtraining:
        return Response('Training session already done',
                        status=status.HTTP_400_BAD_REQUEST)

    session.showtraining = False
    session.save()

    return Response('OK')
def report_finish_display(request):
    try:
        session = get_session(request)
        current_lightset = session.get_current_lightset()
        Event.objects.create(combination=current_lightset,
                             eventtype=Event.TYPE_COMBINATION_FINISHED)
        current_lightset.finish()
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
    session.refresh_from_db()
    if session.status == STATUS_IN_PROGRESS:
        return Response('OK')
    else:
        return Response('FIN')
Beispiel #5
0
def get_experiment_settings(request):
    try:
        session = get_session(request)
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
    return Response({
        'sessionId': session.id,
        'audiomode': session.experiment.audiomode,
        'lightoffmode': session.experiment.lightoffmode,
        'lightofftimeout': session.experiment.lightofftimeout,
        'traininglength': session.experiment.traininglength,
        'instructions': session.experiment.instructions,
        'askUserData': False if session.userage else True,
        'runTrainingSession': session.showtraining,
    })
Beispiel #6
0
def pause_current_lightset(request):
    try:
        session = get_session(request)
        current_repeat = session.get_or_create_current_repeat()
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)

    current_lightset = current_repeat.combinations.filter(
        status=STATUS_IN_PROGRESS).first()

    if not current_lightset:
        return Response('No lightset to pause',
                        status=status.HTTP_400_BAD_REQUEST)

    current_lightset.delete()

    return Response('OK')
Beispiel #7
0
def get_lightset(request):
    try:
        session = get_session(request)
        current_repeat = session.get_or_create_current_repeat()
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
    if current_repeat.combinations.filter(
            status=STATUS_IN_PROGRESS).count() > 0:
        return Response('Another combination is in progress',
                        status=status.HTTP_400_BAD_REQUEST)
    lightsets = set([i for i in range(1, 1024)])
    used_lightsets = current_repeat.combinations.all()
    for l in used_lightsets:
        lightsets.discard(l.lightset)
    lightset = random.choice(list(lightsets))
    Combination.objects.create(repeat=current_repeat, lightset=lightset)
    return Response(lightset)
Beispiel #8
0
def report_user_data(request):
    try:
        session = get_session(request)
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
    if session.username:
        return Response('User data already registered',
                        status=status.HTTP_400_BAD_REQUEST)

    username = request.GET['username']
    userage = request.GET['userage']
    usersex = request.GET['usersex']

    if not (username and userage and usersex):
        return Response('Missing part of user data',
                        status=status.HTTP_400_BAD_REQUEST)

    session.username = username
    session.userage = userage
    session.usersex = usersex
    session.save()

    return Response('OK')