Added team matches list

This commit is contained in:
Jakub Wajs 2019-05-19 00:07:35 +02:00
parent 7d66641386
commit 278bd6ca8c
9 changed files with 146 additions and 46 deletions

BIN
.RData

Binary file not shown.

View File

@ -1,32 +1,3 @@
if(match_row["home_score"] > match_row["away_score"]) {
return(match_row["home_team"])
}
else if(match_row["home_score"] < match_row["away_score"]) {
return(match_row["away_team"])
}
else {
return("Draw")
}
}
get_winner_name(football_data[0])
head(football_data)
get_winner_name(football_data[1])
football_data[1]
football_data[, 1]
top_n(football_data, 1)
football_data %>% slice(1)
football_data %>% slice(1) %>% get_winner_name()
football_data %>% select(2:5) %>% get_winner_name()
football_data %>% select(2:5)
football_data %>% select(2:5) %>% mutate(get_winner_name())
football_data %>% select(2:5) %>% mutate(get_winner_name(.))
football_data %>% select(2:5) %>% mutate(result = get_winner_name(.))
football_data %>% select(2:5) %>% rowwise() %>% mutate(result = get_winner_name(.))
warnings()
football_data %>% select(2:5) %>% rowwise() %>% mutate(result = get_winner_name())
football_data %>%
select(2:5) %>% mutate(get_winner_name(home_score, away_score, home_team, away_team))
get_winner_name <- function(home_score, away_score, home_team, away_team) {
if(home_score > away_score) { if(home_score > away_score) {
return(home_team) return(home_team)
} }
@ -510,3 +481,32 @@ runApp()
runApp() runApp()
runApp() runApp()
runApp() runApp()
shiny::runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
c(home_teams$home_team, away_teams$away_team) %>%
unique()
c(home_teams$home_team, away_teams$away_team)
c(home_teams, away_teams)
c(home_teams, away_teams) %>% unique()
runApp()
full_join(home_teams, away_teams) %>%
unique()
left_join(home_teams, away_teams, by = home_teams$"home_team" == away_teams$"away_team")
home_teams %>% full_join(away_teams)
home_teams %>% full_join(away_teams, by = .$home_team == away_teams$away_team)
home_teams %>% full_join(away_teams, by = .$home_team == away_teams$home_team)
home_teams
away_teams
as.list(home_teams)
mapply(home_teams, away_teams, SIMPLIFY = false)
merge.data.frame(home_teams, away_teams)
merge.data.frame(as.data.frame(home_teams), as.data.frame(away_teams))
merge(home_teams, away_teams)
merge(home_teams$home_team, away_teams$away_team)
home_teams %>% mutate(home_team = away_team)

View File

@ -12,7 +12,7 @@ get_winner_name <- function(match_row) {
} }
# Load data # Load data
football_data <- as_tibble(read.csv("results.csv")) %>% football_data <- as_tibble(read.csv("results.csv", encoding = "UTF-8")) %>%
mutate(winner = apply(., 1, get_winner_name)) mutate(winner = apply(., 1, get_winner_name))
# Prepare data # Prepare data
@ -22,6 +22,12 @@ home_teams <- football_data %>%
away_teams <- football_data %>% away_teams <- football_data %>%
select("away_team") %>% unique() select("away_team") %>% unique()
teams <- merge(home_teams, away_teams,
by.x = "home_team", by.y = "away_team")
tournament_types <- football_data %>%
pull(tournament) %>% unique() %>% sort()
getDateFromData <- function(matchesData) { getDateFromData <- function(matchesData) {
return( return(
matchesData %>% matchesData %>%

View File

@ -11,6 +11,13 @@ getMatchesList <- function(matchesData, first_team, second_team) {
) )
} }
getMatchesForTeam <- function(matchesData, team) {
return(
matchesData %>%
filter(home_team == team | away_team == team)
)
}
# Mathes filters # Mathes filters
filterByDate <- function(matchesData, dateFrom, dateTo) { filterByDate <- function(matchesData, dateFrom, dateTo) {
return( return(

View File

@ -3,6 +3,11 @@
# #
# Results with pagination # Results with pagination
getFilteredResultsForTeam <- function(input) {
getMatchesForTeam(football_data, input$team) %>%
filterByDate(as_date(input$date_range[1]), as_date(input$date_range[2]))
}
getFilteredResults <- function(input) { getFilteredResults <- function(input) {
getMatchesList(football_data, input$first_team, input$second_team) %>% getMatchesList(football_data, input$first_team, input$second_team) %>%
filterByDate(as_date(input$date_range[1]), as_date(input$date_range[2])) filterByDate(as_date(input$date_range[1]), as_date(input$date_range[2]))
@ -20,6 +25,18 @@ resultsWithPagination <- function(input, output) {
) )
} }
matchesForTeam <- function(input, output) {
output$matches_for_team <- DT::renderDataTable(
getFilteredResultsForTeam(input),
extensions = 'Buttons',
options = list(
lengthMenu = list(c(5, 10, -1), c('5', '10', '20', 'All')),
pageLength = 20,
searching = FALSE
)
)
}
# Balance # Balance
getBalanceData <- function(input) { getBalanceData <- function(input) {
getBalance(getFilteredResults(input)) getBalance(getFilteredResults(input))
@ -44,6 +61,10 @@ balancePercentage <- function(input, output) {
stat = "identity") + stat = "identity") +
coord_polar("y", start = 0) + coord_polar("y", start = 0) +
theme_void() + theme_void() +
geom_text(aes(x=1, y = cumsum(percentage) - percentage/2, label = percent(percentage))) geom_text(aes(x=1,
y = cumsum(percentage) - percentage/2,
label = percent(percentage)))
}) })
} }
# Top teams barplot

View File

@ -8,6 +8,10 @@ source("Server/DataProcessor.R")
# Server logic # Server logic
server <- function(input, output) { server <- function(input, output) {
# Tab 1
matchesForTeam(input, output)
# Tab 2
balanceBetweenTeams(input, output) balanceBetweenTeams(input, output)
balancePercentage(input, output) balancePercentage(input, output)
resultsWithPagination(input, output) resultsWithPagination(input, output)

View File

@ -1,7 +1,6 @@
# Teams sidebar panel # Teams sidebar panel
teamsSidebarPanel <- function() teamsSidebarPanel <- function() {
{
fluidRow( fluidRow(
column(12, column(12,
h2("Teams comparison"), h2("Teams comparison"),
@ -15,11 +14,45 @@ teamsSidebarPanel <- function()
"Second team:", "Second team:",
away_teams), away_teams),
dateRangeInput("date_range", dateRangeInput("date_range",
"Date range:", "Date range:",
start = min_date_from, start = min_date_from,
end = max_date_to, end = max_date_to,
min = min_date_from, min = min_date_from,
max = max_date_to) max = max_date_to),
dropdownButton(
label = "Tournament types",
circle = FALSE,
#radioButtons("tournament_all",
# "Select:",
# choices = c("All", "None"),
# selected = "All"),
checkboxGroupInput("tournament_type",
"Tournament type:",
choices = tournament_types,
selected = tournament_types)
)
)
)
)
)
}
teamSidebarPanel <- function() {
fluidRow(
column(12,
h2("Team statistics"),
p("Choose your favorite team."),
fluidRow(
column(12,
selectInput("team",
"Choose team:",
teams),
dateRangeInput("date_range",
"Date range:",
start = min_date_from,
end = max_date_to,
min = min_date_from,
max = max_date_to)
) )
) )
) )

42
UI/UI.R
View File

@ -12,19 +12,47 @@ ui <- navbarPage(
theme = shinytheme("united"), theme = shinytheme("united"),
# Tab 1 # Tab 1
tabPanel("Team statistics"), tabPanel("Team statistics",
fluidRow(
column(3,
teamSidebarPanel()
),
column(9,
tabsetPanel(
tabPanel(
"Charts"
),
tabPanel(
"Summary"
),
tabPanel(
"All matches",
DT::dataTableOutput("matches_for_team")
)
)
)
)),
# Tab 2 # Tab 2
tabPanel("Teams comparison", tabPanel("Teams comparison",
fluidRow( fluidRow(
column(4, column(3,
teamsSidebarPanel() teamsSidebarPanel()
), ),
column(8, column(9,
balanceComponent(6, 6), tabsetPanel(
fluidRow( tabPanel(
DT::dataTableOutput("results_pagination") "Charts",
) balanceComponent(6, 6),
fluidRow(
DT::dataTableOutput("results_pagination")
)
),
tabPanel(
"Summary"
)
)
) )
) )
), ),

1
app.R
View File

@ -10,6 +10,7 @@
library(shiny) library(shiny)
library(dplyr) library(dplyr)
library(shinythemes) library(shinythemes)
library(shinyWidgets)
library(lubridate) library(lubridate)
library(ggplot2) library(ggplot2)
library(scales) library(scales)