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


Python Score.title_found方法代码示例

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


在下文中一共展示了Score.title_found方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: score

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import title_found [as 别名]
    def score(self, current, result):
        user = self.get_current_user()
        score = self.session.query(Score).filter(Score.current_id == current.id).filter(Score.user_id == user.id).first()
        if(score and score.title_found == 1 and score.artist_found == 1):
            return {'already_found': True}

        players_ahead = self.session.query(Score).filter(Score.current_id == current.id).filter(Score.artist_found == '1').filter(Score.title_found == '1').count()
        previous_score = self.session.query(Score).filter(Score.user_id == user.id).filter(Score.current_id == Current.id).filter(Current.game_id == current.game_id).order_by(desc(Score.id)).first()

        special = 0
        streak = 0

        if(previous_score is None):  # No scores for this game
            previous_score = Score()
            previous_score.score = 0
        if(score is None):  # No score in db for the current song
            score = Score()  # Create a new score
            score.user_id = user.id
            score.current_id = current.id
            score.title_found = 0
            score.artist_found = 0
            score.score = int(previous_score.score or 0)

        if(result['title']['found']):  # title has been found
            if(score.title_found == 0):
                score.title_found = 1
                score.score = int(previous_score.score or 0) + 1
                previous_score.score = score.score
            print "Title found!"
        if(result['artist']['found']):  # artist has been found
            if(score.artist_found == 0):
                score.artist_found = 1
                score.score = int(previous_score.score or 0) + 1
            print "Artist found!"
        if(score.artist_found and score.title_found):  # player has found both
            if(players_ahead < 3):  # Player is in top 3
                score.score = score.score + 1
                special = players_ahead + 1
            if(previous_score.artist_found and previous_score.title_found and previous_score.current_id == score.current_id - 1):  # Player is on a streak
                score.score = score.score + 1
                streak = 1

        self.session.add(score)
        self.session.commit()
        return {'points_gained': score.score - previous_score.score, 'score': score.score, 'special': special, 'streak': streak, 'title_found': score.title_found, 'artist_found': score.artist_found}
开发者ID:solnat,项目名称:Dev,代码行数:47,代码来源:main.py


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