TimStats commited on
Commit
0edede0
·
verified ·
1 Parent(s): 4afb549

Upload 2 files

Browse files
Files changed (2) hide show
  1. FB.model +3 -0
  2. app.R +88 -58
FB.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0634ac1f0f8e9b37ea215740d541a0f5ca48cec0c7f048d655ac204de20ea2be
3
+ size 2442683
app.R CHANGED
@@ -1,58 +1,88 @@
1
- library(shiny)
2
- library(bslib)
3
- library(dplyr)
4
- library(ggplot2)
5
-
6
- df <- readr::read_csv("penguins.csv")
7
- # Find subset of columns that are suitable for scatter plot
8
- df_num <- df |> select(where(is.numeric), -Year)
9
-
10
- ui <- page_sidebar(
11
- theme = bs_theme(bootswatch = "minty"),
12
- title = "Penguins explorer",
13
- sidebar = sidebar(
14
- varSelectInput("xvar", "X variable", df_num, selected = "Bill Length (mm)"),
15
- varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),
16
- checkboxGroupInput("species", "Filter by species",
17
- choices = unique(df$Species), selected = unique(df$Species)
18
- ),
19
- hr(), # Add a horizontal rule
20
- checkboxInput("by_species", "Show species", TRUE),
21
- checkboxInput("show_margins", "Show marginal plots", TRUE),
22
- checkboxInput("smooth", "Add smoother"),
23
- ),
24
- plotOutput("scatter")
25
- )
26
-
27
- server <- function(input, output, session) {
28
- subsetted <- reactive({
29
- req(input$species)
30
- df |> filter(Species %in% input$species)
31
- })
32
-
33
- output$scatter <- renderPlot(
34
- {
35
- p <- ggplot(subsetted(), aes(!!input$xvar, !!input$yvar)) +
36
- theme_light() +
37
- list(
38
- theme(legend.position = "bottom"),
39
- if (input$by_species) aes(color = Species),
40
- geom_point(),
41
- if (input$smooth) geom_smooth()
42
- )
43
-
44
- if (input$show_margins) {
45
- margin_type <- if (input$by_species) "density" else "histogram"
46
- p <- p |> ggExtra::ggMarginal(
47
- type = margin_type, margins = "both",
48
- size = 8, groupColour = input$by_species, groupFill = input$by_species
49
- )
50
- }
51
-
52
- p
53
- },
54
- res = 100
55
- )
56
- }
57
-
58
- shinyApp(ui, server)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # This is a Shiny web application. You can run the application by clicking
3
+ # the 'Run App' button above.
4
+ #
5
+ # Find out more about building applications with Shiny here:
6
+ #
7
+ # https://shiny.posit.co/
8
+ #
9
+
10
+ library(shiny)
11
+ library(dplyr)
12
+ library(data.table)
13
+ library(xgboost)
14
+ library(caret)
15
+ # Define UI for application that draws a histogram
16
+ ui <- fluidPage(
17
+
18
+ # Application title
19
+ titlePanel("TimStuff Fastball Calculator"),
20
+
21
+ # Sidebar with a slider input for number of bins
22
+ sidebarLayout(
23
+ sidebarPanel(
24
+ selectInput("phand",
25
+ "Hand",
26
+ c("R","L")),
27
+ numericInput("velo",
28
+ "Velocity /mph",90),
29
+ numericInput("ivb",
30
+ "Induced Vertical Break (IVB) /in. (IVB)",16),
31
+ numericInput("hb",
32
+ "Horizontal Break (HB) /in. (Pitcher's Perspective)",6),
33
+ numericInput("spinrate",
34
+ "Spin Rate /rpm",2300),
35
+ numericInput("ext",
36
+ "Extension /ft",6),
37
+ numericInput("spinaxisdiff",
38
+ "Spin Axis Difference (-180 - 180) /degrees",0),
39
+ numericInput("x0","Horizntal Release Point /ft. (Batter's Perspective)",0),
40
+ numericInput("z0","Vertical Release Point /ft. (Batter's Perspective)", 0),
41
+
42
+
43
+ ),
44
+
45
+ # Show a plot of the generated distribution
46
+ mainPanel(
47
+ textOutput("distPlot")
48
+ )
49
+ )
50
+ )
51
+
52
+ # Define server logic required to draw a histogram
53
+ server <- function(input, output) {
54
+
55
+ output$distPlot <- renderText({
56
+ data <- as.data.frame(5)
57
+ setnames(data,"5","start_speed")
58
+ data$start_speed <- input$velo
59
+ data$IVB <- input$ivb
60
+ if(input$phand == "L"){
61
+ data$HB <- input$hb * -1
62
+ }
63
+ else{
64
+ data$HB <- input$hb
65
+ }
66
+ data$EAA <- input$ext / 6.3
67
+ if(input$phand == "L"){
68
+ data$x0 <- input$x0 * -1
69
+ }
70
+ else{
71
+ data$x0 <- input$x0
72
+ }
73
+ data$z0 <- input$z0
74
+ data$spin_rate <- input$spinrate
75
+ data$SADiff <- input$spinaxisdiff
76
+
77
+ data <- as.matrix(data)
78
+
79
+ prediction <-predict(FBMod,data)
80
+ TimStuff <- (50 - (prediction - -0.0004397118)/ 0.2180433 * 10)
81
+ # FBMod <- xgb.load("FB.model")
82
+ # vip(FBMod)
83
+ return(TimStuff)
84
+ })
85
+ }
86
+
87
+ # Run the application
88
+ shinyApp(ui = ui, server = server)