Skip to content

Commit

Permalink
Merge branch 'master' into rename_smrtype
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftySalmon authored Oct 2, 2023
2 parents 332bffc + 99020b6 commit 2324428
Show file tree
Hide file tree
Showing 120 changed files with 1,685 additions and 700 deletions.
85 changes: 0 additions & 85 deletions 00-Sort_BI_Extracts.py

This file was deleted.

50 changes: 50 additions & 0 deletions 00_Sort_BI_Extracts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Define the source directory and financial year pattern
compress_files <- FALSE
source_dir <- "/conf/sourcedev/Source_Linkage_File_Updates/Extracts Temp"
pattern <- "-20(\\d{4})\\.csv"


# List all the CSV files in the source directory
cat(stringr::str_glue("Looking in '{source_dir}' for csv files."))
csv_files <- list.files(source_dir, pattern = ".csv", full.names = TRUE)
print(stringr::str_glue("Found {length(csv_files)} csv files to process."))

# Create a function to extract the financial year from a filename
extract_financial_year <- function(filename) {
match <- regexpr(pattern, basename(filename))
if (match[[1]][1] > 0) {
financial_year <- substr(basename(filename), match[[1]][1] + 3, match[[1]][1] + 6)
return(financial_year)
} else {
return(NULL)
}
}

# Create directories for each financial year and move files
for (csv_file in csv_files) {
financial_year <- extract_financial_year(csv_file)
# check if year directory exists
if (!is.null(financial_year)) {
financial_year_dir <- file.path("/conf/sourcedev/Source_Linkage_File_Updates", financial_year, "Extracts")
# if not, create the year directory
if (!dir.exists(financial_year_dir)) {
dir.create(financial_year_dir)
}

# compress file
if (compress_files) {
cat("Compressing:", basename(csv_file), "\n")
system2(
command = "gzip",
args = shQuote(csv_file)
)
csv_file <- paste0(csv_file, ".gz")
}

# move file
new_file_path <- file.path(financial_year_dir, basename(csv_file))
file.copy(csv_file, new_file_path)
file.remove(csv_file)
cat("Moved:", csv_file, "to", new_file_path, "\n")
}
}
17 changes: 4 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export(convert_fyyear_to_year)
export(convert_hb_to_hbnames)
export(convert_hscp_to_hscpnames)
export(convert_numeric_to_date)
export(convert_sending_location_to_lca)
export(convert_sc_sending_location_to_lca)
export(convert_year_to_fyyear)
export(create_episode_file)
export(create_homelessness_lookup)
Expand Down Expand Up @@ -47,6 +47,7 @@ export(get_homelessness_completeness_path)
export(get_it_deaths_path)
export(get_it_ltc_path)
export(get_it_prescribing_path)
export(get_la_code_opendata_lookup)
export(get_locality_path)
export(get_lookups_dir)
export(get_ltcs_path)
Expand All @@ -66,7 +67,9 @@ export(get_slf_ch_name_lookup_path)
export(get_slf_chi_deaths_path)
export(get_slf_deaths_lookup_path)
export(get_slf_dir)
export(get_slf_episode_path)
export(get_slf_gpprac_path)
export(get_slf_individual_path)
export(get_slf_postcode_path)
export(get_source_extract_path)
export(get_sparra_path)
Expand All @@ -75,7 +78,6 @@ export(get_year_dir)
export(gzip_files)
export(is_date_in_fyyear)
export(is_missing)
export(la_code_lookup)
export(last_date_month)
export(latest_cost_year)
export(latest_update)
Expand Down Expand Up @@ -172,17 +174,6 @@ export(write_file)
importFrom(data.table,.N)
importFrom(data.table,.SD)
importFrom(magrittr,"%>%")
importFrom(readr,col_character)
importFrom(readr,col_date)
importFrom(readr,col_datetime)
importFrom(readr,col_double)
importFrom(readr,col_factor)
importFrom(readr,col_integer)
importFrom(readr,col_logical)
importFrom(readr,col_number)
importFrom(readr,col_time)
importFrom(readr,cols)
importFrom(readr,cols_only)
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(tibble,tibble)
2 changes: 1 addition & 1 deletion R/add_nsu_cohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @return A data frame containing the Non-Service Users as additional rows
#' @export
#'
#' @family episode file
#' @family episode_file
#' @seealso [get_nsu_path()]
add_nsu_cohort <- function(
data,
Expand Down
2 changes: 1 addition & 1 deletion R/add_ppa_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param data A data frame
#'
#' @return A data frame to use as a lookup of PPAs
#' @family episode file
#' @family episode_file
add_ppa_flag <- function(data) {
check_variables_exist(
data,
Expand Down
2 changes: 1 addition & 1 deletion R/convert_ca_to_lca.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' convert_ca_to_lca(ca)
#'
#' @family code functions
#' @seealso convert_sending_location_to_lca
#' @seealso convert_sc_sending_location_to_lca
convert_ca_to_lca <- function(ca_var) {
lca <- dplyr::case_match(
ca_var,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#'
#' @examples
#' sending_location <- c(100, 120)
#' convert_sending_location_to_lca(sending_location)
#' convert_sc_sending_location_to_lca(sending_location)
#'
#' @family code functions
#'
#' @seealso convert_ca_to_lca
convert_sending_location_to_lca <- function(sending_location) {
convert_sc_sending_location_to_lca <- function(sending_location) {
lca <- dplyr::case_match(
sending_location,
100L ~ "01", # Aberdeen City
Expand Down
2 changes: 2 additions & 0 deletions R/cost_uplift.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' @param data episode data
#'
#' @return episode data with uplifted costs
#' @family episode_file
apply_cost_uplift <- function(data) {
data <- data %>%
# attach a uplift scale as the last column
Expand Down Expand Up @@ -34,6 +35,7 @@ apply_cost_uplift <- function(data) {
#' @param data episode data
#'
#' @return episode data with a uplift scale
#' @family episode_file
lookup_uplift <- function(data) {
# We have set uplifts to use for 2020/21, 2021/22 and 2022/23,
# provided by Paul Leak.
Expand Down
9 changes: 1 addition & 8 deletions R/create_episode_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,7 @@ create_episode_file <- function(
}

if (write_to_disk) {
# TODO make the slf_path a function
slf_episode_path <- get_file_path(
get_year_dir(year),
stringr::str_glue(
"source-episode-file-{year}.parquet"
),
check_mode = "write"
)
slf_episode_path <- get_slf_episode_path(year, check_mode = "write")

write_file(episode_file, slf_episode_path)
}
Expand Down
Loading

0 comments on commit 2324428

Please sign in to comment.