Пример #1
0
def stealths_left(bot, update, args):
    if args:
        user = determine_user(args[0])
        bot.send_message(update.message.chat_id,
                         get_stealth_left_for_user(user))
    else:
        bot.send_message(update.message.chat_id,
                         simple_table(get_stealths_left()))
def second_power_players(bot, update, args):
    if args:
        user = determine_user(args[0])
        bot.send_message(update.message.chat_id,
                         get_second_power_player_for_user(user))
    else:
        bot.send_message(update.message.chat_id,
                         simple_table(get_second_power_players()))
Пример #3
0
def sub_strike_rate(bot, update, args):
    if args:
        user = determine_user(args[0])
        bot.send_message(update.message.chat_id,
                         get_sub_strike_rate_for_user(user))
    else:
        bot.send_message(update.message.chat_id,
                         simple_table(get_sub_strike_rates()))
Пример #4
0
def historical_points(bot, update, args):
    if args:
        user = determine_user(args[0])
        points = get_user_points_history(user)

        # bot.send_message(update.message.chat_id, simple_table(get_user_points_history(user)))

        plt.figure()
        named_file = tempfile.NamedTemporaryFile(suffix='.png')
        plot = sns.pointplot(x=[p[0] for p in points],
                             y=[p[1] for p in points])

        if len(args) > 1:
            user2 = determine_user(args[1])
            points2 = get_user_points_history(user2)
            plot = sns.pointplot(x=[p[0] for p in points2],
                                 y=[p[1] for p in points2],
                                 color='red')

        plot.legend(handles=plot.lines[::len(points) + 1], labels=args)
        plot.figure.savefig(named_file.name)
        bot.send_photo(update.message.chat_id,
                       photo=open(named_file.name, 'rb'))

        plt.figure()
        named_file = tempfile.NamedTemporaryFile(suffix='.png')
        plot = sns.barplot(x=[p[0] for p in points], y=[p[1] for p in points])
        plot.figure.savefig(named_file.name)
        bot.send_photo(update.message.chat_id,
                       photo=open(named_file.name, 'rb'))

        # plot = sns.pointplot(x=[p[0] for p in points], y=[p[1] for p in points])
        # plot.figure.savefig('/tmp/tmp.png')
        # bot.send_photo(update.message.chat_id, photo=open('/tmp/tmp.png', 'rb'))

    else:
        bot.send_message(chat_id=update.message.chat_id,
                         text="Please specify a user")
Пример #5
0
def subs_left(bot, update, args):
    if args:
        user = determine_user(args[0])
        bot.send_message(update.message.chat_id, get_subs_left_for_user(user))
    else:
        matches_left = 7949 - int(get_match_id()) + 1
        projected_subs = int(75 / 55 * matches_left)

        resp = "Matches left: {} \n".format(matches_left)
        resp += "Projected Subs: {}\n".format(projected_subs)

        subs_left = get_subs_left()
        resp += simple_table(subs_left)
        bot.send_message(update.message.chat_id, resp)
Пример #6
0
def mult_left(bot, update, args):
    mult_left = []

    if args:
        user = determine_user(args[0])
        squad_details = get_squad_details(user)
        bot.send_message(update.message.chat_id, _get_mult_left(squad_details))
        return

    for user_id in USER_IDS:
        squad_details = get_squad_details(user_id)
        mult_left.append((get_league_team_name_for_user(user_id),
                          _get_mult_left(squad_details)))

    mult_left.sort(key=lambda x: int(x[1]), reverse=True)
    resp = "2X left: \n"
    resp += simple_table(mult_left)

    bot.send_message(update.message.chat_id, resp)
Пример #7
0
def players_of(bot, update, args):
    # bot.send_message(update.message.chat_id, "Stealth for life!")
    # return
    if not args:
        bot.send_message(update.message.chat_id, "Usage: /playersof badri mi")
        return

    user = determine_user(args[0])
    squad_details = get_squad_details(user)
    players = [get_player(p) for p in squad_details['players']]

    if len(args) > 1:
        teams = list(map(determine_team, args[1:]))
        players = [p for p in players if p['team'] in teams]

    if not players:
        bot.send_message(update.message.chat_id, "No players")
        return

    players_table = []

    pacific_tz = pytz.timezone('US/Pacific')
    now = arrow.now().astimezone(pacific_tz)
    matches = get_matches()
    for player in players:
        next_opportunity = 0
        for match in matches:
            starttime = arrow.get(match.starttime).astimezone(pacific_tz)
            if now > starttime:
                continue
            next_opportunity += 1
            if player.team in match.teams:
                break
        players_table.append(
            (_get_player_name(player, squad_details), next_opportunity))

    message = tabulate.tabulate(players_table,
                                headers=['Player', 'nextopportunityin'])
    resp = "Total Players: {} \n".format(len(players_table))
    resp += message

    bot.send_message(update.message.chat_id, resp)
Пример #8
0
def get_live_total_scores(args=None):
    live_total_scores = {
        _user: get_total_score_so_far_for_user(_user)
        for _user in USER_IDS
    }

    if args:
        user = determine_user(args[0])
        user_score = live_total_scores.get(user)
        live_total_scores = {
            _user: score - user_score
            for _user, score in live_total_scores.items()
        }

    live_total_scores = {
        get_league_team_name_for_user(user): score
        for user, score in live_total_scores.items()
    }
    return sorted(live_total_scores.items(),
                  key=lambda x: int(x[1]),
                  reverse=True)
Пример #9
0
def live_fantasy_scores(bot, update, args):
    resp = get_score_card()
    resp += "\n"

    if args:
        user = determine_user(args[0])
        live_data = get_live_data_for_user(user)
        user_players = get_squad_details(user)['players']

        player_points = []
        for player in live_data['playerPoints']:
            if player['playerId'] in user_players:
                points = get_points_from_live_player_points(player)
                if not points:
                    continue
                player_points.append(
                    (get_player(player['playerId']).name, points))

        player_points = sorted(player_points,
                               key=lambda x: int(x[1]),
                               reverse=True)

        resp += "Live Points: {} \n".format(
            get_total_points_from_live_data(live_data))
        resp += simple_table(player_points)

        bot.send_message(update.message.chat_id, resp)
    else:
        live_scores = []
        for user in USER_IDS:
            live_data = get_live_data_for_user(user)
            score = get_total_points_from_live_data(live_data)
            live_scores.append((get_league_team_name_for_user(user), score))

        live_scores.sort(key=lambda x: int(x[1]), reverse=True)
        resp += simple_table(live_scores)
        bot.send_message(update.message.chat_id, resp)