本文整理汇总了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}