Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -50,8 +50,21 @@ build_pitcher_stats <- function(df, min_pitches) {
|
|
| 50 |
bip_n = sum(!is.na(ExitSpeed) &
|
| 51 |
!PitchCall %in% c("FoulBall","FoulBallNotFieldable",
|
| 52 |
"FoulBallFieldable","FoulTip"), na.rm=TRUE),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
.groups = "drop"
|
| 54 |
) %>%
|
|
|
|
| 55 |
filter(Pitches >= min_pitches) %>%
|
| 56 |
mutate(
|
| 57 |
Name = sapply(Pitcher, format_name),
|
|
@@ -67,6 +80,7 @@ build_pitcher_stats <- function(df, min_pitches) {
|
|
| 67 |
),
|
| 68 |
`Whiff%` = round(whiff_n / pmax(swing_n, 1) * 100, 1),
|
| 69 |
`Chase%` = round(chase_n / pmax(outzone_n, 1) * 100, 1),
|
|
|
|
| 70 |
`Hard Hit%` = round(hh_n / pmax(bip_n, 1) * 100, 1)
|
| 71 |
) %>%
|
| 72 |
# filter out blank or incomplete names
|
|
@@ -76,8 +90,8 @@ build_pitcher_stats <- function(df, min_pitches) {
|
|
| 76 |
# must have both first and last name (at least one space)
|
| 77 |
grepl(" ", trimws(Name))
|
| 78 |
) %>%
|
| 79 |
-
select(Name, Level, Team=PitcherTeam, Pitches, `
|
| 80 |
-
`K/BB`, `Whiff%`, `Chase%`, `Hard Hit%`) %>%
|
| 81 |
arrange(desc(Pitches))
|
| 82 |
}
|
| 83 |
|
|
@@ -263,7 +277,7 @@ output$pitcher_table <- renderDT({
|
|
| 263 |
order = list(list(2, "desc")),
|
| 264 |
dom = "lfrtip",
|
| 265 |
columnDefs = list(
|
| 266 |
-
list(className="dt-center", targets=2:
|
| 267 |
list(className="dt-left", targets=0:1)
|
| 268 |
)
|
| 269 |
)
|
|
|
|
| 50 |
bip_n = sum(!is.na(ExitSpeed) &
|
| 51 |
!PitchCall %in% c("FoulBall","FoulBallNotFieldable",
|
| 52 |
"FoulBallFieldable","FoulTip"), na.rm=TRUE),
|
| 53 |
+
fb_velo_sum = sum(ifelse(!is.na(RelSpeed) &
|
| 54 |
+
TaggedPitchType %in% c("Fastball","FourSeamFastBall",
|
| 55 |
+
"Four-Seam","FourSeam",
|
| 56 |
+
"Sinker","TwoSeamFastBall",
|
| 57 |
+
"OneSeamFastball","Cutter"),
|
| 58 |
+
RelSpeed, NA), na.rm=TRUE),
|
| 59 |
+
fb_velo_n = sum(!is.na(RelSpeed) &
|
| 60 |
+
TaggedPitchType %in% c("Fastball","FourSeamFastBall",
|
| 61 |
+
"Four-Seam","FourSeam",
|
| 62 |
+
"Sinker","TwoSeamFastBall",
|
| 63 |
+
"OneSeamFastball","Cutter"),
|
| 64 |
+
na.rm=TRUE),
|
| 65 |
.groups = "drop"
|
| 66 |
) %>%
|
| 67 |
+
ungroup() %>%
|
| 68 |
filter(Pitches >= min_pitches) %>%
|
| 69 |
mutate(
|
| 70 |
Name = sapply(Pitcher, format_name),
|
|
|
|
| 80 |
),
|
| 81 |
`Whiff%` = round(whiff_n / pmax(swing_n, 1) * 100, 1),
|
| 82 |
`Chase%` = round(chase_n / pmax(outzone_n, 1) * 100, 1),
|
| 83 |
+
`FB Velo` = ifelse(fb_velo_n == 0, NA_real_, round(fb_velo_sum / fb_velo_n, 1)),
|
| 84 |
`Hard Hit%` = round(hh_n / pmax(bip_n, 1) * 100, 1)
|
| 85 |
) %>%
|
| 86 |
# filter out blank or incomplete names
|
|
|
|
| 90 |
# must have both first and last name (at least one space)
|
| 91 |
grepl(" ", trimws(Name))
|
| 92 |
) %>%
|
| 93 |
+
select(Name, Level, Team=PitcherTeam, Pitches, `FB Velo`, `Zone%`, `Strike%`,
|
| 94 |
+
`K's`, `BB's`, `K/BB`, `Whiff%`, `Chase%`, `Hard Hit%`) %>%
|
| 95 |
arrange(desc(Pitches))
|
| 96 |
}
|
| 97 |
|
|
|
|
| 277 |
order = list(list(2, "desc")),
|
| 278 |
dom = "lfrtip",
|
| 279 |
columnDefs = list(
|
| 280 |
+
list(className="dt-center", targets=2:12),
|
| 281 |
list(className="dt-left", targets=0:1)
|
| 282 |
)
|
| 283 |
)
|