DaveM2430 commited on
Commit
a1baf93
Β·
verified Β·
1 Parent(s): 079be9e

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +22 -7
app.R CHANGED
@@ -16,6 +16,10 @@ load_scores <- function(level) {
16
  arrow::read_parquet(path)
17
  }
18
 
 
 
 
 
19
  # ── Pitch colors ───────────────────────────────────────────────────────────────
20
  pitch_colors <- c(
21
  "Fastball" = "red", "Sinker" = "orange",
@@ -45,7 +49,7 @@ clean_pitch_type <- function(pt) {
45
  }
46
 
47
  # ── Pitcher stats ──────────────────────────────────────────────────────────────
48
- build_pitcher_stats <- function(df, min_pitches, scores) {
49
 
50
  team_lookup <- df %>%
51
  select(Pitcher, PitcherTeam) %>%
@@ -101,6 +105,8 @@ build_pitcher_stats <- function(df, min_pitches, scores) {
101
  ) %>%
102
  left_join(team_lookup, by="Pitcher") %>%
103
  left_join(scores %>% select(Pitcher, `Stuff+`, `Location+`), by="Pitcher") %>%
 
 
104
  filter(Pitches >= min_pitches) %>%
105
  mutate(
106
  Name = sapply(Pitcher, format_name),
@@ -128,7 +134,7 @@ build_pitcher_stats <- function(df, min_pitches, scores) {
128
  '+baseball+twitter" target="_blank">&#x1F426; Search</a>')
129
  ) %>%
130
  filter(!is.na(Name), trimws(Name)!="", grepl(" ",trimws(Name))) %>%
131
- select(Name, Level, Team, Pitches, `FB Velo`, `Zone%`, `Strike%`,
132
  `K's`, `BB's`, `K/BB`, `Whiff%`, `Chase%`, `Hard Hit%`,
133
  `Stuff+`, `Location+`, `Plot`, `Twitter`) %>%
134
  arrange(desc(Pitches))
@@ -183,6 +189,8 @@ ui <- fluidPage(
183
  background:#e8f0fe; border-radius:4px; padding:3px 8px; display:inline-block;
184
  }
185
  table.dataTable tbody td a:hover { background:#002147; color:white; }
 
 
186
 
187
  .modal-overlay { position:fixed; top:0; left:0; width:100%; height:100%;
188
  background:rgba(0,0,0,0.55); z-index:2000;
@@ -325,7 +333,8 @@ server <- function(input, output, session) {
325
  tryCatch({
326
  list(
327
  df = load_data(input$level),
328
- scores = load_scores(input$level)
 
329
  )
330
  }, error = function(e) {
331
  showNotification(paste("Failed to load:", e$message), type="error")
@@ -339,7 +348,8 @@ server <- function(input, output, session) {
339
  build_pitcher_stats(
340
  raw_data()$df,
341
  input$min_pitches,
342
- raw_data()$scores
 
343
  )
344
  })
345
 
@@ -385,14 +395,19 @@ server <- function(input, output, session) {
385
  dom = "lfrtip",
386
  columnDefs = list(
387
  list(className="dt-left", targets=0:1),
388
- list(className="dt-center", targets=2:16),
389
- list(orderable=FALSE, targets=c(15,16))
390
  ),
391
  initComplete = JS("function(settings, json) {
392
  $('#loading_msg').hide();
393
  }")
394
  )
395
- )
 
 
 
 
 
396
  })
397
 
398
  current_pitcher <- reactiveVal(NULL)
 
16
  arrow::read_parquet(path)
17
  }
18
 
19
+ load_portal <- function() {
20
+ arrow::read_parquet("/app/transfer_portal.parquet")
21
+ }
22
+
23
  # ── Pitch colors ───────────────────────────────────────────────────────────────
24
  pitch_colors <- c(
25
  "Fastball" = "red", "Sinker" = "orange",
 
49
  }
50
 
51
  # ── Pitcher stats ──────────────────────────────────────────────────────────────
52
+ build_pitcher_stats <- function(df, min_pitches, scores, portal) {
53
 
54
  team_lookup <- df %>%
55
  select(Pitcher, PitcherTeam) %>%
 
105
  ) %>%
106
  left_join(team_lookup, by="Pitcher") %>%
107
  left_join(scores %>% select(Pitcher, `Stuff+`, `Location+`), by="Pitcher") %>%
108
+ left_join(portal, by="Pitcher") %>%
109
+ mutate(Portal = ifelse(is.na(Portal), "No", Portal)) %>%
110
  filter(Pitches >= min_pitches) %>%
111
  mutate(
112
  Name = sapply(Pitcher, format_name),
 
134
  '+baseball+twitter" target="_blank">&#x1F426; Search</a>')
135
  ) %>%
136
  filter(!is.na(Name), trimws(Name)!="", grepl(" ",trimws(Name))) %>%
137
+ select(Name, Level, Team, Pitches, Portal, `FB Velo`, `Zone%`, `Strike%`,
138
  `K's`, `BB's`, `K/BB`, `Whiff%`, `Chase%`, `Hard Hit%`,
139
  `Stuff+`, `Location+`, `Plot`, `Twitter`) %>%
140
  arrange(desc(Pitches))
 
189
  background:#e8f0fe; border-radius:4px; padding:3px 8px; display:inline-block;
190
  }
191
  table.dataTable tbody td a:hover { background:#002147; color:white; }
192
+ .portal-yes { color:#00840D; font-weight:700; }
193
+ .portal-no { color:#aaa; font-weight:400; }
194
 
195
  .modal-overlay { position:fixed; top:0; left:0; width:100%; height:100%;
196
  background:rgba(0,0,0,0.55); z-index:2000;
 
333
  tryCatch({
334
  list(
335
  df = load_data(input$level),
336
+ scores = load_scores(input$level),
337
+ portal = load_portal()
338
  )
339
  }, error = function(e) {
340
  showNotification(paste("Failed to load:", e$message), type="error")
 
348
  build_pitcher_stats(
349
  raw_data()$df,
350
  input$min_pitches,
351
+ raw_data()$scores,
352
+ raw_data()$portal
353
  )
354
  })
355
 
 
395
  dom = "lfrtip",
396
  columnDefs = list(
397
  list(className="dt-left", targets=0:1),
398
+ list(className="dt-center", targets=2:17),
399
+ list(orderable=FALSE, targets=c(16,17))
400
  ),
401
  initComplete = JS("function(settings, json) {
402
  $('#loading_msg').hide();
403
  }")
404
  )
405
+ ) %>%
406
+ formatStyle(
407
+ "Portal",
408
+ color = styleEqual(c("Yes","No"), c("#00840D","#aaaaaa")),
409
+ fontWeight = styleEqual(c("Yes","No"), c("700","400"))
410
+ )
411
  })
412
 
413
  current_pitcher <- reactiveVal(NULL)