diff --git a/.RData b/.RData index 62140d2..07ef8dc 100644 Binary files a/.RData and b/.RData differ diff --git a/.Rhistory b/.Rhistory index bd03f97..ed895b1 100644 --- a/.Rhistory +++ b/.Rhistory @@ -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) diff --git a/Data/Loader.R b/Data/Loader.R index 29d6919..b61a853 100644 --- a/Data/Loader.R +++ b/Data/Loader.R @@ -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 %>% diff --git a/Server/DataProcessor.R b/Server/DataProcessor.R index 3e7f35b..69ec4c4 100644 --- a/Server/DataProcessor.R +++ b/Server/DataProcessor.R @@ -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( diff --git a/Server/Results.R b/Server/Results.R index 83b92e6..737b291 100644 --- a/Server/Results.R +++ b/Server/Results.R @@ -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))) }) -} \ No newline at end of file +} + +# Top teams barplot \ No newline at end of file diff --git a/Server/Server.R b/Server/Server.R index 8c9ee7c..7c3472f 100644 --- a/Server/Server.R +++ b/Server/Server.R @@ -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) diff --git a/UI/SidebarPanel.R b/UI/SidebarPanel.R index 51455e4..1d16c6b 100644 --- a/UI/SidebarPanel.R +++ b/UI/SidebarPanel.R @@ -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) ) ) ) diff --git a/UI/UI.R b/UI/UI.R index ba12511..a91b198 100644 --- a/UI/UI.R +++ b/UI/UI.R @@ -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" + ) + ) + ) ) ), diff --git a/app.R b/app.R index 821e265..3670ba4 100644 --- a/app.R +++ b/app.R @@ -10,6 +10,7 @@ library(shiny) library(dplyr) library(shinythemes) +library(shinyWidgets) library(lubridate) library(ggplot2) library(scales)