Upload calculate_arm_angles.py
Browse files
stuff_model/calculate_arm_angles.py
CHANGED
|
@@ -5,7 +5,7 @@ import requests
|
|
| 5 |
def calculate_arm_angles(df: pl.DataFrame,pitcher_id:int) -> pl.DataFrame:
|
| 6 |
df_arm_angle = pl.read_csv('stuff_model/pitcher_arm_angles_2024.csv')
|
| 7 |
#pitcher_id = 489446
|
| 8 |
-
df_filter = df.filter(pl.col("pitcher_id") == pitcher_id)
|
| 9 |
# data = requests.get(f'https://statsapi.mlb.com/api/v1/people?personIds={pitcher_id}').json()
|
| 10 |
|
| 11 |
if pitcher_id not in df_arm_angle["pitcher"]:
|
|
@@ -45,7 +45,7 @@ def calculate_arm_angles(df: pl.DataFrame,pitcher_id:int) -> pl.DataFrame:
|
|
| 45 |
)
|
| 46 |
.with_columns(
|
| 47 |
(pl.col("release_pos_z") - shoulder_z).alias("Opp"),
|
| 48 |
-
(pl.col("release_pos_x") - shoulder_x).alias("Adj"),
|
| 49 |
)
|
| 50 |
.with_columns(
|
| 51 |
pl.struct(["Opp", "Adj"]).map_elements(lambda x: np.arctan2(x["Opp"], x["Adj"])).alias("arm_angle_rad")
|
|
@@ -57,11 +57,10 @@ def calculate_arm_angles(df: pl.DataFrame,pitcher_id:int) -> pl.DataFrame:
|
|
| 57 |
)
|
| 58 |
|
| 59 |
df_filter = df_filter.with_columns(
|
| 60 |
-
((pl.col("arm_angle") *
|
| 61 |
)
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
-
return df_filter
|
| 67 |
-
|
|
|
|
| 5 |
def calculate_arm_angles(df: pl.DataFrame,pitcher_id:int) -> pl.DataFrame:
|
| 6 |
df_arm_angle = pl.read_csv('stuff_model/pitcher_arm_angles_2024.csv')
|
| 7 |
#pitcher_id = 489446
|
| 8 |
+
df_filter = df.filter(pl.col("pitcher_id") == pitcher_id).drop_nulls(subset=["release_pos_x", "release_pos_z"])
|
| 9 |
# data = requests.get(f'https://statsapi.mlb.com/api/v1/people?personIds={pitcher_id}').json()
|
| 10 |
|
| 11 |
if pitcher_id not in df_arm_angle["pitcher"]:
|
|
|
|
| 45 |
)
|
| 46 |
.with_columns(
|
| 47 |
(pl.col("release_pos_z") - shoulder_z).alias("Opp"),
|
| 48 |
+
(pl.col("release_pos_x") - shoulder_x*-1).alias("Adj"),
|
| 49 |
)
|
| 50 |
.with_columns(
|
| 51 |
pl.struct(["Opp", "Adj"]).map_elements(lambda x: np.arctan2(x["Opp"], x["Adj"])).alias("arm_angle_rad")
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
df_filter = df_filter.with_columns(
|
| 60 |
+
((pl.col("arm_angle") * 1) + (ball_angle * 0.0)).alias("arm_angle")
|
| 61 |
)
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
+
return df_filter
|
|
|