Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -169,41 +169,6 @@ scale_TimStuff <- function(raw_score, model_mean, model_sd) {
|
|
| 169 |
return(result)
|
| 170 |
}
|
| 171 |
|
| 172 |
-
calculate_primary <- function(data){
|
| 173 |
-
data <- data %>%
|
| 174 |
-
group_by(pitch_name, `Pitcher Name`, `Pitcher ID`, date) %>%
|
| 175 |
-
mutate(
|
| 176 |
-
pitch_count = n(),
|
| 177 |
-
avg_start_speed = mean(start_speed, na.rm = TRUE),
|
| 178 |
-
avg_IVB = mean(IVB, na.rm = TRUE),
|
| 179 |
-
avg_HB = mean(HB, na.rm = TRUE)
|
| 180 |
-
) %>%
|
| 181 |
-
ungroup() %>%
|
| 182 |
-
group_by(`Pitcher Name`, `Pitcher ID`, date) %>%
|
| 183 |
-
mutate(
|
| 184 |
-
is_highest_occurrence = case_when(
|
| 185 |
-
pitch_count == max(pitch_count) ~ 1,
|
| 186 |
-
TRUE ~ 0
|
| 187 |
-
)
|
| 188 |
-
) %>%
|
| 189 |
-
mutate(
|
| 190 |
-
is_highest_occurrence = case_when(
|
| 191 |
-
is_highest_occurrence == 1 & pitch_count == max(pitch_count[is_highest_occurrence == 1]) &
|
| 192 |
-
avg_start_speed == max(avg_start_speed[is_highest_occurrence == 1]) ~ 1,
|
| 193 |
-
TRUE ~ 0
|
| 194 |
-
)
|
| 195 |
-
) %>%
|
| 196 |
-
mutate(
|
| 197 |
-
primary_speed = avg_start_speed[is_highest_occurrence == 1][1],
|
| 198 |
-
primary_IVB = avg_IVB[is_highest_occurrence == 1][1],
|
| 199 |
-
primary_HB = avg_HB[is_highest_occurrence == 1][1]
|
| 200 |
-
) %>%
|
| 201 |
-
ungroup() %>%
|
| 202 |
-
mutate(primvelodiff = primary_speed - start_speed,
|
| 203 |
-
primivbdiff = primary_IVB - IVB,
|
| 204 |
-
primhbdiff = primary_HB - HB)
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
calculate_timstuff <- function(game) {
|
| 208 |
# game <- calculate_primary(game)
|
| 209 |
game <- game %>%
|
|
|
|
| 169 |
return(result)
|
| 170 |
}
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
calculate_timstuff <- function(game) {
|
| 173 |
# game <- calculate_primary(game)
|
| 174 |
game <- game %>%
|