TimStats commited on
Commit
03c3978
·
verified ·
1 Parent(s): 37d646c

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +98 -73
app.R CHANGED
@@ -1,12 +1,3 @@
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)
@@ -14,75 +5,109 @@ 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.",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
- verbatimTextOutput("stuff")
48
-
49
- )
50
  )
 
51
  )
52
 
53
  # Define server logic required to draw a histogram
54
  server <- function(input, output) {
55
-
56
- output$stuff <- renderText({
57
- data <- as.data.frame(5)
58
- setnames(data,"5","start_speed")
59
- data$start_speed <- input$velo
60
- data$IVB <- input$ivb
61
- if(input$phand == "L"){
62
- data$HB <- input$hb * -1
63
- }
64
- else{
65
- data$HB <- input$hb
66
- }
67
- data$EAA <- input$ext / 6.3
68
- if(input$phand == "L"){
69
- data$x0 <- input$x0 * -1
70
- }
71
- else{
72
- data$x0 <- input$x0
73
- }
74
- data$z0 <- input$z0
75
- data$spin_rate <- input$spinrate
76
- data$SADiff <- input$spinaxisdiff
77
-
78
- data <- as.matrix(data)
79
- FBMod <- xgb.load('FB.model')
80
- prediction <-predict(FBMod,data)
81
- TimStuff <- (50 - (prediction - -0.0011801)/ 0.007989927 * 10)
82
- # FBMod <- xgb.load("FB.model")
83
- # vip(FBMod)
84
- return(paste("TimStuff: ",TimStuff, "20-80 Scale, 50 is Average 1 SD is 10",sep = "\n"))
85
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
87
 
88
  # Run the application
 
 
 
 
 
 
 
 
 
 
1
  library(shiny)
2
  library(dplyr)
3
  library(data.table)
 
5
  library(caret)
6
  # Define UI for application that draws a histogram
7
  ui <- fluidPage(
8
+
9
+ # Application title
10
+ titlePanel("TimStuff Fastball/Offspeed Calculator"),
11
+
12
+ # Sidebar with a slider input for number of bins
13
+ sidebarLayout(
14
+ sidebarPanel(
15
+ selectInput("pitch","Pitch Type",c("Fastball","Offspeed")),
16
+ selectInput("phand",
17
+ "Hand",
18
+ c("R","L")),
19
+ numericInput("velo",
20
+ "Velocity /mph",90),
21
+ numericInput("ivb",
22
+ "Induced Vertical Break (IVB) /in.",16),
23
+ numericInput("hb",
24
+ "Horizontal Break (HB) /in. (Pitcher's Perspective)",6),
25
+ numericInput("spinrate",
26
+ "Spin Rate /rpm",2300),
27
+ numericInput("ext",
28
+ "Extension /ft",6),
29
+ numericInput("spinaxisdiff",
30
+ "Spin Axis Difference (-180 - 180) /degrees",0),
31
+ numericInput("x0","Horizntal Release Point /ft. (Batter's Perspective)",0),
32
+ numericInput("z0","Vertical Release Point /ft. (Batter's Perspective)", 0),
33
+
34
+
35
+ ),
36
+
37
+ # Show a plot of the generated distribution
38
+ mainPanel(
39
+ verbatimTextOutput("stuff")
40
+
41
  )
42
+ )
43
  )
44
 
45
  # Define server logic required to draw a histogram
46
  server <- function(input, output) {
47
+ observeEvent(input$pitch,{
48
+ if(input$pitch == "Offspeed"){
49
+ output$stuff <- renderText({
50
+ data <- as.data.frame(5)
51
+ setnames(data,"5","start_speed")
52
+ data$start_speed <- input$velo
53
+ data$IVB <- input$ivb
54
+ if(input$phand == "L"){
55
+ data$HB <- input$hb * -1
56
+ }
57
+ else{
58
+ data$HB <- input$hb
59
+ }
60
+ data$EAA <- input$ext / 6.3
61
+ if(input$phand == "L"){
62
+ data$x0 <- input$x0 * -1
63
+ }
64
+ else{
65
+ data$x0 <- input$x0
66
+ }
67
+ data$z0 <- input$z0
68
+ data$spin_rate <- input$spinrate
69
+ data$SADiff <- input$spinaxisdiff
70
+
71
+ data <- as.matrix(data)
72
+ OffMod <- xgb.load('Off.model')
73
+ prediction <-predict(OffMod,data)
74
+ TimStuff <- (50 - (prediction - -0.002239657)/ 0.01043216 * 10)
75
+
76
+ return(paste("TimStuff: ",TimStuff, "20-80 Scale, 50 is Average 1 SD is 10",sep = "\n"))
77
+ })
78
+ }
79
+ if(input$pitch == "Fastball"){
80
+ output$stuff <- renderText({
81
+ data <- as.data.frame(5)
82
+ setnames(data,"5","start_speed")
83
+ data$start_speed <- input$velo
84
+ data$IVB <- input$ivb
85
+ if(input$phand == "L"){
86
+ data$HB <- input$hb * -1
87
+ }
88
+ else{
89
+ data$HB <- input$hb
90
+ }
91
+ data$EAA <- input$ext / 6.3
92
+ if(input$phand == "L"){
93
+ data$x0 <- input$x0 * -1
94
+ }
95
+ else{
96
+ data$x0 <- input$x0
97
+ }
98
+ data$z0 <- input$z0
99
+ data$spin_rate <- input$spinrate
100
+ data$SADiff <- input$spinaxisdiff
101
+
102
+ data <- as.matrix(data)
103
+ FBMod <- xgb.load('FB.model')
104
+ prediction <-predict(FBMod,data)
105
+ TimStuff <- (50 - (prediction - -0.0011801)/ 0.007989927 * 10)
106
+
107
+ return(paste("TimStuff: ",TimStuff, "20-80 Scale, 50 is Average 1 SD is 10",sep = "\n"))
108
+ })
109
+ }
110
+ })
111
  }
112
 
113
  # Run the application