Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -156,6 +156,11 @@ IF_OAA_25 <- download_private_parquet("CoastalBaseball/DefenseAppDataset", "IF_O
|
|
| 156 |
Date = as.Date(Date),
|
| 157 |
Inning = as.numeric(Inning))
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
OF_OAA_25 <- as.data.frame(download_private_parquet("CoastalBaseball/DefenseAppDataset", "CC_OAA25.parquet")) %>%
|
| 160 |
mutate(obs_player = str_replace_all(obs_player, "(\\w+), (\\w+)", "\\2 \\1"),
|
| 161 |
pred_catch = as.numeric(as.character(pred_catch)),
|
|
@@ -353,8 +358,6 @@ if_oaa_setup <- function(data) {
|
|
| 353 |
player_angle_rad = atan2(obs_player_x, obs_player_z)) %>%
|
| 354 |
filter(!is.na(obs_player))
|
| 355 |
|
| 356 |
-
# For IF model, success_ind needs to be factor
|
| 357 |
-
|
| 358 |
processed <- bake(IF_OAA_recipe, new_data = d) %>%
|
| 359 |
dplyr::select(-any_of("success_ind")) %>%
|
| 360 |
mutate(across(where(is.factor), as.numeric), across(where(is.character), as.numeric))
|
|
@@ -369,7 +372,7 @@ if_oaa_setup <- function(data) {
|
|
| 369 |
Inning = as.numeric(Inning),
|
| 370 |
play_prob = 1 - play_prob,
|
| 371 |
play_pred = ifelse(play_prob >= .5, 1, 0),
|
| 372 |
-
OAA = (as.numeric(success_ind)
|
| 373 |
dplyr::select(obs_player_name, obs_player, success_ind, play_prob, play_pred, OAA,
|
| 374 |
obs_player_direction_diff, obs_player_bearing, obs_player_x, obs_player_z,
|
| 375 |
HangTime, Distance, Bearing, Direction, ExitSpeed, Angle,
|
|
@@ -585,8 +588,7 @@ infield_star_graph <- function(player, position, IF_OAA) {
|
|
| 585 |
pd <- pd %>% mutate(
|
| 586 |
star_group = case_when(play_prob>=0.90~"1 Star",play_prob>=0.70~"2 Star",
|
| 587 |
play_prob>=0.50~"3 Star",play_prob>=0.25~"4 Star",
|
| 588 |
-
play_prob>=0.00000001~"5 Star")
|
| 589 |
-
obs_player_bearing_diff = obs_player_direction_diff)
|
| 590 |
|
| 591 |
OAA <- round(sum(pd$OAA,na.rm=T),1)
|
| 592 |
n_plays <- nrow(pd)
|
|
@@ -596,7 +598,7 @@ infield_star_graph <- function(player, position, IF_OAA) {
|
|
| 596 |
points_data <- pd %>% filter(play_prob > 0) %>%
|
| 597 |
filter(play_prob <= 0.5 | between(obs_player_bearing_diff, -12.5, 12.5))
|
| 598 |
|
| 599 |
-
p <- ggplot(IF_OAA
|
| 600 |
aes(obs_player_bearing_diff, play_prob)) +
|
| 601 |
stat_summary_2d(aes(z = play_prob), fun = mean, bins = 15) +
|
| 602 |
scale_fill_gradientn(
|
|
|
|
| 156 |
Date = as.Date(Date),
|
| 157 |
Inning = as.numeric(Inning))
|
| 158 |
|
| 159 |
+
if obs_player_bearing_diff %in% names(IF_OAA_25) {
|
| 160 |
+
IF_OAA_25$obs_player_direction_diff <- IF_OAA_25$obs_player_bearing_diff
|
| 161 |
+
IF_OAA_25 <- IF_OAA_25 %>% dplyr::select(-obs_player_bearing_diff)
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
OF_OAA_25 <- as.data.frame(download_private_parquet("CoastalBaseball/DefenseAppDataset", "CC_OAA25.parquet")) %>%
|
| 165 |
mutate(obs_player = str_replace_all(obs_player, "(\\w+), (\\w+)", "\\2 \\1"),
|
| 166 |
pred_catch = as.numeric(as.character(pred_catch)),
|
|
|
|
| 358 |
player_angle_rad = atan2(obs_player_x, obs_player_z)) %>%
|
| 359 |
filter(!is.na(obs_player))
|
| 360 |
|
|
|
|
|
|
|
| 361 |
processed <- bake(IF_OAA_recipe, new_data = d) %>%
|
| 362 |
dplyr::select(-any_of("success_ind")) %>%
|
| 363 |
mutate(across(where(is.factor), as.numeric), across(where(is.character), as.numeric))
|
|
|
|
| 372 |
Inning = as.numeric(Inning),
|
| 373 |
play_prob = 1 - play_prob,
|
| 374 |
play_pred = ifelse(play_prob >= .5, 1, 0),
|
| 375 |
+
OAA = (as.numeric(success_ind)) - play_prob) %>%
|
| 376 |
dplyr::select(obs_player_name, obs_player, success_ind, play_prob, play_pred, OAA,
|
| 377 |
obs_player_direction_diff, obs_player_bearing, obs_player_x, obs_player_z,
|
| 378 |
HangTime, Distance, Bearing, Direction, ExitSpeed, Angle,
|
|
|
|
| 588 |
pd <- pd %>% mutate(
|
| 589 |
star_group = case_when(play_prob>=0.90~"1 Star",play_prob>=0.70~"2 Star",
|
| 590 |
play_prob>=0.50~"3 Star",play_prob>=0.25~"4 Star",
|
| 591 |
+
play_prob>=0.00000001~"5 Star"))
|
|
|
|
| 592 |
|
| 593 |
OAA <- round(sum(pd$OAA,na.rm=T),1)
|
| 594 |
n_plays <- nrow(pd)
|
|
|
|
| 598 |
points_data <- pd %>% filter(play_prob > 0) %>%
|
| 599 |
filter(play_prob <= 0.5 | between(obs_player_bearing_diff, -12.5, 12.5))
|
| 600 |
|
| 601 |
+
p <- ggplot(IF_OAA,
|
| 602 |
aes(obs_player_bearing_diff, play_prob)) +
|
| 603 |
stat_summary_2d(aes(z = play_prob), fun = mean, bins = 15) +
|
| 604 |
scale_fill_gradientn(
|