igroffman commited on
Commit
0aa3a70
·
verified ·
1 Parent(s): 57b80f6

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +16 -20
app.R CHANGED
@@ -173,7 +173,7 @@ spring26_ncaa <- download_master_dataset("CoastalBaseball/2026MasterDataset", "n
173
  college_join <- download_private_csv("CoastalBaseball/DefenseAppDataset", "college_join.csv")
174
 
175
  # Load Catcher 2026 data
176
- Catcher2026 <- read_parquet("Catcher2026.parquet")
177
  Catcher2026 <- Catcher2026 %>%
178
  mutate(
179
  Date = as.Date(Date),
@@ -189,26 +189,29 @@ Catcher2026 <- Catcher2026 %>%
189
  )
190
 
191
  # Classify framing: Strike Added / Strike Lost
192
- STRIKE_CALLS <- c("StrikeCalled","Called Strike","strike_called","StrikeSwinging",
193
- "FoulBall","InPlay","Foul","FoulBallNotFieldable",
194
- "FoulBallFieldable","FoulTip","Foul Tip")
195
- BALL_CALLS <- c("BallCalled","Ball","ball_called","BallinDirt","BallIntentional",
196
- "HitByPitch","ball","AutomaticBall")
197
  Catcher2026 <- Catcher2026 %>%
198
  mutate(
199
- StolenStrike = as.integer(in_zone == 0 & PitchCall %in% STRIKE_CALLS),
200
- StrikeLost = as.integer(in_zone == 1 & PitchCall %in% BALL_CALLS),
 
201
  frame = case_when(
202
- in_zone == 1 & PitchCall %in% BALL_CALLS ~ "Strike Lost",
203
- in_zone == 0 & PitchCall %in% STRIKE_CALLS ~ "Strike Added",
 
204
  TRUE ~ NA_character_
205
  ),
206
  frame_numeric = case_when(
207
- in_zone == 1 & PitchCall %in% BALL_CALLS ~ -1,
208
- in_zone == 0 & PitchCall %in% STRIKE_CALLS ~ 1,
209
  TRUE ~ NA_real_
210
  )
211
- )
 
212
 
213
  # ============================================================
214
  # PREPARE DEFENSE DATA
@@ -1774,7 +1777,6 @@ server <- function(input, output, session) {
1774
  fill=NA, color="gray40", linewidth=.4, inherit.aes=FALSE) +
1775
  geom_point(aes(fill=TaggedPitchType), shape=21, size=5,
1776
  color="black", stroke=.6, alpha=.95, na.rm=TRUE) +
1777
- geom_text(aes(label=row_num), size=2.0, fontface="bold", color="white", na.rm=TRUE) +
1778
  scale_fill_manual(values=pitch_colors, na.value="grey60",
1779
  name="Pitch Type", drop=FALSE, limits=apt) +
1780
  coord_equal() +
@@ -1837,7 +1839,6 @@ server <- function(input, output, session) {
1837
  fill=NA, color="gray50", linewidth=.6, inherit.aes=FALSE) +
1838
  geom_polygon(data=plate_oh, aes(x=x,y=y), fill="gray95", color="black", linewidth=.8, inherit.aes=FALSE) +
1839
  geom_point(aes(fill=TaggedPitchType), shape=21, size=4, color="black", stroke=.6, alpha=.95) +
1840
- geom_text(aes(label=row_num), size=2.0, fontface="bold", color="white") +
1841
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", drop=FALSE, limits=apt) +
1842
  coord_fixed() + labs(title=ttl, x="Side (ft)", y="Depth (ft)") +
1843
  theme_minimal() + theme(plot.title=element_text(hjust=.5, size=10, face="bold"),
@@ -1853,7 +1854,6 @@ server <- function(input, output, session) {
1853
  annotate("text", x=min(d2$cpz, na.rm=TRUE)-0.1, y=3.3775, label="Zone Top", hjust=1, size=2.5, color="gray40") +
1854
  geom_vline(xintercept=0, color="gray50", linewidth=.4, linetype="dotted") +
1855
  geom_point(aes(fill=TaggedPitchType), shape=21, size=4, color="black", stroke=.6, alpha=.95) +
1856
- geom_text(aes(label=row_num), size=2.0, fontface="bold", color="white") +
1857
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", drop=FALSE, limits=apt) +
1858
  labs(title="Strikes Added - Catch Depth (Side)", x="Depth / Z (ft)", y="Height / Y (ft)") +
1859
  theme_minimal() + theme(plot.title=element_text(hjust=.5, size=10, face="bold"),
@@ -1888,7 +1888,6 @@ server <- function(input, output, session) {
1888
  fill=NA, color="gray50", linewidth=.6, inherit.aes=FALSE) +
1889
  geom_polygon(data=plate_oh, aes(x=x,y=y), fill="gray95", color="black", linewidth=.8, inherit.aes=FALSE) +
1890
  geom_point(aes(fill=TaggedPitchType), shape=21, size=4, color="black", stroke=.6, alpha=.95) +
1891
- geom_text(aes(label=row_num), size=2.0, fontface="bold", color="white") +
1892
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", drop=FALSE, limits=apt) +
1893
  coord_fixed() + labs(title=ttl, x="Side (ft)", y="Depth (ft)") +
1894
  theme_minimal() + theme(plot.title=element_text(hjust=.5, size=10, face="bold"),
@@ -1904,7 +1903,6 @@ server <- function(input, output, session) {
1904
  annotate("text", x=min(d2$cpz, na.rm=TRUE)-0.1, y=3.3775, label="Zone Top", hjust=1, size=2.5, color="gray40") +
1905
  geom_vline(xintercept=0, color="gray50", linewidth=.4, linetype="dotted") +
1906
  geom_point(aes(fill=TaggedPitchType), shape=21, size=4, color="black", stroke=.6, alpha=.95) +
1907
- geom_text(aes(label=row_num), size=2.0, fontface="bold", color="white") +
1908
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", drop=FALSE, limits=apt) +
1909
  labs(title="Strikes Lost - Catch Depth (Side)", x="Depth / Z (ft)", y="Height / Y (ft)") +
1910
  theme_minimal() + theme(plot.title=element_text(hjust=.5, size=10, face="bold"),
@@ -2298,7 +2296,6 @@ server <- function(input, output, session) {
2298
  geom_segment(aes(x=-bo,xend=-bo,y=bymin,yend=bymax), color="black", linewidth=.8, inherit.aes=FALSE) +
2299
  geom_polygon(data=plate, aes(x,y), fill=NA, color="black", linewidth=.8, inherit.aes=FALSE) +
2300
  geom_point(aes(fill=TaggedPitchType, shape=block_type), size=4, color="black", stroke=.6) +
2301
- geom_text(aes(label=row_num), size=2.0, fontface="bold", color="white") +
2302
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type") +
2303
  scale_shape_manual(values=sv, name=NULL) +
2304
  coord_fixed() + labs(title="Blocking (Overhead View)", x=NULL, y=NULL) +
@@ -2339,7 +2336,6 @@ server <- function(input, output, session) {
2339
  geom_polygon(data=hp_f, aes(x=x,y=y),
2340
  fill=NA, color="gray40", linewidth=.5, inherit.aes=FALSE) +
2341
  geom_point(aes(fill=TaggedPitchType, shape=block_type), size=4, color="black", stroke=.6, na.rm=TRUE) +
2342
- geom_text(aes(label=row_num), size=2.0, fontface="bold", color="white", na.rm=TRUE) +
2343
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", labels=cl) +
2344
  scale_shape_manual(values=sv, name=NULL, labels=slb) +
2345
  coord_equal(xlim=c(-2.5,2.5), ylim=c(-1,4.5)) +
 
173
  college_join <- download_private_csv("CoastalBaseball/DefenseAppDataset", "college_join.csv")
174
 
175
  # Load Catcher 2026 data
176
+ Catcher2026 <- download_private_parquet("CoastalBaseball/DefenseAppDataset", "Catcher2026.parquet")
177
  Catcher2026 <- Catcher2026 %>%
178
  mutate(
179
  Date = as.Date(Date),
 
189
  )
190
 
191
  # Classify framing: Strike Added / Strike Lost
192
+ # Use plate location geometry (converted to feet) to determine zone status
193
+ # Zone: |PlateLocSide/12| <= 0.83083 AND PlateLocHeight/12 between 1.5 and 3.3775
194
+ CALLED_STRIKE <- c("StrikeCalled","Called Strike","strike_called")
195
+ CALLED_BALL <- c("BallCalled","Ball","ball_called","BallinDirt","BallIntentional",
196
+ "HitByPitch","AutomaticBall")
197
  Catcher2026 <- Catcher2026 %>%
198
  mutate(
199
+ pls_ft = as.numeric(PlateLocSide) / 12,
200
+ plh_ft = as.numeric(PlateLocHeight) / 12,
201
+ loc_in_zone = abs(pls_ft) <= 0.83083 & plh_ft >= 1.5 & plh_ft <= 3.3775,
202
  frame = case_when(
203
+ is.na(pls_ft) | is.na(plh_ft) ~ NA_character_,
204
+ !loc_in_zone & PitchCall %in% CALLED_STRIKE ~ "Strike Added",
205
+ loc_in_zone & PitchCall %in% CALLED_BALL ~ "Strike Lost",
206
  TRUE ~ NA_character_
207
  ),
208
  frame_numeric = case_when(
209
+ frame == "Strike Added" ~ 1,
210
+ frame == "Strike Lost" ~ -1,
211
  TRUE ~ NA_real_
212
  )
213
+ ) %>%
214
+ dplyr::select(-pls_ft, -plh_ft, -loc_in_zone)
215
 
216
  # ============================================================
217
  # PREPARE DEFENSE DATA
 
1777
  fill=NA, color="gray40", linewidth=.4, inherit.aes=FALSE) +
1778
  geom_point(aes(fill=TaggedPitchType), shape=21, size=5,
1779
  color="black", stroke=.6, alpha=.95, na.rm=TRUE) +
 
1780
  scale_fill_manual(values=pitch_colors, na.value="grey60",
1781
  name="Pitch Type", drop=FALSE, limits=apt) +
1782
  coord_equal() +
 
1839
  fill=NA, color="gray50", linewidth=.6, inherit.aes=FALSE) +
1840
  geom_polygon(data=plate_oh, aes(x=x,y=y), fill="gray95", color="black", linewidth=.8, inherit.aes=FALSE) +
1841
  geom_point(aes(fill=TaggedPitchType), shape=21, size=4, color="black", stroke=.6, alpha=.95) +
 
1842
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", drop=FALSE, limits=apt) +
1843
  coord_fixed() + labs(title=ttl, x="Side (ft)", y="Depth (ft)") +
1844
  theme_minimal() + theme(plot.title=element_text(hjust=.5, size=10, face="bold"),
 
1854
  annotate("text", x=min(d2$cpz, na.rm=TRUE)-0.1, y=3.3775, label="Zone Top", hjust=1, size=2.5, color="gray40") +
1855
  geom_vline(xintercept=0, color="gray50", linewidth=.4, linetype="dotted") +
1856
  geom_point(aes(fill=TaggedPitchType), shape=21, size=4, color="black", stroke=.6, alpha=.95) +
 
1857
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", drop=FALSE, limits=apt) +
1858
  labs(title="Strikes Added - Catch Depth (Side)", x="Depth / Z (ft)", y="Height / Y (ft)") +
1859
  theme_minimal() + theme(plot.title=element_text(hjust=.5, size=10, face="bold"),
 
1888
  fill=NA, color="gray50", linewidth=.6, inherit.aes=FALSE) +
1889
  geom_polygon(data=plate_oh, aes(x=x,y=y), fill="gray95", color="black", linewidth=.8, inherit.aes=FALSE) +
1890
  geom_point(aes(fill=TaggedPitchType), shape=21, size=4, color="black", stroke=.6, alpha=.95) +
 
1891
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", drop=FALSE, limits=apt) +
1892
  coord_fixed() + labs(title=ttl, x="Side (ft)", y="Depth (ft)") +
1893
  theme_minimal() + theme(plot.title=element_text(hjust=.5, size=10, face="bold"),
 
1903
  annotate("text", x=min(d2$cpz, na.rm=TRUE)-0.1, y=3.3775, label="Zone Top", hjust=1, size=2.5, color="gray40") +
1904
  geom_vline(xintercept=0, color="gray50", linewidth=.4, linetype="dotted") +
1905
  geom_point(aes(fill=TaggedPitchType), shape=21, size=4, color="black", stroke=.6, alpha=.95) +
 
1906
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", drop=FALSE, limits=apt) +
1907
  labs(title="Strikes Lost - Catch Depth (Side)", x="Depth / Z (ft)", y="Height / Y (ft)") +
1908
  theme_minimal() + theme(plot.title=element_text(hjust=.5, size=10, face="bold"),
 
2296
  geom_segment(aes(x=-bo,xend=-bo,y=bymin,yend=bymax), color="black", linewidth=.8, inherit.aes=FALSE) +
2297
  geom_polygon(data=plate, aes(x,y), fill=NA, color="black", linewidth=.8, inherit.aes=FALSE) +
2298
  geom_point(aes(fill=TaggedPitchType, shape=block_type), size=4, color="black", stroke=.6) +
 
2299
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type") +
2300
  scale_shape_manual(values=sv, name=NULL) +
2301
  coord_fixed() + labs(title="Blocking (Overhead View)", x=NULL, y=NULL) +
 
2336
  geom_polygon(data=hp_f, aes(x=x,y=y),
2337
  fill=NA, color="gray40", linewidth=.5, inherit.aes=FALSE) +
2338
  geom_point(aes(fill=TaggedPitchType, shape=block_type), size=4, color="black", stroke=.6, na.rm=TRUE) +
 
2339
  scale_fill_manual(values=pitch_colors, na.value="grey60", name="Pitch Type", labels=cl) +
2340
  scale_shape_manual(values=sv, name=NULL, labels=slb) +
2341
  coord_equal(xlim=c(-2.5,2.5), ylim=c(-1,4.5)) +