Added balance for one team

This commit is contained in:
Jakub Wajs 2019-05-19 01:33:04 +02:00
parent 278bd6ca8c
commit 553164e6bf
5 changed files with 50 additions and 10 deletions

View File

@ -37,3 +37,15 @@ getBalancePercentage <- function(balance) {
balancePerc <- balance %>%
mutate(percentage = n/sum(.$n))
}
getBalanceForTeam <- function(football_data, team) {
balance_full <- football_data %>%
count(winner, sort = TRUE)
balance <- balance_full[(balance_full$winner %in% c(team, "Draw")),]
other_sum <- sum(balance_full[!(balance_full$winner %in% c(team, "Draw")),]$n)
balance <- balance %>%
rbind(c("Other", other_sum))
balance <- balance %>%
mutate(n = as.numeric(as.character(n)))
return(balance)
}

View File

@ -5,7 +5,7 @@
# Results with pagination
getFilteredResultsForTeam <- function(input) {
getMatchesForTeam(football_data, input$team) %>%
filterByDate(as_date(input$date_range[1]), as_date(input$date_range[2]))
filterByDate(as_date(input$date_range_for_team[1]), as_date(input$date_range_for_team[2]))
}
getFilteredResults <- function(input) {
@ -38,10 +38,6 @@ matchesForTeam <- function(input, output) {
}
# Balance
getBalanceData <- function(input) {
getBalance(getFilteredResults(input))
}
balanceBetweenTeams <- function(input, output) {
output$balance <- renderPlot({
ggplot(getFilteredResults(input), aes(x=as.factor(winner),
@ -52,7 +48,27 @@ balanceBetweenTeams <- function(input, output) {
})
}
getBalanceDataForTeamBarplot <- function(input) {
return(
getBalanceForTeam(getFilteredResultsForTeam(input), input$team)
)
}
balanceForTeamBarplot <- function(input, output) {
output$balance_for_team <- renderPlot({
ggplot(getBalanceDataForTeamBarplot(input),
aes(x=as.factor(winner), y=as.factor(n))) +
geom_bar(stat = "identity", fill = rgb(0.6, 0.1, 0.4, 0.7)) +
theme_minimal() +
labs(x = "", y = "Matches balance for")
})
}
# Balance percentage
getBalanceData <- function(input) {
getBalance(getFilteredResults(input))
}
balancePercentage <- function(input, output) {
output$balancePieChart <- renderPlot({
ggplot(getBalancePercentage(getBalanceData(input))) +
@ -66,5 +82,3 @@ balancePercentage <- function(input, output) {
label = percent(percentage)))
})
}
# Top teams barplot

View File

@ -9,6 +9,7 @@ source("Server/DataProcessor.R")
# Server logic
server <- function(input, output) {
# Tab 1
balanceForTeamBarplot(input, output)
matchesForTeam(input, output)
# Tab 2

View File

@ -47,7 +47,7 @@ teamSidebarPanel <- function() {
selectInput("team",
"Choose team:",
teams),
dateRangeInput("date_range",
dateRangeInput("date_range_for_team",
"Date range:",
start = min_date_from,
end = max_date_to,

15
UI/UI.R
View File

@ -20,7 +20,20 @@ ui <- navbarPage(
column(9,
tabsetPanel(
tabPanel(
"Charts"
"Charts",
h2("Matches balance charts"),
fluidRow(
column(6,
wellPanel(
plotOutput("balance_for_team")
)
),
column(6,
wellPanel(
verbatimTextOutput("Test")
)
)
)
),
tabPanel(
"Summary"