Update app.py
Browse files
app.py
CHANGED
|
@@ -242,84 +242,84 @@ def server(input, output, session):
|
|
| 242 |
|
| 243 |
return df_merge
|
| 244 |
|
| 245 |
-
@reactive.Calc
|
| 246 |
-
def ts_data():
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
|
| 324 |
@reactive.Calc
|
| 325 |
def ts_data_summ():
|
|
@@ -646,9 +646,9 @@ def server(input, output, session):
|
|
| 646 |
df_last_game = df_spring_stuff.filter(pl.col("is_last_game"))
|
| 647 |
df_prior_games = df_spring_stuff.filter(~pl.col("is_last_game"))
|
| 648 |
|
| 649 |
-
# Step 5: Apply feature engineering to both
|
| 650 |
-
df_last_group = stuff_apply.stuff_apply(fe.feature_engineering(df_last_game))
|
| 651 |
-
df_prior_group = stuff_apply.stuff_apply(fe.feature_engineering(df_prior_games))
|
| 652 |
|
| 653 |
# Step 6: Group and aggregate both
|
| 654 |
def group_by_pitch(df):
|
|
|
|
| 242 |
|
| 243 |
return df_merge
|
| 244 |
|
| 245 |
+
# @reactive.Calc
|
| 246 |
+
# def ts_data():
|
| 247 |
+
|
| 248 |
+
# df_spring = spring_data()
|
| 249 |
+
|
| 250 |
+
# # df_year_old = stuff_apply.stuff_apply(fe.feature_engineering(pl.concat([df_mlb,df_aaa,df_a,df_afl])))
|
| 251 |
+
# # df_year_2old = stuff_apply.stuff_apply(fe.feature_engineering(pl.concat([df_mlb_2023])))
|
| 252 |
+
# df_spring_stuff = stuff_apply.stuff_apply(fe.feature_engineering(df_spring))
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
# import polars as pl
|
| 256 |
+
|
| 257 |
+
# # Compute total pitches for each pitcher
|
| 258 |
+
# df_pitcher_totals = df_spring_stuff.group_by("pitcher_id").agg(
|
| 259 |
+
# pl.col("start_speed").count().alias("pitcher_total")
|
| 260 |
+
# )
|
| 261 |
+
|
| 262 |
+
# df_spring_group = df_spring_stuff.group_by(['pitcher_id', 'pitcher_name', 'pitch_type']).agg([
|
| 263 |
+
# pl.col('start_speed').count().alias('count'),
|
| 264 |
+
# pl.col('start_speed').mean().alias('start_speed'),
|
| 265 |
+
# pl.col('start_speed').max().alias('max_start_speed'),
|
| 266 |
+
# pl.col('ivb').mean().alias('ivb'),
|
| 267 |
+
# pl.col('hb').mean().alias('hb'),
|
| 268 |
+
# pl.col('release_pos_z').mean().alias('release_pos_z'),
|
| 269 |
+
# pl.col('release_pos_x').mean().alias('release_pos_x'),
|
| 270 |
+
# pl.col('extension').mean().alias('extension'),
|
| 271 |
+
# pl.col('tj_stuff_plus').mean().alias('tj_stuff_plus'),
|
| 272 |
+
# (pl.col('start_speed').filter(pl.col('batter_hand')=='L').count()).alias('rhh_count'),
|
| 273 |
+
# (pl.col('start_speed').filter(pl.col('batter_hand')=='R').count()).alias('lhh_count')
|
| 274 |
+
# ])
|
| 275 |
+
|
| 276 |
+
# # Join total pitches per pitcher to the grouped DataFrame on pitcher_id
|
| 277 |
+
# df_spring_group = df_spring_group.join(df_pitcher_totals, on="pitcher_id", how="left")
|
| 278 |
+
|
| 279 |
+
# # Now calculate the pitch percent for each pitcher/pitch_type combination
|
| 280 |
+
# df_spring_group = df_spring_group.with_columns(
|
| 281 |
+
# (pl.col("count") / pl.col("pitcher_total")).alias("pitch_percent")
|
| 282 |
+
# )
|
| 283 |
+
|
| 284 |
+
# # Optionally, if you want the percentage of left/right-handed batters within the group:
|
| 285 |
+
# df_spring_group = df_spring_group.with_columns([
|
| 286 |
+
# (pl.col("rhh_count") / pl.col("pitcher_total")).alias("rhh_percent"),
|
| 287 |
+
# (pl.col("lhh_count") / pl.col("pitcher_total")).alias("lhh_percent")
|
| 288 |
+
# ])
|
| 289 |
+
|
| 290 |
+
# df_merge = df_spring_group.join(df_year_old_group,on=['pitcher_id','pitch_type'],how='left',suffix='_old')
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
# df_merge = df_merge.with_columns(
|
| 294 |
+
# pl.col('pitcher_id').is_in(df_year_old_group['pitcher_id']).alias('exists_in_old')
|
| 295 |
+
# )
|
| 296 |
+
|
| 297 |
+
# df_merge = df_merge.with_columns(
|
| 298 |
+
# pl.when(pl.col('start_speed_old').is_null() & pl.col('exists_in_old'))
|
| 299 |
+
# .then(pl.lit(True))
|
| 300 |
+
# .otherwise(pl.lit(None))
|
| 301 |
+
# .alias("new_pitch")
|
| 302 |
+
# )
|
| 303 |
+
|
| 304 |
+
# df_merge = df_merge.select([
|
| 305 |
+
# 'pitcher_id',
|
| 306 |
+
# 'pitcher_name',
|
| 307 |
+
# 'pitch_type',
|
| 308 |
+
# 'count',
|
| 309 |
+
# 'pitch_percent',
|
| 310 |
+
# 'rhh_percent',
|
| 311 |
+
# 'lhh_percent',
|
| 312 |
+
# 'start_speed',
|
| 313 |
+
# 'max_start_speed',
|
| 314 |
+
# 'ivb',
|
| 315 |
+
# 'hb',
|
| 316 |
+
# 'release_pos_z',
|
| 317 |
+
# 'release_pos_x',
|
| 318 |
+
# 'extension',
|
| 319 |
+
# 'tj_stuff_plus',
|
| 320 |
+
# ])
|
| 321 |
+
|
| 322 |
+
# return df_merge
|
| 323 |
|
| 324 |
@reactive.Calc
|
| 325 |
def ts_data_summ():
|
|
|
|
| 646 |
df_last_game = df_spring_stuff.filter(pl.col("is_last_game"))
|
| 647 |
df_prior_games = df_spring_stuff.filter(~pl.col("is_last_game"))
|
| 648 |
|
| 649 |
+
# # Step 5: Apply feature engineering to both
|
| 650 |
+
# df_last_group = stuff_apply.stuff_apply(fe.feature_engineering(df_last_game))
|
| 651 |
+
# df_prior_group = stuff_apply.stuff_apply(fe.feature_engineering(df_prior_games))
|
| 652 |
|
| 653 |
# Step 6: Group and aggregate both
|
| 654 |
def group_by_pitch(df):
|