def run(self): cl_qualifiers = cleanup_dataframe( self.qualifiers_results(self.URL_CL_QUALIFIERS)) el_qualifiers = cleanup_dataframe( self.qualifiers_results(self.URL_EL_QUALIFIERS)) cl_qualifiers = self.get_first_game_result(cl_qualifiers) el_qualifiers = self.get_first_game_result(el_qualifiers) save_output_to_csv(output=cl_qualifiers, filename="cl_qualifiers") save_output_to_csv(output=el_qualifiers, filename="el_qualifiers")
def calculate_weight(df, my_uefa): df_ranks = [] for year in my_uefa["Year"].unique(): df = my_uefa[my_uefa["Year"] == year] df['Weight'] = [(x_i - min(df["Points"])) / (max(df["Points"]) - min(df["Points"])) for x_i in df["Points"]] df_ranks.append(df) return cleanup_dataframe(pd.concat(df_ranks))
def collect_uefa_clubs_ids(self): ids = [] for season in range(self.SEASON_START, self.SEASON_END): page_content = self.scrape_page(self._URL_UEFA_CLUBS_TABLE, str(season)) ids.append(uefa_ids(page_content)) ids = pd.concat(ids).drop_duplicates() return cleanup_dataframe(ids)
def collect_links_particular_seasons(self): links_to_particular_seasons = [] similar_leagues_links = self.similar_leagues_results_links() for row in similar_leagues_links.itertuples(): page_content = self.scrape_page(self.URL_SOCCERWAY_SEASON, row.Link) links_to_particular_seasons.append( seasons_in_league(page_content, row.Country)) return cleanup_dataframe(pd.concat(links_to_particular_seasons))
def detailed_info_teams(self): links = self.details_clubs_links() detailed_top_tier_teams = [] for link in links: page_content = self.scrape_page(self.URL_BASE, link) detailed_top_tier_teams.append( pd.DataFrame(self.collect_details(page_content, link).to_dict(), index=[0])) return cleanup_dataframe(pd.concat(detailed_top_tier_teams))
def run_uefa_coeff(self): uefa_rankings = [] for season_ranking in range(self.SEASON_START, self.SEASON_END + 1): page_content = self.scrape_page(url=self._URL_UEFA, suffix=str(season_ranking)) uefa_rankings.append( uefa_country_rankings(page_content, season_ranking)) uefa_ranking_all_seasons = cleanup_dataframe(pd.concat(uefa_rankings)) uefa_ranking_similar_leagues = self.keep_similar_leagues( uefa_ranking_all_seasons) similar_leagues = pd.unique(uefa_ranking_similar_leagues["Country"]) return uefa_ranking_similar_leagues, similar_leagues
def run(): teams_full_record = cleanup_dataframe(read_input("teams_full_record")) my_uefa = read_input("uefa_ranking") weight = calculate_weight(teams_full_record, my_uefa) teams_full_record = teams_full_record.merge(weight, how="left", left_on=["Country", "Year"], right_on=["Country", "Year"]) calculate_score_for_single_cup(teams_full_record, "EL") calculate_score_for_single_cup(teams_full_record, "CL") calculate_score_for_single_cup(teams_full_record, "ELQ") calculate_score_for_single_cup(teams_full_record, "CLQ") calculate_score_for_single_cup(teams_full_record, "DL") teams_full_record.replace(np.nan, 0, inplace=True) calculate_score(teams_full_record) save_output_to_csv(teams_full_record, "teams_score")
def check_empty(self, dfs): if dfs: return [cleanup_dataframe(pd.concat(dfs))] else: return []
def similar_leagues_results_links(self): page_content = self.scrape_page(self.URL_SOCCERWAY) all_leagues_links = cleanup_dataframe( pd.concat([leagues_links_soccerway(page_content)])) return all_leagues_links[all_leagues_links['Country'].isin( self.similar_leagues())].reset_index(drop=True)