Skip to content

Commit

Permalink
Refactor and create website
Browse files Browse the repository at this point in the history
  • Loading branch information
topfunky committed Dec 2, 2020
1 parent 0823f49 commit 99a381d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 19 deletions.
42 changes: 42 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
baseurl = "/"
languageCode = "en-us"
title = "A Hugo website"
theme = "hugo-lithium"
googleAnalytics = ""
disqusShortname = ""
ignoreFiles = ["\\.Rmd$", "\\.Rmarkdown$", "_cache$", "\\.knit\\.md$", "\\.utf8\\.md$"]

[permalinks]
post = "/:year/:month/:day/:slug/"

[[menu.main]]
name = "About"
url = "/about/"
[[menu.main]]
name = "GitHub"
url = "https://github.com/rstudio/blogdown"
[[menu.main]]
name = "Twitter"
url = "https://twitter.com/rstudio"

[params]
description = "A website built through Hugo and blogdown."

# options for highlight.js (version, additional languages, and theme)
highlightjsVersion = "9.12.0"
highlightjsCDN = "//cdnjs.cloudflare.com/ajax/libs"
highlightjsLang = ["r", "yaml"]
highlightjsTheme = "github"

MathJaxCDN = "//cdnjs.cloudflare.com/ajax/libs"
MathJaxVersion = "2.7.5"

# path to the favicon, under "static"
favicon = "favicon.ico"

[params.logo]
url = "logo.png"
width = 50
height = 50
alt = "Logo"

53 changes: 34 additions & 19 deletions nfl_expected_wins.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ load_data <- function(start_year, end_year) {
return(data)
}

plot_wins <- function(data, start_year, end_year) {
plot_wins <- function(data, start_year, end_year, title) {
# Chart ActualWins and PredictedWins
chart <-
ggplot(data = data, aes(x = Year, y = W)) +
Expand Down Expand Up @@ -185,25 +185,14 @@ plot_wins <- function(data, start_year, end_year) {
geom_line() + geom_point() +
# Styling
scale_y_continuous(breaks = seq(0, 16, by = 4)) +
theme_minimal() + style_fonts("Sentinel", "Avenir", "InputSans") +
theme_minimal() + style_fonts("Sentinel", "Avenir", "InputSans") +
labs(
title = str_interp("NFL Predicted vs Actual Wins, ${start_year}-${end_year}"),
title = str_interp("${title}, ${start_year}-${end_year}"),
subtitle = "Predicted wins from an efficiency metrics model (red), Pythagorean wins (purple), DVOA (turquoise)",
y = "Wins",
caption = "Based on data from pro-football-reference.com and footballoutsiders.com"
) +
facet_wrap( ~ TEAM.MASCOT)

if (!dir.exists("out")) {
dir.create("out")
}

ggsave(
plot = chart,
filename = "out/wins.png",
width = 16,
height = 9
)
}

style_fonts <-
Expand Down Expand Up @@ -268,10 +257,7 @@ calculate_pythagorean_wins <- function(PF, PA) {
(1 / (1 + (PA / PF) ^ 2)) * 16
}

run_report <- function() {
training_years <- c(2015, 2019)
all_years <- c(2002, 2020)

load_data_and_build_model <- function(training_years, all_years) {
training_data <- load_data(training_years[1], training_years[2])
# Run regression model on training years
nfl_win_model <- build_regression_model(training_data)
Expand All @@ -288,8 +274,37 @@ run_report <- function() {
PythagoreanW = calculate_pythagorean_wins(PF, PA),
DVOAW = predict(dvoa_win_model, data[row_number(),])
)
return(data)
}

plot_wins(data, all_years[1], all_years[2])
run_report <- function() {
training_years <- c(2015, 2019)
all_years <- c(2002, 2020)

data <- load_data_and_build_model(training_years, all_years)
plot <- plot_wins(data, all_years[1], all_years[2], "NFL Predicted Wins vs Actual Wins")

if (!dir.exists("out")) {
dir.create("out")
}

ggsave(
plot = plot,
filename = "out/wins.png",
width = 16,
height = 9
)

# Just Patriots and Browns
data_two_teams <- data %>% filter(TEAM.MASCOT == "Patriots" | TEAM.MASCOT == "Browns")

plot2 <- plot_wins(data_two_teams, all_years[1], all_years[2], "Browns and Patriots")
ggsave(
plot = plot2,
filename = "out/wins-detail.png",
width = 16,
height = 7
)
}

run_report()
2 changes: 2 additions & 0 deletions r-nfl-expected-wins.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Website

0 comments on commit 99a381d

Please sign in to comment.