Ejemplo n.º 1
0
def player_questions(name):
    ''' get a relevant question
    '''

    '''
    players = Player.objects(name=name)
    if not players:
        abort(404)
    player = players[0]
    '''

    questions = Question.objects()
    index = int(math.floor(random.random()*len(questions)))

    q = questions[index]

    return jsonify({
        'prompt': q.prompt
        , 'response_0': q.possible_responses[0]
        , 'response_1': q.possible_responses[1]
        , 'response_2': q.possible_responses[2]
        , 'response_3': q.possible_responses[3]
        , 'classification': q.classification
        , 'question_id': str(q.id)
    })
Ejemplo n.º 2
0
def destroy_seed():
    objects = []
    objects.extend(Question.objects())
    objects.extend(Player.objects())
    objects.extend(Answer.objects())
    objects.extend(BodyMediaData.objects())

    for o in objects:
        o.delete()

    return 'ouch'
Ejemplo n.º 3
0
def destroy_seed():
    objects = []
    objects.extend(Question.objects())
    objects.extend(Player.objects())
    objects.extend(Answer.objects())
    objects.extend(BodyMediaData.objects())

    for o in objects:
        o.delete()

    return 'ouch'
Ejemplo n.º 4
0
def player_answers(name):
    players = Player.objects(name=name)
    if not players:
        abort(404)
    player = players[0]

    question_id = request.form.get('question_id', '')
    response = request.form.get('response', '')
    question = Question.objects(id=question_id)[0]

    new_answer = Answer(question=question,
                        player=player,
                        data=int(response),
                        timestamp=datetime.datetime.utcnow())
    new_answer.save()

    player.update(set__last_answer_time=datetime.datetime.utcnow())
    answer_count = Answer.objects(player=player).count()

    return jsonify({'status': 'ok', 'answer_count': answer_count})
Ejemplo n.º 5
0
def player_answers(name):
    players = Player.objects(name=name)
    if not players:
        abort(404)
    player = players[0]

    question_id = request.form.get('question_id', '')
    response = request.form.get('response', '') 
    question = Question.objects(id=question_id)[0]

    new_answer = Answer(
        question = question
        , player = player
        , data = int(response)
        , timestamp = datetime.datetime.utcnow()
    )
    new_answer.save()

    player.update(set__last_answer_time=datetime.datetime.utcnow())
    answer_count = Answer.objects(player=player).count()

    return jsonify({'status': 'ok', 'answer_count': answer_count})
Ejemplo n.º 6
0
def player_questions(name):
    ''' get a relevant question
    '''
    '''
    players = Player.objects(name=name)
    if not players:
        abort(404)
    player = players[0]
    '''

    questions = Question.objects()
    index = int(math.floor(random.random() * len(questions)))

    q = questions[index]

    return jsonify({
        'prompt': q.prompt,
        'response_0': q.possible_responses[0],
        'response_1': q.possible_responses[1],
        'response_2': q.possible_responses[2],
        'response_3': q.possible_responses[3],
        'classification': q.classification,
        'question_id': str(q.id)
    })
Ejemplo n.º 7
0
def seed_questions():
    questions = Question.objects()
    if questions:
        return 'already seeded'

    q = Question(
        prompt = 'How many times did you wake up last night?'
        , possible_responses = ['0', '1', '2', '3']
        , classification = 'morning'
    )
    q.save()

    q = Question(
        prompt = 'How bad were your asthma symptoms when you woke up this morning?'
        , possible_responses = ['not bad at all', 'a little bad', 'somewhat bad', 'very bad']
        , classification = 'morning'
    )
    q.save()

    q = Question(
        prompt = 'How rested do you feel this morning?'
        , possible_responses = ['well rested', 'somewhat', 'a little', 'not at all']
        , classification = 'morning'
    )
    q.save()

    q = Question(
        prompt = 'How much trouble did you have falling asleep?'
        , possible_responses = ['no trouble', 'a little trouble', 'some trouble', 'a lot of trouble']
        , classification = 'morning'
    )
    q.save()

    q = Question(
        prompt = 'How limited were you in activities because of your asthma?'
        , possible_responses = ['not at all', 'a little', 'somewhat', 'a lot']
        , classification = 'night'
    )
    q.save()

    q = Question(
        prompt = 'How much shortness did you experience because of your asthma?'
        , possible_responses = ['none at all', 'a little', 'some', 'a lot']
        , classification = 'night'
    )
    q.save()

    q = Question(
        prompt = 'How much time did you wheeze today?'
        , possible_responses = ['none at all', 'a little of the time', 'some of the time', 'a lot of the time']
        , classification = 'night'
    )
    q.save()

    q = Question(
        prompt = 'How many times did you use your inhaler today?'
        , possible_responses = ['zero', '1-2', '3-4', '5+']
        , classification = 'night'
    )
    q.save()

    q = Question(
        prompt = 'How much did your asthma affect your exercise today?'
        , possible_responses = ['not at all', 'a little', 'somewhat', 'a lot']
        , classification = 'night'
    )
    q.save()

    q = Question(
        prompt = 'How would you rate your asthma control today?'
        , possible_responses = ['1', '2', '3', '4']
        , classification = 'night'
    )
    q.save()

    return 'ok'
Ejemplo n.º 8
0
def seed_questions():
    questions = Question.objects()
    if questions:
        return 'already seeded'

    q = Question(prompt='How many times did you wake up last night?',
                 possible_responses=['0', '1', '2', '3'],
                 classification='morning')
    q.save()

    q = Question(
        prompt=
        'How bad were your asthma symptoms when you woke up this morning?',
        possible_responses=[
            'not bad at all', 'a little bad', 'somewhat bad', 'very bad'
        ],
        classification='morning')
    q.save()

    q = Question(prompt='How rested do you feel this morning?',
                 possible_responses=[
                     'well rested', 'somewhat', 'a little', 'not at all'
                 ],
                 classification='morning')
    q.save()

    q = Question(prompt='How much trouble did you have falling asleep?',
                 possible_responses=[
                     'no trouble', 'a little trouble', 'some trouble',
                     'a lot of trouble'
                 ],
                 classification='morning')
    q.save()

    q = Question(
        prompt='How limited were you in activities because of your asthma?',
        possible_responses=['not at all', 'a little', 'somewhat', 'a lot'],
        classification='night')
    q.save()

    q = Question(
        prompt='How much shortness did you experience because of your asthma?',
        possible_responses=['none at all', 'a little', 'some', 'a lot'],
        classification='night')
    q.save()

    q = Question(prompt='How much time did you wheeze today?',
                 possible_responses=[
                     'none at all', 'a little of the time', 'some of the time',
                     'a lot of the time'
                 ],
                 classification='night')
    q.save()

    q = Question(prompt='How many times did you use your inhaler today?',
                 possible_responses=['zero', '1-2', '3-4', '5+'],
                 classification='night')
    q.save()

    q = Question(
        prompt='How much did your asthma affect your exercise today?',
        possible_responses=['not at all', 'a little', 'somewhat', 'a lot'],
        classification='night')
    q.save()

    q = Question(prompt='How would you rate your asthma control today?',
                 possible_responses=['1', '2', '3', '4'],
                 classification='night')
    q.save()

    return 'ok'