def get_number_of_players(): teams = dbf.db_select(database=dbase1, table='teams', columns_in=['team_name']) res = {i: 0 for i in teams} for team in res: players = dbf.db_select(database=dbase1, table='players', columns_in=['player_id'], where='player_status = "{}"'.format(team)) res[team] = len(players) return res
def extract_players_to_sell_and_cash(team, payment): """ Take the players written in the .txt and correct their name if mispelled. Also separe players to sell from the cash. Used inside fix_players_names(). :param team: str :param payment: list, Ex. [Gildias, 2] :return: tuple, Ex. ([GIL DIAS], 2) """ all_players = dbf.db_select(database=dbase1, table='players', columns_in=['player_name'], where=f'player_status = "{team}"') try: cash = re.findall(r'\d+', ''.join(payment))[0] players_to_sell = [i for i in payment if i != cash] except IndexError: cash = 0 players_to_sell = payment for i in range(len(players_to_sell)): players_to_sell[i] = ef.jaccard_result(players_to_sell[i], all_players, 3) return players_to_sell, cash
def __init__(self, team): self.team = team # Players to buy, players to sell and additional money used for each # offer self.acquisti, self.cessioni, self.contanti = self.open_buste() # Players already sold. Used to handle different offers with same # players as payment: if they are used in one offer they cannot be # used in another one self.players_sold = [] self.only_names = [ self.acquisti[i][0] for i in range(1, 6) if self.acquisti[i] ] data = dbf.db_select(database=dbase1, table='classifica', columns_in=['team', 'Tot']) self.pos = [i[0] for i in data].index(team) + 1 self.abs_points = data[self.pos - 1][1]
def extract_player_to_buy_and_price(player_to_buy): """ Take the player written in the .txt and correct its name if mispelled. Used inside fix_players_names(). :param player_to_buy: str, Ex. "Sczezny20" :return: tuple, Ex. (SZCZESNY, 20) """ price = re.findall(r'\d+', player_to_buy)[0] player_to_buy = player_to_buy.replace(price, '').upper() all_players = dbf.db_select(database=dbase1, table='players', columns_in=['player_name'], where=f'player_status = "FREE"') player_to_buy = ef.jaccard_result(player_to_buy, all_players, 3) return player_to_buy, int(price)
def budget_is_ok(tm, players_to_sell, price): """ Check whether the team has money to pay the price and buy the player. Used inside buste_results(). :param tm: str, fantateam :param players_to_sell: list, players sold and used to pay the price. Ex. ['MESSI', 'MARADONA'] :param price: int, value of the offer :return: int if budget is enough, False otherwise """ budg = budgets[tm] for player in players_to_sell: budg += dbf.db_select(database=dbase1, table='players', columns_in=['player_price'], where='player_name = "{}"'.format(player))[0] return budg if price <= budg else False
values=['FREE'], where=f'{wheres[i]} = "{pl_name}"') MIN_NUM_PLAYERS = 25 MAX_NUM_PLAYERS = 32 EXTRA_MONEY = 20 main_dir = '/Users/andrea/Desktop/Cartelle' dbase1 = f'{main_dir}/Bots/FantAstaBot/fanta_asta_db.db' dbase2 = f'{main_dir}/Bots/FantaScandalo/fantascandalo_db.db' number_of_players_per_team = get_number_of_players() budgets = dbf.db_select(database=dbase1, table='budgets', columns_in=['budget_team', 'budget_value']) budgets = {el[0]: el[1] + EXTRA_MONEY for el in budgets} print('\nBUDGET INIZIALE\n') print( tabulate(pd.DataFrame(budgets, index=[0]), showindex=False, headers='keys', numalign='center', tablefmt="orgtbl")) fix_buste_names() buste = {i: Busta(i) for i in budgets}