def top_10(message): chat_id = message.chat.id query = get_ranking() rankings = (query.order_by(Ranking.wins.desc()).order_by( Ranking.total.desc()).all()) text = _('No user with any resolved bet.') if rankings: text = (emoji(':trophy:') + ' ' + _('TOP 10 WINS') + ' ' + emoji(':trophy:') + '\n') text += '-----------------\n' query = get_users() count = 0 for ra in rankings: if count == 10: break count += 1 username = query.filter(User.player_id == ra.player_id).first() textu = '<pre>' textu += username.telegram.encode('UTF-8') textu += ' ' * (20 - len(textu)) + ' ' textu += '</pre>' # text += '{0: <15}'.format(username.telegram) textu += emoji(':trophy:') + ' ' + str(ra.wins) textu += emoji(':video_game:') + ' ' + str(ra.total) + '\n' text += textu bot.send_message(chat_id, text, parse_mode="html")
def top_10_rate(message): chat_id = message.chat.id query = get_ranking() session = get_session() rankings = session.execute( 'select id, player_id, (wins * 100 / total) as percentage, total' ' from ranking group by player_id, percentage, total, id ' 'having total > (select max(total) from ranking) / 2 ' 'order by percentage desc limit 10').fetchall() text = _('No user with any resolved bet.') if rankings: text = '🏆 TOP 10 WIN RATE 🏆 \n' if rankings else '' text += '═══════════════════\n' query = get_users() for ra in rankings: username = query.filter(User.player_id == ra[1]).first() # textu = '{0: <15}'.format(username.telegram) textu = '<pre>' textu += username.telegram.encode('UTF-8') textu += ' ' * (20 - len(textu)) + ' ' textu += '</pre>' textu += emoji(':game_die:').encode('UTF-8') textu += ' ' + str(ra[2]) + '% \n' text += textu bot.send_message(chat_id, text, parse_mode="html")
def set_bet_db(message): chat_id = message.chat.id markup = types.ReplyKeyboardHide() bot.send_message(chat_id, _('Winner correctly selected.'), reply_markup=markup) query = get_matches() match = query.filter( Match.id == to_winner[message.from_user.id]['id']).first() match.score1 = to_winner[message.from_user.id]['score1'] match.score2 = message.text update() query = get_bets() bets = query.filter( Bet.match == to_winner[message.from_user.id]['id']).all() for b in bets: query = get_ranking() ranking = query.filter(Ranking.player_id == b.player_id).first() if not ranking: ranking = Ranking(player_id=b.player_id) add(ranking) ranking.total += 1 winner = ('team1' if int(message.text) < int( to_winner[message.from_user.id]['score1']) else 'team2') if to_winner[message.from_user.id][winner] == b.bet: ranking.wins += 1 update() userStep[message.from_user.id] = None
def mestats(message): chat_id = message.chat.id query = get_ranking() ra = query.filter(Ranking.player_id == message.from_user.id).first() query = get_users() username = query.filter(User.player_id == message.from_user.id).first() text = _('You do not have any resolved bet yet.') if username and username.telegram: text = username.telegram.encode('UTF-8') + ' \n' text += emoji(':trophy:') + ' ' + str(ra.wins) + ' \n' text += emoji(':1234:') + ' ' + str(ra.total) + ' \n' text += (emoji(':chart_with_upwards_trend:') + ' ' + str(ra.wins * 100 / ra.total) + '%') bot.send_message(chat_id, text)