本文整理汇总了Python中models.Answer.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Answer.objects方法的具体用法?Python Answer.objects怎么用?Python Answer.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Answer
的用法示例。
在下文中一共展示了Answer.objects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: player_home
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import objects [as 别名]
def player_home(name):
players = Player.objects(name=name)
if not players:
abort(404)
player = players[0]
answer_count = Answer.objects(player=player).count()
return render_template('player_home.html', name=name
, answer_count=answer_count)
示例2: destroy_seed
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import objects [as 别名]
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'
示例3: player_answers
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import objects [as 别名]
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})
示例4: compute
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import objects [as 别名]
def compute(player, requested_date, data):
''' compute all parameters..
'''
# calculatron
''' net caloric intake
'''
net = data.caloric_intake - data.caloric_output
if net >= 100:
net_calories = 3
elif net >= -100 and net < 100:
net_calories = 2
else:
net_calories = 1
''' activity calculator
'''
caloric_target = 2475 # parameterize later
age = 39
if player.gender == 'male':
BMR = 66 + (6.23 * player.weight) + (12.7 * player.height) - (6.8 * age)
else:
BMR = 655 + (4.35 * player.weight) + (4.7 * player.height) - (4.7 * age)
baseline = BMR * 1.2
if data.caloric_output >= caloric_target + 200:
physical_activity = 3
elif data.caloric_output >= baseline + 350 and data.caloric_output < caloric_target + 200:
physical_activity = 2
else:
physical_activity = 1
''' sleep calculator
'''
sleep_goal = 60*8 # parameterize one day, lalala
# try to get the previous day
previous_day = requested_date - datetime.timedelta(days=1)
previous_day_data = BodyMediaData.objects(player=player
, timestamp=previous_day)
if not previous_day_data:
# 100% weighted to current day
percent_of_goal = data.lying_down / sleep_goal
sleep_efficiency = data.sleep_duration / data.lying_down
if percent_of_goal > 1:
percent_score = 3
elif percent_of_goal > 0.9:
percent_score = 2
else:
percent_score = 1
if sleep_efficiency >= 0.8:
efficiency_score = 3
elif sleep_efficiency > 0.6:
efficiency_score = 2
else:
efficiency_score = 1
if efficiency_score == 3 and percent_score == 3:
time_slept = 3
elif efficiency_score == 2 or percent_score == 2:
time_slept = 2
elif efficiency_score == 1 or percent_score == 1:
time_slept = 1
else:
previous_day_data = previous_day_data[0]
# 25% yesterday, 75% today
percent_of_goal = data.lying_down / sleep_goal
percent_of_goal_yesterday = previous_day_data.lying_down / sleep_goal
sleep_efficiency = data.sleep_duration / data.lying_down
sleep_efficiency_yesterday = previous_day_data.sleep_duration / data.lying_down
if percent_of_goal*0.75 + percent_of_goal_yesterday*0.25 > 1:
percent_score = 3
if percent_of_goal*0.75 + percent_of_goal_yesterday*0.25 > 0.9:
percent_score = 2
else:
percent_score = 1
if sleep_efficiency*0.75 + sleep_efficiency_yesterday*0.25 >= 0.8:
efficiency_score = 3
if sleep_efficiency*0.75 + sleep_efficiency_yesterday*0.25 >= 0.6:
efficiency_score = 2
else:
efficiency_score = 1
if efficiency_score == 3 and percent_score == 3:
time_slept = 3
elif efficiency_score == 2 or percent_score == 2:
time_slept = 2
elif efficiency_score == 1 or percent_score == 1:
time_slept = 1
#.........这里部分代码省略.........