• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Score类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.Score的典型用法代码示例。如果您正苦于以下问题:Python Score类的具体用法?Python Score怎么用?Python Score使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Score类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: test

  def test(self, score_class_mock):
    save_mock = Mock(return_value=None)
    score_class_mock.return_value.save = save_mock

    storage = Storage()
    storage.populate()
    self.assertEqual(save_mock.call_count, 1)

    score = Score()
    score.score = 1234
    score_class_mock.objects.all.return_value.order_by.return_value = QuerySetMock(score_class_mock, score)
    score = storage.get_score()
    self.assertEqual(score, 1234)
开发者ID:CADBOT,项目名称:sample-django-mysql-selenium,代码行数:13,代码来源:tests.py


示例17: create_user

    def create_user(self, request):
        """Create a User. Requires a unique username"""
        if User.query(User.name == request.user_name).get():
            raise endpoints.ConflictException(
                    'A User with that name already exists!')
        user = User(name=request.user_name, email=request.email)
        user.put()

        # Create an associated Score for this user

        score = Score(user=user.key)
        score.put()
        return StringMessage(message='User {} created!'.format(
                request.user_name))
开发者ID:CurtiePi,项目名称:triviagame,代码行数:14,代码来源:api.py


示例18: create_score

def create_score(registered_client):
    score = Score()
    score.registered_client = registered_client
    score.played_on = timezone.now()
    score.recieved_on = timezone.now()
    score.play_time = random.randint(2000, 30000)
    score.altitude = random.randint(0, 2000)
    score.score = random.randint(0, 130)
    score.save()

    return score
开发者ID:RomekRJM,项目名称:BubbleUpServer,代码行数:11,代码来源:tests.py


示例19: index

def index():
    den = Score.get_or_insert('den', name='Denver', amount=0)
    sea = Score.get_or_insert('sea', name='Seattle', amount=0)
    goal = 6500 * 100.0
    if den.amount < goal and sea.amount < goal:
        den_factor = den.amount * 100.0 / goal
        sea_factor = sea.amount * 100.0 / goal
    else: 
        den_factor = 100
        sea_factor = 100
        if den.amount > sea.amount:
            sea_factor = sea.amount * 100.0 / den.amount
        elif sea.amount > den.amount:
            den_factor = den.amount * 100.0 / sea.amount
    return render_template('index.html', den=den, sea=sea, den_factor=den_factor, sea_factor=sea_factor)
开发者ID:tghw,项目名称:gotr-bowl,代码行数:15,代码来源:views.py


示例20: get_user_rankings

    def get_user_rankings(self, request):
        """Get game history"""
        # user rankings
        userRanking = UserRankForms()

        # get  all users
        users = User.query().fetch()

        # Get user scores and perform calculation
        for user in users:
            user_scores = Score.query(ancestor=user.key)
            user_scores.count()
            won = 0.0
            lost = 0
            gamecount = 0
            if user_scores:
                for score in user_scores:
                    gamecount += 1
                    if score.won is True:
                        won += 1
                    else:
                        lost += 1
                # perform ranking calculation
                if gamecount > 0:
                    performance = won/gamecount
                else:
                    performance = -1.0  # -1 means user has not completed any games

                # userRankingList.append()
                userRanking.items.append(UserRankForm(user_name=user.name, performance_indicator=performance))
        userRanking.items.sort(key=lambda x: x.performance_indicator, reverse=True)
        return userRanking
开发者ID:joelzeal,项目名称:udacity-appengine-game-project,代码行数:32,代码来源:api.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Server类代码示例发布时间:2022-05-27
下一篇:
Python Runs.get_by_objects方法代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap