当前位置: 首页>>代码示例>>Python>>正文


Python models.Score类代码示例

本文整理汇总了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))
开发者ID:antoshkaplus,项目名称:Django_PersonalWebsite,代码行数:25,代码来源:views.py

示例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])
开发者ID:NellMartin,项目名称:Game-Design,代码行数:7,代码来源:api.py

示例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])
开发者ID:AlecTietjens,项目名称:Hangman,代码行数:7,代码来源:api.py

示例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))
开发者ID:zachdonovan,项目名称:muddragon,代码行数:32,代码来源:app.py

示例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))
开发者ID:kensupernova,项目名称:tic-tac-toe-game-api,代码行数:27,代码来源:api.py

示例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])
开发者ID:Ilyes-Hammadi,项目名称:hangman,代码行数:8,代码来源:api.py

示例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))
开发者ID:Terhands,项目名称:django,代码行数:8,代码来源:tests.py

示例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
开发者ID:thechad12,项目名称:App-engine-game,代码行数:8,代码来源:api.py

示例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()
开发者ID:vaguity,项目名称:music-clurb,代码行数:8,代码来源:clurb.py

示例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)
开发者ID:muthurajendran,项目名称:hangman,代码行数:9,代码来源:views.py

示例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}
开发者ID:raymank26,项目名称:asteroids-server,代码行数:9,代码来源:scores.py

示例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])
开发者ID:cobunny,项目名称:Game-API-Design,代码行数:9,代码来源:api.py

示例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()
开发者ID:phyrenight,项目名称:Udproject4,代码行数:12,代码来源:index.py

示例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])
开发者ID:sensi501,项目名称:GAE-Concentration,代码行数:12,代码来源:api.py

示例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)])
开发者ID:minjiecode,项目名称:TicTacToe,代码行数:13,代码来源:api.py


注:本文中的models.Score类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。