Skip to content

Commit

Permalink
Formally adding CPI to weekly job
Browse files Browse the repository at this point in the history
  • Loading branch information
erikhall6373 committed Oct 16, 2023
1 parent 2924147 commit cfc509f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
8 changes: 4 additions & 4 deletions heisman_project/Weekly_Data_Job/Weekly_Job.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

qb_stats_df = Quarterback_Stats.get_cfb_ref_passing_data(2023)
qb_stats_df = qb_stats_df[qb_stats_df['School'] != 'School']
#cpi_df = CPI_Ratings.get_cpi_df(2022)
cpi_df = CPI_Ratings.current_cpi_df(2023)

#cpi_df = model_data_clean.cpi_cleaning(cpi_df)
cpi_df = model_data_clean.cpi_cleaning(cpi_df)

cpi_df = Get_Weekly_Win_Percent.calculate_winning_percent(2023)
cpi_df['CPI'] = (cpi_df['Winning_Percent'] * 0.25) * 100
#cpi_df = Get_Weekly_Win_Percent.calculate_winning_percent(2023)
#cpi_df['CPI'] = (cpi_df['Winning_Percent'] * 0.25) * 100
cpi_df = cpi_df[['School', 'Year', 'CPI']]

weekly_df = qb_stats_df.merge(cpi_df, how = 'inner', on = ['School', 'Year'])
Expand Down
25 changes: 23 additions & 2 deletions heisman_project/heisman_model/Data_Wrangling/CPI_Ratings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ def get_cpi_df(year):

return cpi_df

def current_cpi_df(current_year):

cpi_tables = pd.read_html(f"http://www.cpiratings.com/archives/current_table.html")
cpi_df = cpi_tables[0]

cpi_df = set_col_names(cpi_df)
cpi_df = calc_unrounded_ratings(cpi_df)

cpi_df = cpi_df[['Team', 'CPI', 'W', 'L', 'OW', 'OL', 'OOW', 'OOL']].reset_index(drop = True)
cpi_df['Year'] = current_year
cpi_df['Team'] = cpi_df['Team'].apply(lambda x: x.replace('CFP', ""))
cpi_df['Team'] = cpi_df['Team'].apply(lambda x: x.replace('AP', ""))
cpi_df['Team'] = cpi_df['Team'].apply(lambda x: x.replace('BCS', ""))
cpi_df['Team'] = cpi_df['Team'].apply(lambda x: x.replace('(', ""))
cpi_df['Team'] = cpi_df['Team'].apply(lambda x: x.replace(')', ""))
cpi_df['Team'] = cpi_df['Team'].apply(lambda x: x.replace(',', ""))
cpi_df['Team'] = cpi_df['Team'].apply(lambda x: x.strip())

return cpi_df



def get_cpi_by_years(years):

cpi_list = [get_cpi_df(year) for year in years]
Expand All @@ -66,5 +88,4 @@ def get_cpi_by_years(years):

#test = get_cpi_by_years(range(2012, 2020, 1))

#test[test['Year'] == 2012].head()

#test[test['Year'] == 2012].head()
Binary file not shown.
Binary file not shown.

0 comments on commit cfc509f

Please sign in to comment.