Skip to content

Commit

Permalink
fixing a ton of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
benny-dreyf committed Feb 19, 2023
1 parent 8f6181f commit 6529c5e
Show file tree
Hide file tree
Showing 6 changed files with 3,944 additions and 95 deletions.
38 changes: 0 additions & 38 deletions R/dvoa_weekly.R

This file was deleted.

34 changes: 21 additions & 13 deletions R/gridiron_ou_all.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
#' After using oddsmakr::odds_consensus to scrape data and you've compiled it into a dataframe, you can plot a time-series of over-under vs. % share of bet volume for each team by game using this function
#'
#' @param dat dataframe or tibble containing public consensus share of bets and over-under for multiples games for a given week pulled more than once by odds_consensus function from oddsmaker package
#' @param dataset dataframe or tibble containing public consensus share of bets and over-under for multiples games for a given week pulled more than once by odds_consensus function from oddsmaker package
#' @param week_no the week number to visualize
#'
#' @return a patchwork plot showing all spread and spread_share for each game
#'
#' @example None
#'
#' @export
#'
gridiron_ou<-function(dat){
dat<- dat |> dplyr::mutate(id= as.numeric(id), team= stringr::str_extract(team, '^([A-Z]{3}|[A-Z]{2})'))
# ou_colors<- c('Over' = 'blue', 'Under' = 'red')
# ou_colors<- ou_colors[unique(dat$ou)]
p<- function(d){
z<- ggplot2::ggplot(data = d, mapping = ggplot2::aes(x= id, y= ou_share, color= ou)) +
gridiron_ou<-function(dataset, week_no){
dataset<- dataset |>
dplyr::mutate(id= as.numeric(id), team= stringr::str_extract(team, '^([A-Z]{3}|[A-Z]{2})')) |>
filter(week== week_no)
# matches<-master |>
# filter(week== week_no) |>
# select(matchup) |>
# unique() |>
# c()
p<- function(dataset){
z<- ggplot2::ggplot(data = dataset, mapping = ggplot2::aes(x= date_pulled, y= ou_share, color= ou)) +
ggplot2::geom_line() +
ggplot2::geom_text(aes(label= ou_target), vjust= -1, size = 1.5, show.legend = F) +
ggplot2::geom_text(ggplot2::aes(label= ou_target), vjust= -1, size = 1.5, show.legend = F) +
ggplot2::theme(panel.background = element_rect(fill= 'white'),
title = element_text(size= 8),
axis.text = element_text(size= 6),
axis.text.x = ggplot2::element_text(angle = 90, size = 8),
panel.grid.major.y= element_line(color= 'grey'),
panel.grid.major.x= element_blank(),
legend.key = element_rect(fill = "white")) +
ggplot2::labs(title= 'Oddsshark % Share of Bet Volume & Over/Under', subtitle= unique(d[5]), x= 'Oddsshark Site Scrape #', y= '% Share of Bet Volume') +
ggplot2::scale_x_continuous(breaks= seq(min(d$id), max(d$id), 1)) +
ggplot2::scale_y_continuous(breaks = seq(0, 1, .1), limits= c(0,1), labels = scales::label_percent(accuracy= 1))
ggplot2::labs(title= 'Oddsshark % Share of Bets @ OU', subtitle= unique(dataset[10]), x= 'Datetime of Data Pull', y= '% Share of Bet Volume', color= 'Over-Under') +
ggplot2::scale_x_datetime(date_breaks= '12 hours', date_labels = '%m/%d/%y %H') +
ggplot2::scale_y_continuous(breaks = seq(0, 1, .1), limits= c(0,1), labels = scales::label_percent(accuracy= 1)) +
ggplot2::scale_color_manual(values= c('red', 'blue'))
return(z)
}
f<- dat %>%
split(f = dat$game_num) %>%
f<- dataset %>%
split(f = dataset$matchup) %>%
purrr::map(p) %>%
patchwork::wrap_plots()
return(f)
Expand Down
43 changes: 0 additions & 43 deletions R/pfr_scores.R

This file was deleted.

1 change: 0 additions & 1 deletion R/picks_consensus.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ picks_consensus<-function(season){
game_time > '2023-01-11' & game_time < '2023-01-18' ~ 'week_19',
game_time > '2023-01-18' & game_time < '2023-01-25' ~ 'week_20',
game_time > '2023-01-25' & game_time < '2023-02-01' ~ 'week_21',
# game_time > '2023-02-01' & game_time < '2023-02-08' ~ 'week_22',
game_time > '2023-02-08' & game_time < '2023-02-15' ~ 'week_22',
)) |>
dplyr::select(-2)
Expand Down
74 changes: 74 additions & 0 deletions app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# weekly data
df<- readr::read_csv('master_2022.csv') |>
dplyr::arrange(week, date_pulled)


# UI creation ----
ui<- fluidPage(titlePanel('Weekly Legs'),

shiny::sidebarLayout(
shiny::sidebarPanel(
width= 3,
shiny::h1('Pick a Week'),
shiny::selectInput(
inputId = "week_select",
label = "Select a Week",
choices = unique(df$week),
selected = 1),

shiny::h2('Pick a Game'),
shiny::selectInput(
inputId = "game_select",
label = "Select a Game",
choices = NULL)),

shiny::mainPanel(
shiny::tabsetPanel(
shiny::tabPanel(
plotly::plotlyOutput('gameplot', width = 800, height = 500),
div(style = "height:50px"),
plotly::plotlyOutput('ou_plot', width = 800, height = 500),
div(style = "height:50px"))
)
)
)
)



# build app ----

server<- function(input, output){

week_select <- reactive({
dplyr::filter(df, week == input$week_select)
})
observeEvent(week_select(), {
choices <- unique(week_select()$matchup)
updateSelectInput(inputId = "game_select", choices = choices)
})

game <- reactive({
shiny::req(input$game_select)
dplyr::filter(week_select(), matchup == input$game_select)
})

output$gameplot<- plotly::renderPlotly({
req(input$game_select)
week_select() |>
dplyr::filter(matchup == input$game_select) |>
oddsmaker::pick_share_plot()
})

output$ou_plot<- plotly::renderPlotly({
req(input$game_select)
week_select() |>
dplyr::filter(matchup == input$game_select) |>
oddsmaker::ou_share_plot()
})

}

# run the app ----

shiny::shinyApp(ui= ui, server= server)
Loading

0 comments on commit 6529c5e

Please sign in to comment.