Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -33,12 +33,19 @@ load_portal <- function() {
|
|
| 33 |
df <- arrow::read_parquet("/app/transfer_portal.parquet")
|
| 34 |
names(df) <- tolower(names(df))
|
| 35 |
df %>%
|
| 36 |
-
rename(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
distinct(Pitcher, .keep_all = TRUE)
|
| 38 |
},
|
| 39 |
error = function(e) {
|
| 40 |
message("Portal load failed: ", e$message)
|
| 41 |
-
tibble(Pitcher
|
|
|
|
| 42 |
})
|
| 43 |
}
|
| 44 |
|
|
@@ -128,9 +135,15 @@ build_pitcher_stats <- function(df, min_pitches, scores, portal) {
|
|
| 128 |
left_join(team_lookup, by = "Pitcher") %>%
|
| 129 |
left_join(scores %>% select(Pitcher, `Stuff+`, `Location+`) %>% distinct(Pitcher, .keep_all = TRUE), by = "Pitcher") %>%
|
| 130 |
filter(Pitches >= min_pitches) %>%
|
| 131 |
-
left_join(
|
|
|
|
|
|
|
|
|
|
| 132 |
mutate(
|
| 133 |
Portal = ifelse(is.na(Portal), "No", as.character(Portal)),
|
|
|
|
|
|
|
|
|
|
| 134 |
Name = sapply(Pitcher, format_name),
|
| 135 |
Team = PitcherTeam,
|
| 136 |
`Zone%` = round(zone_n / Pitches * 100, 1),
|
|
@@ -156,9 +169,10 @@ build_pitcher_stats <- function(df, min_pitches, scores, portal) {
|
|
| 156 |
'+baseball+twitter" target="_blank">🐦 Search</a>')
|
| 157 |
) %>%
|
| 158 |
filter(!is.na(Name), trimws(Name) != "", grepl(" ", trimws(Name))) %>%
|
| 159 |
-
select(Name, Level, Team, Pitches, Portal,
|
| 160 |
-
`
|
| 161 |
-
`
|
|
|
|
| 162 |
arrange(desc(Pitches))
|
| 163 |
}
|
| 164 |
|
|
@@ -451,8 +465,8 @@ server <- function(input, output, session) {
|
|
| 451 |
dom = "lfrtip",
|
| 452 |
columnDefs = list(
|
| 453 |
list(className = "dt-left", targets = 0:1),
|
| 454 |
-
list(className = "dt-center", targets = 2:
|
| 455 |
-
list(orderable = FALSE, targets = c(
|
| 456 |
),
|
| 457 |
initComplete = JS("function(settings, json) {
|
| 458 |
$('#loading_msg').hide();
|
|
|
|
| 33 |
df <- arrow::read_parquet("/app/transfer_portal.parquet")
|
| 34 |
names(df) <- tolower(names(df))
|
| 35 |
df %>%
|
| 36 |
+
rename(
|
| 37 |
+
Pitcher = pitcher,
|
| 38 |
+
Portal = transfer,
|
| 39 |
+
ERA = era,
|
| 40 |
+
FIP = fip,
|
| 41 |
+
WHIP = whip
|
| 42 |
+
) %>%
|
| 43 |
distinct(Pitcher, .keep_all = TRUE)
|
| 44 |
},
|
| 45 |
error = function(e) {
|
| 46 |
message("Portal load failed: ", e$message)
|
| 47 |
+
tibble(Pitcher=character(), Portal=character(),
|
| 48 |
+
ERA=numeric(), FIP=numeric(), WHIP=numeric())
|
| 49 |
})
|
| 50 |
}
|
| 51 |
|
|
|
|
| 135 |
left_join(team_lookup, by = "Pitcher") %>%
|
| 136 |
left_join(scores %>% select(Pitcher, `Stuff+`, `Location+`) %>% distinct(Pitcher, .keep_all = TRUE), by = "Pitcher") %>%
|
| 137 |
filter(Pitches >= min_pitches) %>%
|
| 138 |
+
left_join(
|
| 139 |
+
portal %>% select(Pitcher, Portal, ERA, FIP, WHIP),
|
| 140 |
+
by = "Pitcher"
|
| 141 |
+
) %>%
|
| 142 |
mutate(
|
| 143 |
Portal = ifelse(is.na(Portal), "No", as.character(Portal)),
|
| 144 |
+
ERA = ifelse(Portal == "No", NA_real_, as.numeric(ERA)),
|
| 145 |
+
FIP = ifelse(Portal == "No", NA_real_, as.numeric(FIP)),
|
| 146 |
+
WHIP = ifelse(Portal == "No", NA_real_, as.numeric(WHIP)),
|
| 147 |
Name = sapply(Pitcher, format_name),
|
| 148 |
Team = PitcherTeam,
|
| 149 |
`Zone%` = round(zone_n / Pitches * 100, 1),
|
|
|
|
| 169 |
'+baseball+twitter" target="_blank">🐦 Search</a>')
|
| 170 |
) %>%
|
| 171 |
filter(!is.na(Name), trimws(Name) != "", grepl(" ", trimws(Name))) %>%
|
| 172 |
+
select(Name, Level, Team, Pitches, Portal, ERA, FIP, WHIP,
|
| 173 |
+
`FB Velo`, `Zone%`, `Strike%`, `K's`, `BB's`, `K/BB`,
|
| 174 |
+
`Whiff%`, `Chase%`, `Hard Hit%`, `Stuff+`, `Location+`,
|
| 175 |
+
`Plot`, `Twitter`) %>%
|
| 176 |
arrange(desc(Pitches))
|
| 177 |
}
|
| 178 |
|
|
|
|
| 465 |
dom = "lfrtip",
|
| 466 |
columnDefs = list(
|
| 467 |
list(className = "dt-left", targets = 0:1),
|
| 468 |
+
list(className = "dt-center", targets = 2:20),
|
| 469 |
+
list(orderable = FALSE, targets = c(19, 20))
|
| 470 |
),
|
| 471 |
initComplete = JS("function(settings, json) {
|
| 472 |
$('#loading_msg').hide();
|