Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix/old la data #7

Merged
merged 6 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions R/enabler2_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ enabler2_tab <- function() {
condition = "(input.geographic_breakdown_e2 == 'North Northamptonshire / West Northamptonshire')",
p("North Northamptonshire and West Northamptonshire submitted a joint workforce return in 2021 and onwards, and their data is reported together")
),
conditionalPanel(
condition = "(input.geographic_breakdown_e2 == 'Cumbria')",
p("To view 2023 and onwards data select ", strong("Cumberland"), "or", strong("Westmorland and Furness"), ". Cumbria local authority was replaced with two new unitary authorities, Cumberland and Westmorland and Furness, in April 2023.")
),
conditionalPanel(
condition = "(input.geographic_breakdown_e2 == 'Northamptonshire')",
p("To view 2021 and onwards data select ", strong("North Northamptonshire / West Northamptonshire"), ". Northamptonshire local authority was replaced with two new unitary authorities, North Northamptonshire and West Northamptonshire, in April 2021.")
),
conditionalPanel(
condition = "(input.geographic_breakdown_e2 == 'Poole')",
p("To view 2019 and onwards data select ", strong("Bournemouth, Christchurch and Poole"), ". Bournemouth, Christchurch and Poole local authority was formed in April 2019.")
),
conditionalPanel(
condition = "(input.geographic_breakdown_e2 == 'Bournemouth')",
p("To view 2019 and onwards data select ", strong("Bournemouth, Christchurch and Poole"), ". Bournemouth, Christchurch and Poole local authority was formed in April 2019.")
),
# conditionalPanel(
# condition = "(input.geographic_breakdown_e2 == 'Cumbria')",
# p("To view 2023 and onwards data select ", strong("Cumberland"), "or", strong("Westmorland and Furness"), ". Cumbria local authority was replaced with two new unitary authorities, Cumberland and Westmorland and Furness, in April 2023.")
# ),
# conditionalPanel(
# condition = "(input.geographic_breakdown_e2 == 'Northamptonshire')",
# p("To view 2021 and onwards data select ", strong("North Northamptonshire / West Northamptonshire"), ". Northamptonshire local authority was replaced with two new unitary authorities, North Northamptonshire and West Northamptonshire, in April 2021.")
# ),
# conditionalPanel(
# condition = "(input.geographic_breakdown_e2 == 'Poole')",
# p("To view 2019 and onwards data select ", strong("Bournemouth, Christchurch and Poole"), ". Bournemouth, Christchurch and Poole local authority was formed in April 2019.")
# ),
# conditionalPanel(
# condition = "(input.geographic_breakdown_e2 == 'Bournemouth')",
# p("To view 2019 and onwards data select ", strong("Bournemouth, Christchurch and Poole"), ". Bournemouth, Christchurch and Poole local authority was formed in April 2019.")
# ),
# p(htmlOutput("enabler2_choice_text2")),
br(),
div(
Expand Down
24 changes: 12 additions & 12 deletions R/outcome1_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ outcome1_tab <- function() {
gov_row(
br(),
p(htmlOutput("outcome1_choice_text1"), htmlOutput("outcome1_choice_text2")),
conditionalPanel(
condition = "(input.geographic_breakdown_o1 == 'Northamptonshire')",
p("To view 2021 and onwards data select ", strong("North Northamptonshire"), "or", strong("West Northamptonshire"), ". Northamptonshire local authority was replaced with two new unitary authorities, North Northamptonshire and West Northamptonshire, in April 2021.")
),
conditionalPanel(
condition = "(input.geographic_breakdown_o1 == 'Poole')",
p("To view 2020 and onwards data select ", strong("Bournemouth, Christchurch and Poole"), ". Bournemouth, Christchurch and Poole local authority was formed in April 2019.")
),
conditionalPanel(
condition = "(input.geographic_breakdown_o1 == 'Bournemouth')",
p("To view 2020 and onwards data select ", strong("Bournemouth, Christchurch and Poole"), ". Bournemouth, Christchurch and Poole local authority was formed in April 2019.")
),
# conditionalPanel(
# condition = "(input.geographic_breakdown_o1 == 'Northamptonshire')",
# p("To view 2021 and onwards data select ", strong("North Northamptonshire"), "or", strong("West Northamptonshire"), ". Northamptonshire local authority was replaced with two new unitary authorities, North Northamptonshire and West Northamptonshire, in April 2021.")
# ),
# conditionalPanel(
# condition = "(input.geographic_breakdown_o1 == 'Poole')",
# p("To view 2020 and onwards data select ", strong("Bournemouth, Christchurch and Poole"), ". Bournemouth, Christchurch and Poole local authority was formed in April 2019.")
# ),
# conditionalPanel(
# condition = "(input.geographic_breakdown_o1 == 'Bournemouth')",
# p("To view 2020 and onwards data select ", strong("Bournemouth, Christchurch and Poole"), ". Bournemouth, Christchurch and Poole local authority was formed in April 2019.")
# ),
),
gov_row(
br(),
Expand Down
89 changes: 49 additions & 40 deletions R/read_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,46 @@ convert_perc_cols_to_numeric <- function(x) {
return(x)
}

# sample data functions we dont need this~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
read_revenue_data <- function(file = "data/la_maintained_schools_revenue_reserve_final.csv") {
# This reads in an example file. For the purposes of this demo, we're using the
# latest LA expenditure data downloaded from the EES release.
dfRevenue <- read.csv(file)
# The time period column name has some non-ascii characters so we're just going to rename it here.
colnames(dfRevenue)[1] <- "time_period"
dfRevenue <- dfRevenue %>% mutate(
year = as.numeric(paste0("20", substr(format(time_period), 5, 6))),
area_name = case_when(
geographic_level == "National" ~ country_name,
geographic_level == "Regional" ~ region_name,
TRUE ~ la_name
)
)
return(dfRevenue)
remove_old_la_data <- function(data) {
ons_la_data <- read.csv("data/Lower_Tier_Local_Authority_to_Upper_Tier_Local_Authority_(April_2023)_Lookup_in_England_and_Wales.csv")
ons_la_data <- ons_la_data %>%
select(UTLA23CD, UTLA23NM) %>%
filter(!str_starts(UTLA23CD, "W")) %>%
unique()

removed_old_las <- data %>% filter(new_la_code == "" | new_la_code %in% (ons_la_data$UTLA23CD))

return(removed_old_las)
}


# # sample data functions we dont need this~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# read_revenue_data <- function(file = "data/la_maintained_schools_revenue_reserve_final.csv") {
# # This reads in an example file. For the purposes of this demo, we're using the
# # latest LA expenditure data downloaded from the EES release.
# dfRevenue <- read.csv(file)
# # The time period column name has some non-ascii characters so we're just going to rename it here.
# colnames(dfRevenue)[1] <- "time_period"
# dfRevenue <- dfRevenue %>% mutate(
# year = as.numeric(paste0("20", substr(format(time_period), 5, 6))),
# area_name = case_when(
# geographic_level == "National" ~ country_name,
# geographic_level == "Regional" ~ region_name,
# TRUE ~ la_name
# )
# )
# return(dfRevenue)
# }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Test not important
read_definitions <- function(file = "data/definitions.csv") {
definitions <- read.csv(file)
# colnames(definitions) <- c("Outcome/Enabler", "Domain", "Indicator", "Rationale/Description")
# definitions <- definitions[,1:4]
return(definitions)
}
# read_definitions <- function(file = "data/definitions.csv") {
# definitions <- read.csv(file)
# # colnames(definitions) <- c("Outcome/Enabler", "Domain", "Indicator", "Rationale/Description")
# # definitions <- definitions[,1:4]
# return(definitions)
# }


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -621,39 +635,35 @@ read_cin_referral_data <- function(file = "data/c1_children_in_need_referrals_an
# }

read_outcome2 <- function(file = "data/la_children_who_ceased_during_the_year.csv") {
ceased_cla_data <- read.csv(file)
old_dorset <- ceased_cla_data %>% filter(time_period <= 2019, new_la_code == "E10000009")
new_dorset <- ceased_cla_data %>% filter(time_period > 2019, new_la_code == "E06000059")
data_without_dorset <- ceased_cla_data %>% filter(la_name != "Dorset")

dorset_data <- bind_rows(new_dorset, old_dorset)
final_filtered_data <- bind_rows(data_without_dorset, dorset_data)
read_data <- read.csv(file)
# Call remove old la data function to remove the old
# final_filtered_data <- remove_old_la_data(read_data)
las_to_remove <- c("Poole", "Bournemouth", "Northamptonshire")

final_filtered_data <- read_data %>% filter(new_la_code != "E10000009", !la_name %in% las_to_remove)
ceased_cla_data <- final_filtered_data %>%
mutate(geo_breakdown = case_when(
geographic_level == "National" ~ "National", # NA_character_,
geographic_level == "Regional" ~ region_name,
geographic_level == "Local authority" ~ la_name
)) %>%
mutate(number = case_when(
mutate(number_num = case_when(
number == "z" ~ NA,
number == "x" ~ NA,
number == "c" ~ NA,
TRUE ~ as.numeric(number)
)) %>%
filter("new_la_code" != "E10000009") %>%
select("time_period", "geographic_level", "geo_breakdown", "cla_group", "characteristic", "number", "percentage")
select("time_period", "geographic_level", "geo_breakdown", "old_la_code", "new_la_code", "cla_group", "characteristic", "number", "number_num", "percentage")

totals <- ceased_cla_data %>%
filter(characteristic == "Total" & cla_group == "Reason episode ceased") %>%
rename("Total" = "number") %>%
select(time_period, geographic_level, geo_breakdown, cla_group, Total)
filter(characteristic == "Total") %>%
rename("Total_num" = "number_num") %>%
mutate("Total" = number) %>%
select(time_period, geographic_level, geo_breakdown, cla_group, Total_num, Total)

joined <- left_join(ceased_cla_data, totals, by = c("time_period", "geographic_level", "geo_breakdown", "cla_group"))
joined$perc <- round((joined$number_num / joined$Total_num) * 100, digits = 1)

test <- ceased_cla_data %>% filter(cla_group == "Reason episode ceased" & characteristic != "Total")

joined <- left_join(test, totals, by = c("time_period", "geographic_level", "geo_breakdown", "cla_group"))
joined$perc <- round((joined$number / joined$Total) * 100, digits = 1)
joined <- joined %>%
mutate(perc = case_when(
percentage == "z" ~ "z",
Expand All @@ -669,6 +679,5 @@ read_outcome2 <- function(file = "data/la_children_who_ceased_during_the_year.cs
percentage == "x" ~ NA,
TRUE ~ as.numeric(perc)
))

return(joined)
}
Loading
Loading