diff --git a/R/prerun_utils.R b/R/prerun_utils.R index 57fe8f0..0414a57 100644 --- a/R/prerun_utils.R +++ b/R/prerun_utils.R @@ -3,6 +3,7 @@ run_data_update <- function() { # The input is the attendance_data df produced in global.R, so you'll need to # source global.R before running this script. + #### SECTION 1 - Databricks connections and processing functions #### conn <- odbcConnect("Attendance Project Warehouse") sqlQuery(conn, "USE CATALOG catalog_40_copper") @@ -54,6 +55,7 @@ run_data_update <- function() { # create_ees_tables_summer(attendance_data_summer) } +#### SECTION 2 - Processing daily, weekly and year to date #### process_attendance_data <- function(attendance_data_raw, start_date, end_date, pa_fullyear_file) { # Set up data for use across the app # Take the raw data and make columns numeric and filter to only Primary, Secondary and Special @@ -227,10 +229,12 @@ process_attendance_data <- function(attendance_data_raw, start_date, end_date, p ) %>% distinct(academic_year, geographic_level, country_code, country_name, region_code, region_name, new_la_code, la_name, old_la_code, school_type, .keep_all = TRUE) + # If prior to week 2 publication, comment the line below out attendance_data_ytd <- left_join(attendance_data_ytd, dplyr::select(pa_data_raw, c(geographic_level, region_name, la_name, school_type, pa_flag, ytd_enrolments)), by = c("geographic_level" = "geographic_level", "region_name" = "region_name", "la_name" = "la_name", "school_type" = "school_type")) attendance_data <- bind_rows(attendance_data_daily, attendance_data_weekly, attendance_data_ytd) + # If prior to week 2 publication, comment the line below out attendance_data <- attendance_data %>% mutate(pa_perc = (pa_flag / ytd_enrolments) * 100) # Prep for calculation of totals by doing rates X census counts @@ -461,7 +465,7 @@ process_attendance_data <- function(attendance_data_raw, start_date, end_date, p # ) } -# ## Processing autumn +#### SECTION 3 - Processing Autumn #### process_attendance_data_autumn <- function(attendance_data_raw, autumn_start, autumn_end, pa_autumn_file) { # Set up data for use across the app # Take the raw data and make columns numeric and filter to only Primary, Secondary and Special @@ -706,7 +710,7 @@ process_attendance_data_autumn <- function(attendance_data_raw, autumn_start, au # ) } -## Processing Spring +#### SECTION 4 - Processing Spring #### process_attendance_data_spring <- function(attendance_data_raw, spring_start, spring_end, pa_spring_file) { # Set up data for use across the app # Take the raw data and make columns numeric and filter to only Primary, Secondary and Special @@ -950,7 +954,7 @@ process_attendance_data_spring <- function(attendance_data_raw, spring_start, sp # ) } # -# ## Processing Summer +#### SECTION 5 - Processing Summer #### # process_attendance_data_summer <- function(attendance_data_raw, summer_start, summer_end, pa_summer_file){ # #Set up data for use across the app # #Take the raw data and make columns numeric and filter to only Primary, Secondary and Special @@ -1184,6 +1188,7 @@ process_attendance_data_spring <- function(attendance_data_raw, spring_start, sp # # ) # } +#### SECTION 6 - Creating EES tables for daily, weekly and year to date #### create_ees_tables <- function(attendance_data) { # Set up data for download # EES daily data/download data @@ -1571,6 +1576,7 @@ create_ees_tables <- function(attendance_data) { write.csv(EES_ytd_data, "data\\EES_ytd_data.csv", row.names = FALSE) } +#### SECTION 7 - Creating EES table for Autumn #### create_ees_tables_autumn <- function(df_attendance_autumn) { # Set up data for download # EES ytd data @@ -1707,6 +1713,7 @@ create_ees_tables_autumn <- function(df_attendance_autumn) { write.csv(EES_aut_data, "data\\EES_aut_data.csv", row.names = FALSE) } +#### SECTION 8 - Creating EES table for Spring #### create_ees_tables_spring <- function(df_attendance_spring) { # Set up data for download # EES ytd data @@ -1842,7 +1849,8 @@ create_ees_tables_spring <- function(df_attendance_spring) { write.csv(EES_spr_data, "data\\EES_spr_data.csv", row.names = FALSE) } -# + +#### SECTION 9 - Creating EES table for Summer #### # create_ees_tables_summer<- function(df_attendance_summer){ # #Set up data for download # #EES ytd data @@ -1976,6 +1984,7 @@ create_ees_tables_spring <- function(df_attendance_spring) { # # } +#### SECTION 10 - Using daily data to read in for app #### read_ees_daily <- function() { read.csv("data/EES_daily_data.csv", stringsAsFactors = FALSE) } diff --git a/global.R b/global.R index 9792fd7..0638f06 100644 --- a/global.R +++ b/global.R @@ -90,6 +90,7 @@ google_analytics_key <- "DG7P4WLB0Y" # Read in data # attendance_data_raw <- fread("data/Weekly_dummy_data.csv") +#### SECTION 1 - date filters #### start_date <- as.Date("2023-09-11") end_date <- as.Date("2024-04-05") # funeral_date <- as.Date("2022-09-19") @@ -114,12 +115,14 @@ spring_end <- as.Date("2024-03-31") most_recent_week_dates <- paste0("Latest week -", as.Date(end_date) - 4, " to ", as.Date(end_date)) ytd_dates <- paste0("Year to date -", as.Date(start_date), "to", as.Date(end_date)) +#### SECTION 2 - reading in csvs to run dashboard #### attendance_data <- read.csv("data/attendance_data_dashboard.csv") message(paste("Finished processing steps, ", Sys.time())) EES_daily_data <- read_ees_daily() +#### SECTION 3 - Lookups #### # Add geog lookup geog_lookup <- attendance_data %>% dplyr::select(geographic_level, region_name, la_name) %>% @@ -197,6 +200,7 @@ las <- geog_lookup %>% pull(la_name) %>% unique() +#### SECTION 4 - Functions #### # Expandable dropdown function---------------------------------- expandable <- function(inputId, label, contents) { govDetails <- shiny::tags$details( @@ -229,6 +233,7 @@ roundFiveUp <- function(value, dp) { return(z * sign(value)) } +#### SECTION 5 - Map #### ## Reading in data ########################################################## # Read in shapefile and transform coordinates (because map reasons...) diff --git a/tests/testthat/_snaps/UI_tests/001_.png b/tests/testthat/_snaps/UI_tests/001_.png index 7948850..10829ea 100644 Binary files a/tests/testthat/_snaps/UI_tests/001_.png and b/tests/testthat/_snaps/UI_tests/001_.png differ diff --git a/tests/testthat/_snaps/UI_tests/002_.png b/tests/testthat/_snaps/UI_tests/002_.png index 3c897cc..617d4a3 100644 Binary files a/tests/testthat/_snaps/UI_tests/002_.png and b/tests/testthat/_snaps/UI_tests/002_.png differ diff --git a/tests/testthat/_snaps/UI_tests/003_.png b/tests/testthat/_snaps/UI_tests/003_.png index 4e5e47f..9bf81d7 100644 Binary files a/tests/testthat/_snaps/UI_tests/003_.png and b/tests/testthat/_snaps/UI_tests/003_.png differ diff --git a/tests/testthat/_snaps/UI_tests/004_.png b/tests/testthat/_snaps/UI_tests/004_.png index 169ffc8..5bd6727 100644 Binary files a/tests/testthat/_snaps/UI_tests/004_.png and b/tests/testthat/_snaps/UI_tests/004_.png differ diff --git a/tests/testthat/_snaps/UI_tests/005_.png b/tests/testthat/_snaps/UI_tests/005_.png index 4c3f7a4..41f809a 100644 Binary files a/tests/testthat/_snaps/UI_tests/005_.png and b/tests/testthat/_snaps/UI_tests/005_.png differ diff --git a/tests/testthat/_snaps/UI_tests/006_.png b/tests/testthat/_snaps/UI_tests/006_.png index adae869..08c8246 100644 Binary files a/tests/testthat/_snaps/UI_tests/006_.png and b/tests/testthat/_snaps/UI_tests/006_.png differ diff --git a/tests/testthat/_snaps/UI_tests/007_.png b/tests/testthat/_snaps/UI_tests/007_.png index 2660dcf..1e97178 100644 Binary files a/tests/testthat/_snaps/UI_tests/007_.png and b/tests/testthat/_snaps/UI_tests/007_.png differ diff --git a/tests/testthat/_snaps/UI_tests/008_.png b/tests/testthat/_snaps/UI_tests/008_.png index 9962afb..5861757 100644 Binary files a/tests/testthat/_snaps/UI_tests/008_.png and b/tests/testthat/_snaps/UI_tests/008_.png differ diff --git a/tests/testthat/_snaps/UI_tests/009_.png b/tests/testthat/_snaps/UI_tests/009_.png index 154ae0e..4040be0 100644 Binary files a/tests/testthat/_snaps/UI_tests/009_.png and b/tests/testthat/_snaps/UI_tests/009_.png differ diff --git a/tests/testthat/_snaps/UI_tests/010_.png b/tests/testthat/_snaps/UI_tests/010_.png index 1b6968b..b147a37 100644 Binary files a/tests/testthat/_snaps/UI_tests/010_.png and b/tests/testthat/_snaps/UI_tests/010_.png differ diff --git a/tests/testthat/_snaps/UI_tests/011_.png b/tests/testthat/_snaps/UI_tests/011_.png index acc150c..b7ce985 100644 Binary files a/tests/testthat/_snaps/UI_tests/011_.png and b/tests/testthat/_snaps/UI_tests/011_.png differ diff --git a/tests/testthat/_snaps/UI_tests/012_.png b/tests/testthat/_snaps/UI_tests/012_.png index 236b2fc..ee2aef6 100644 Binary files a/tests/testthat/_snaps/UI_tests/012_.png and b/tests/testthat/_snaps/UI_tests/012_.png differ diff --git a/tests/testthat/_snaps/UI_tests/013_.png b/tests/testthat/_snaps/UI_tests/013_.png index 92afc2d..c4d8b24 100644 Binary files a/tests/testthat/_snaps/UI_tests/013_.png and b/tests/testthat/_snaps/UI_tests/013_.png differ diff --git a/tests/testthat/_snaps/UI_tests/014_.png b/tests/testthat/_snaps/UI_tests/014_.png index 421f7b5..735cb47 100644 Binary files a/tests/testthat/_snaps/UI_tests/014_.png and b/tests/testthat/_snaps/UI_tests/014_.png differ