本文整理汇总了Python中models.Player.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Player.objects方法的具体用法?Python Player.objects怎么用?Python Player.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.objects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_team
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import objects [as 别名]
def save_team(request):
team_str = request.POST.get('team')
team_json = json.loads(team_str)
goalkeepers = team_json['GK']
defenders = team_json['D']
midfielders = team_json['M']
forwards = team_json['F']
subs = team_json['S']
username = 'kdyachkov'
team_name = 'TestFC'
user = None
team = None
user_objs = User.objects(name=username)
if user_objs:
if len(user_objs) > 1:
return HttpResponse(status=500)
else:
user = user_objs[0]
team = user.team
else:
user = User(name=username)
team = Team(name=team_name)
user.team = team
user.save()
goalkeeper = Player.objects(id__in=[goalkeeper['id'] for goalkeeper in goalkeepers]) if goalkeepers else []
defenders_objs = Player.objects(id__in=[defender['id'] for defender in defenders]) if defenders else []
midfielders_objs = Player.objects(id__in=[midfielder['id'] for midfielder in midfielders]) if midfielders else []
forwards_objs = Player.objects(id__in=[forward['id'] for forward in forwards]) if forwards else []
subs_objs = Player.objects(id__in=[sub['id'] for sub in subs]) if subs else []
team.goalkeeper = goalkeeper
team.defenders = defenders_objs
team.midfielders = midfielders_objs
team.forwards = forwards_objs
team.subs = subs_objs
user.team = team
user.save()
print goalkeeper
print defenders
print midfielders
print forwards
print subs
return HttpResponse(status=200)
示例2: player_home
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player 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)
示例3: destroy_seed
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player 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'
示例4: seed_players
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import objects [as 别名]
def seed_players():
players = Player.objects()
if players:
return 'already seeded'
new_player = Player(
name = 'matt'
, signup_time = datetime.datetime.utcnow()
, birthday = datetime.date(1988, 2, 3)
, height = '77'
, weight = '165'
, smoker = False
, gender = 'male'
)
new_player.save()
return 'ok'
示例5: seed_bmdata
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import objects [as 别名]
def seed_bmdata():
''' hacked way to get our static data into the db
'''
# if there is no body media data in the db
bm_data = BodyMediaData.objects()
if bm_data:
return 'already seeded'
# attach to a specific player
player = Player.objects(name='matt')[0]
# in 'static' dir we have an excel file with Body Media data rows
data_path = 'static/data/v2.csv'
with open(data_path, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
''' iterate over the rows and inject body media entries
assuming this column order in the excel file:
timestamp, lying down, sleep duration, calories in, calories out,
average MET, sed, mod, vigorous
'''
count = 0
for row in reader:
if count == 0:
count += 1
continue
bmdata = BodyMediaData(
timestamp = datetime.datetime.fromtimestamp(time.mktime(
time.strptime(row[0], '%Y%m%d.000000')))
, lying_down = float(row[1])
, sleep_duration = float(row[2])
, caloric_intake = float(row[3])
, caloric_output = float(row[4])
, average_met = float(row[5])
, sedentary_activity_duration = float(row[6])
, moderate_activity_duration = float(row[7])
, vigorous_activity_duration = float(row[8])
, player=player
)
bmdata.save()
return 'ok'
示例6: player_answers
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player 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})
示例7: player_data
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import objects [as 别名]
def player_data(name, date):
''' date is of the format 20120910 or YYmd
'''
players = Player.objects(name=name)
if not players:
abort(404)
player = players[0]
requested_date = datetime.datetime.fromtimestamp(time.mktime(
time.strptime(date, '%Y%m%d')))
data = None
# what if 2010??
while not data:
data = BodyMediaData.objects(player=player, timestamp=requested_date)
requested_date = requested_date - datetime.timedelta(days=1)
data = data[0]
todays_result = compute(player, requested_date, data)
# total-score computation
total_score = 0
for i in [0,1,2]:
requested_date = requested_date - datetime.timedelta(days=i)
r = compute(player, requested_date, data)
if i == 0:
total_score += 0.6*(10*r['physical_activity'] + r['question_responses'] + 10*r['net_calories'] + 10*r['time_slept'])
elif i == 1:
total_score += 0.3*(10*r['physical_activity'] + r['question_responses'] + 10*r['net_calories'] + 10*r['time_slept'])
elif i == 2:
total_score += 0.1*(10*r['physical_activity'] + r['question_responses'] + 10*r['net_calories'] + 10*r['time_slept'])
todays_result['total_score'] = int(total_score)
return jsonify(todays_result)