Basic statistics and map POC
This commit is contained in:
parent
b69c80c37b
commit
6d1c9756ef
@ -1,6 +1,3 @@
|
||||
getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))
|
||||
)
|
||||
runApp()
|
||||
runApp()
|
||||
runApp()
|
||||
runApp()
|
||||
@ -510,3 +507,6 @@ runApp()
|
||||
runApp()
|
||||
runApp()
|
||||
runApp()
|
||||
version()
|
||||
version
|
||||
packageVersion("shiny")
|
||||
|
@ -44,7 +44,7 @@ getBalanceForTeam <- function(football_data, team) {
|
||||
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))
|
||||
rbind(c("Loss", other_sum))
|
||||
balance <- balance %>%
|
||||
mutate(n = as.numeric(as.character(n)))
|
||||
return(balance)
|
||||
|
9
Server/InteractiveMapStatistics.R
Normal file
9
Server/InteractiveMapStatistics.R
Normal file
@ -0,0 +1,9 @@
|
||||
#
|
||||
# Interactive Map Component
|
||||
#
|
||||
|
||||
interactiveMapStatistics <- function(input, output) {
|
||||
output$interactive_world_map <- renderLeaflet(
|
||||
leaflet(World) %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17)
|
||||
)
|
||||
}
|
@ -81,4 +81,11 @@ balancePercentage <- function(input, output) {
|
||||
y = cumsum(percentage) - percentage/2,
|
||||
label = percent(percentage)))
|
||||
})
|
||||
}
|
||||
|
||||
# Summary statistics
|
||||
summaryStatistics <- function(input, output) {
|
||||
output$summary_statistics <- renderTable(
|
||||
goalsScored(getFilteredResultsForTeam(input), input$team)
|
||||
)
|
||||
}
|
@ -5,15 +5,21 @@
|
||||
# Import files
|
||||
source("Server/Results.R")
|
||||
source("Server/DataProcessor.R")
|
||||
source("Server/SummaryStatistics.R")
|
||||
source("Server/InteractiveMapStatistics.R")
|
||||
|
||||
# Server logic
|
||||
server <- function(input, output) {
|
||||
# Tab 1
|
||||
balanceForTeamBarplot(input, output)
|
||||
matchesForTeam(input, output)
|
||||
summaryStatistics(input, output)
|
||||
|
||||
# Tab 2
|
||||
balanceBetweenTeams(input, output)
|
||||
balancePercentage(input, output)
|
||||
resultsWithPagination(input, output)
|
||||
|
||||
# Tab 3
|
||||
interactiveMapStatistics(input, output)
|
||||
}
|
||||
|
80
Server/SummaryStatistics.R
Normal file
80
Server/SummaryStatistics.R
Normal file
@ -0,0 +1,80 @@
|
||||
#
|
||||
# Summary statistics
|
||||
#
|
||||
|
||||
# Sum
|
||||
goalsScored <- function(matches, team) {
|
||||
home_goals <- matches %>%
|
||||
filter(home_team == team) %>%
|
||||
select(home_score) %>% sum()
|
||||
|
||||
away_goals <- matches %>%
|
||||
filter(away_team == team) %>%
|
||||
select(away_score) %>% sum()
|
||||
|
||||
goals_scored <- tribble(
|
||||
~home_goals, ~away_goals, ~overall,
|
||||
home_goals, away_goals, home_goals + away_goals
|
||||
)
|
||||
|
||||
return(goals_scored)
|
||||
}
|
||||
|
||||
goalsLost <- function(matches, team) {
|
||||
home_goals <- matches %>%
|
||||
filter(home_team != team) %>%
|
||||
select(home_score) %>% sum()
|
||||
|
||||
away_goals <- matches %>%
|
||||
filter(away_team != team) %>%
|
||||
select(away_score) %>% sum()
|
||||
|
||||
goals_lost <- tribble(
|
||||
~home_goals, ~away_goals, ~overall,
|
||||
home_goals, away_goals, home_goals + away_goals
|
||||
)
|
||||
|
||||
return(goals_scored)
|
||||
}
|
||||
|
||||
matchesNumber <- function(matches, team) {
|
||||
home_matches <- matches %>%
|
||||
filter(home_team == team) %>% nrow()
|
||||
|
||||
away_matches <- matches %>%
|
||||
filter(away_team == team) %>% nrow()
|
||||
|
||||
matches_number <- tribble(
|
||||
~home_matches, ~away_matches, ~overall,
|
||||
home_matches, away_matches, home_matches + away_matches
|
||||
)
|
||||
|
||||
return(matches_number)
|
||||
}
|
||||
|
||||
# Mean
|
||||
avgGoalsScored <- function(matches, team) {
|
||||
goals_scored <- goalsScored(matches, team)
|
||||
matches_number <- matchesNumber(matches, team)
|
||||
avg_goals_scored <- tribble(
|
||||
~home_goals_avg, ~away_goals_avg, ~overall_avg,
|
||||
goals_scored$home_goals / matches_number$home_matches,
|
||||
goals_scored$away_goals / matches_number$away_matches,
|
||||
goals_scored$overall / matches_number$overall
|
||||
)
|
||||
|
||||
return(avg_goals_scored)
|
||||
}
|
||||
|
||||
avgGoalsLost <- function(matches, team) {
|
||||
goals_lost <- goalsLost(matches, team)
|
||||
matches_number <- matchesNumber(matches, team)
|
||||
avg_goals_lost <- tribble(
|
||||
~home_goals_avg, ~away_goals_avg, ~overall_avg,
|
||||
goals_lost$home_goals / matches_number$home_matches,
|
||||
goals_lost$away_goals / matches_number$away_matches,
|
||||
goals_lost$overall / matches_number$overall
|
||||
)
|
||||
|
||||
return(avg_goals_lost)
|
||||
}
|
@ -14,4 +14,4 @@ balanceComponent <- function(pieChartSize, barplotSize)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
12
UI/InteractiveMapComponent.R
Normal file
12
UI/InteractiveMapComponent.R
Normal file
@ -0,0 +1,12 @@
|
||||
#
|
||||
# Interactive map component
|
||||
#
|
||||
|
||||
interactiveMapComponent <- function(rowSize)
|
||||
{
|
||||
fluidRow(
|
||||
column(rowSize,
|
||||
leafletOutput("interactive_world_map")
|
||||
)
|
||||
)
|
||||
}
|
24
UI/UI.R
24
UI/UI.R
@ -5,6 +5,7 @@
|
||||
# Import files
|
||||
source("UI/SidebarPanel.R")
|
||||
source("UI/BalanceComponent.R")
|
||||
source("UI/InteractiveMapComponent.R")
|
||||
|
||||
# UI
|
||||
ui <- navbarPage(
|
||||
@ -36,11 +37,13 @@ ui <- navbarPage(
|
||||
)
|
||||
),
|
||||
tabPanel(
|
||||
"Summary"
|
||||
"Summary",
|
||||
tableOutput("summary_statistics")
|
||||
|
||||
),
|
||||
tabPanel(
|
||||
"All matches",
|
||||
DT::dataTableOutput("matches_for_team")
|
||||
dataTableOutput("matches_for_team")
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -71,5 +74,20 @@ ui <- navbarPage(
|
||||
),
|
||||
|
||||
# Tab 3
|
||||
tabPanel("World map")
|
||||
tabPanel("Overall",
|
||||
fluidRow(
|
||||
column(12,
|
||||
tabsetPanel(
|
||||
tabPanel(
|
||||
"Map",
|
||||
interactiveMapComponent(12)
|
||||
),
|
||||
tabPanel(
|
||||
"Summary"
|
||||
),
|
||||
tabPanel(
|
||||
"All matches"
|
||||
)
|
||||
))
|
||||
))
|
||||
)
|
6
app.R
6
app.R
@ -14,6 +14,9 @@ library(shinyWidgets)
|
||||
library(lubridate)
|
||||
library(ggplot2)
|
||||
library(scales)
|
||||
library(tmap)
|
||||
library(tmaptools)
|
||||
library(leaflet)
|
||||
|
||||
# Load files
|
||||
source("Data/Loader.R")
|
||||
@ -21,5 +24,4 @@ source("UI/UI.R")
|
||||
source("Server/Server.R")
|
||||
|
||||
# Run the application
|
||||
shinyApp(ui = ui, server = server)
|
||||
|
||||
shinyApp(ui = ui, server = server)
|
Loading…
Reference in New Issue
Block a user