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) {
return(home_team)
}
@ -510,3 +481,32 @@ 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
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))
# Prepare data
@ -22,6 +22,12 @@ home_teams <- football_data %>%
away_teams <- football_data %>%
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) {
return(
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
filterByDate <- function(matchesData, dateFrom, dateTo) {
return(

View File

@ -3,6 +3,11 @@
#
# 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) {
getMatchesList(football_data, input$first_team, input$second_team) %>%
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
getBalanceData <- function(input) {
getBalance(getFilteredResults(input))
@ -44,6 +61,10 @@ balancePercentage <- function(input, output) {
stat = "identity") +
coord_polar("y", start = 0) +
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 <- function(input, output) {
# Tab 1
matchesForTeam(input, output)
# Tab 2
balanceBetweenTeams(input, output)
balancePercentage(input, output)
resultsWithPagination(input, output)

View File

@ -1,7 +1,6 @@
# Teams sidebar panel
teamsSidebarPanel <- function()
{
teamsSidebarPanel <- function() {
fluidRow(
column(12,
h2("Teams comparison"),
@ -15,11 +14,45 @@ teamsSidebarPanel <- function()
"Second team:",
away_teams),
dateRangeInput("date_range",
"Date range:",
start = min_date_from,
end = max_date_to,
min = min_date_from,
max = max_date_to)
"Date range:",
start = min_date_from,
end = max_date_to,
min = min_date_from,
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"),
# 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
tabPanel("Teams comparison",
fluidRow(
column(4,
column(3,
teamsSidebarPanel()
),
column(8,
balanceComponent(6, 6),
fluidRow(
DT::dataTableOutput("results_pagination")
)
column(9,
tabsetPanel(
tabPanel(
"Charts",
balanceComponent(6, 6),
fluidRow(
DT::dataTableOutput("results_pagination")
)
),
tabPanel(
"Summary"
)
)
)
)
),

1
app.R
View File

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