Created
May 5, 2022 06:50
-
-
Save databyjp/3b50f9f71b96bff0b0dd92a1fa0318d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for gm_id in gm_ids: | |
shot_blot_dfs = list() | |
gm_df = playoffs_df[playoffs_df.GAME_ID == gm_id] | |
game_date = gm_df["realtime_dt"].min().date() | |
game_date_str = f"{game_date.day}_{game_date.strftime('%b')}_{game_date.strftime('%Y')}" | |
tm_ids = gm_df.teamId.unique() | |
tm_abvs = [teams.find_team_name_by_id(tm_id)['abbreviation'] for tm_id in tm_ids] | |
for tm_id in tm_ids: | |
tmp_dfs = list() | |
tm = teams.find_team_name_by_id(tm_id) | |
logger.info(f'Analysing game {gm_id} for {tm["full_name"]}') | |
tm_gm_df = gm_df[gm_df.teamId == tm_id] | |
tm_gm_gdf = utils.get_shot_dist_df(tm_gm_df, playoffs_df) | |
tm_gm_gdf = tm_gm_gdf.assign(segment=game_date_str) | |
pl_gdf = utils.get_pl_shot_dist_df(tm_gm_df, season_df) | |
pl_gdf = pl_gdf.assign(segment=game_date_str) | |
pl_ranks = pl_gdf.groupby("group").sum()["shot_atts"].sort_values().index.to_list()[::-1] | |
tm_playoffs_df = playoffs_df[playoffs_df.teamId == tm_id] | |
tm_playoffs_gdf = utils.get_shot_dist_df(tm_playoffs_df, season_df) | |
tm_playoffs_gdf = tm_playoffs_gdf.assign(group=f'{tm["abbreviation"]}_playoffs') | |
tm_playoffs_gdf = tm_playoffs_gdf.assign(segment="Playoffs") | |
tm_season_df = season_df[season_df.teamId == tm_id] | |
tm_season_gdf = utils.get_shot_dist_df(tm_season_df, season_df) | |
tm_season_gdf = tm_season_gdf.assign(group=f'{tm["abbreviation"]}_season') | |
tm_season_gdf = tm_season_gdf.assign(segment="Regular Season") | |
# Add dataframes together | |
tmp_dfs.append(tm_gm_gdf) | |
tmp_dfs.append(pl_gdf) | |
tmp_dfs.append(tm_season_gdf) | |
tmp_dfs.append(tm_playoffs_gdf) | |
tmp_df = pd.concat(tmp_dfs) | |
tmp_df = tmp_df.assign(team=tm["abbreviation"]) | |
# Add Overall dataframes together | |
shot_blot_dfs.append(tmp_df) | |
shot_blot_df = pd.concat(shot_blot_dfs) | |
shot_blot_df = shot_blot_df.assign(filt_avg=(shot_blot_df["filt_start"] + shot_blot_df["filt_end"])/2) | |
shot_blot_df.to_csv(f'temp/{tm_abvs[0]}_{tm_abvs[1]}_{game_date_str}.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment