本文整理汇总了Python中models.Score类的典型用法代码示例。如果您正苦于以下问题:Python Score类的具体用法?Python Score怎么用?Python Score使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Score类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request
def request(request):
if request.method == "GET":
rg = request.GET
player = Player.objects.get(id=request.session['user_id'])
if 'new_player_name' in rg:
player.name = rg['new_player_name']
player.save()
return HttpResponse(json.dumps({"result": "success", "player_name": rg['new_player_name']}))
if 'new_max_score' in rg:
game_name = rg['game_name']
score = None
try:
score = Score.objects.get(player=player, game__name=game_name)
except:
score = Score(player=player, game=Game.objects.get(name=game_name), score=0)
score.score = rg['new_max_score']
score.save()
return HttpResponse(json.dumps({"result": "success", "max_score": rg['new_max_score']}))
if 'max_score_records' in rg:
game_name = rg['game_name']
count = rg['count']
max_score_records = []
for record in Score.objects.filter(game__name=game_name).order_by('-score')[:10]:
max_score_records.append({"score": record.score, "player_name": record.player.name})
return HttpResponse(json.dumps(max_score_records))
示例2: get_high_scores
def get_high_scores(self,request):
"""Return all scores ordered by total points"""
if request.number_of_results:
scores = Score.query(Score.won == True).order(Score.attempts_allowed,Score.guesses).fetch(request.number_of_results)
else:
scores = Score.query(Score.won == True).order(Score.attempts_allowed,Score.guesses).fetch()
return ScoreForms(items=[score.to_form() for score in scores])
示例3: get_high_scores
def get_high_scores(self, request):
"""Gets the high scores for the game"""
if request.number_of_results is not None:
scores = Score.query().order(Score.score).fetch(request.number_of_results)
else:
scores = Score.query().order(Score.score)
return ScoreForms(items=[score.to_form() for score in scores])
示例4: player_data
def player_data():
if not request.json or 'player' not in request.json:
print(request, request.json)
abort(400)
db = get_db()
player_data = request.json['player']
friends = player_data['friends']
puzzle_data = player_data['puzzle_data']
del player_data['friends']
del player_data['puzzle_data']
player = Player.get_or_create(player_data)
db.session.query(Player).filter(
Player.social_id == player.social_id).update(player_data)
for friend_social_id in friends:
friend = Player.get_or_create({"social_id": friend_social_id})
player.add_friendship(friend)
for index, puzzle_id in enumerate(puzzle_data['puzzles']):
Score.maybe_update_score({
'player_social_id': player.social_id,
'puzzle_id': puzzle_id,
'score': puzzle_data['scores'][index],
'stars': puzzle_data['stars'][index]})
db.session.commit()
return jsonify(
_assemble_response(player))
示例5: _cache_winning_chance
def _cache_winning_chance(user_name):
"""Populates memcache with the average moves remaining of Games"""
## the scores user earned when it is user in games
user_chance = 0
oppo_chance = 0
user_scores = Score.query(Game.user.get().name == user_name).fetch()
if user_scores:
total = 2*len(user_scores)
wins = sum([score.user_score_to_int() for score in user_scores])
user_chance = wins/float(total)
## score the user earned when it is the opponent in games
oppo_scores = Score.query(Game.user.get().name == GLOBAL_CURRENT_USER_NAME).fetch()
if user_scores:
total = 2*len(oppo_scores)
wins = sum([score.user_score_to_int() for score in oppo_scores])
oppo_chance = wins/float(total)
if user_chance == 0 or oppo_chance == 0:
chance = user_chance | oppo_chance
else:
change = (user_chance+oppo_chance)/2
print "Winning chance of {} is {}".format(GLOBAL_CURRENT_USER_NAME, chance)
memcache.set(MEMCACHE_WINNING_CHANCE,
'The winning chance is {:.2f}'.format(chance))
示例6: get_high_scores
def get_high_scores(self, request):
""" Get the user scores, Requires the user info's"""
user = self._get_user(request)
if request.number_of_results:
scores = Score.query(Score.user == user.key).order(Score.score).fetch(limit=request.number_of_results)
else:
scores = Score.query(Score.user == user.key).order(Score.score)
return ScoreForms(items=[score.to_form() for score in scores])
示例7: test_float_serialization
def test_float_serialization(self):
"""Tests that float values serialize and deserialize intact"""
sc = Score(score=3.4)
sc.save()
serial_str = serializers.serialize(self.serializer_name, [sc])
deserial_objs = list(serializers.deserialize(self.serializer_name,
serial_str))
self.assertEqual(deserial_objs[0].object.score, Approximate(3.4, places=1))
示例8: get_user_rankings
def get_user_rankings(self, request):
"""Returns user rankings"""
users = User.query(User.name)
scores = Score.query([Score.user == user.key])
wins = Score.query([Score.won == True for user in users])
games = Game.query(User.name)
ranks = [(sum(wins)/sum(games) * 100) for user in users]
return ranks
示例9: song_create_score
def song_create_score(user_id, user_email, song_slug, score):
score = Score(
user_id=user_id,
user_email=user_email,
song_slug=song_slug,
score=score,
)
score.put()
示例10: post
def post(self, request):
score = request.POST.get('score')
question_id = request.POST.get('question_id')
question = Question.objects.get(pk=question_id)
score = Score(question=question,user=request.user,score=int(score))
score.save()
return HttpResponse(status=201)
示例11: submit
def submit(user):
try:
score_ = submit_score(request.form.to_dict())
except MultipleInvalid as e:
return show_errors(e)
score = Score(value=score_['score'], user=user)
score.save()
return {"success": True}
示例12: get_high_scores
def get_high_scores(self, request):
"""Return all scores ordered by total points"""
if request.limit:
scores = Score.query().order(-Score.num_of_wons).fetch(request.limit)
else:
scores = Score.query().order(-Score.num_of_wons).fetch()
return ScoreForms(items=[score.to_form() for score in scores])
示例13: end_Game
def end_Game(game, won):
"""
args: game -
won -
ends the user's game.
"""
game.endGame = True
game.put()
user = User.query(User.key == game.user).get()
gameScore = get_Score(game, won)
score = Score(player=user.name, score=gameScore, won=won)
score.put()
示例14: get_high_scores
def get_high_scores(self, request):
"""Return a specified number of high scores"""
# Checks the value of number_of_results to determine if it is a number
# to return a specific number of highscores if it is not then function
# will only return 10 highscores
if isinstance(request.number_of_results, int):
_number_of_results = request.number_of_results
scores = Score.query(Score.won==True).order(Score.total_attempts).fetch(limit=_number_of_results)
return ScoreForms(items=[score.to_form() for score in scores])
else:
scores = Score.query(Score.won==True).order(Score.total_attempts).fetch(limit=10)
return ScoreForms(items=[score.to_form() for score in scores])
示例15: get_user_rankings
def get_user_rankings(self, request):
"""Get user rankings"""
users = User.query()
for user in users:
games = Score.query(Score.user == user.key)
win = Score.query().filter(Score.result == 'Win').fetch()
draw = Score.query().filter(Score.result == 'Draw').fetch()
lose = Score.query().filter(Score.result == "Lose").fetch()
# The final score is base on both performance and participation.
final_score = 5*len(win) + 3*len(win)+ 1*len(lose)
user.rankingscore = final_score
user.put()
return UserForms(items=[user.to_form() for user in User.query().order(-User.rankingscore)])