Skip to content

Commit

Permalink
Make sure summarise asserts still work
Browse files Browse the repository at this point in the history
The behaviour of summarise has changed. Need to make sure we are actually
checking for assumtpsion that there is only one distinct s_state and s_postcode
value for each site_id.
  • Loading branch information
cchristiansen committed Jul 27, 2023
1 parent f6271c4 commit fe7c642
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions process_input_data/process_input_data_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,27 @@ sum_manufacturers <- function(manufacturers){
return(manufacturer)
}

assert_raw_site_details_assumptions <- function(site_details){
# Check in coming site data for conformance to data processing assumptions
# We assume that only possible s_state values are NSW, QLD, VIC, TAS, SA, WA, NT, ACT
s_state <- site_details$s_state
assert_that(all(s_state == "NSW" | s_state == "QLD" | s_state == "VIC" | s_state == "TAS" | s_state == "SA" |
s_state == "WA" | s_state == "ACT"), msg="State values outside expected set NSW, ACT, SA etc")
# We assume that for each site id there is only one distinct s_state value and s_postcode value
site_details_grouped <- group_by(site_details, site_id)
site_details_grouped <- summarise(site_details_grouped, s_state=unique(s_state), s_postcode=unique(s_postcode))
site_details_grouped <- as.data.frame(site_details_grouped)
assert_that(all(lapply(site_details_grouped$s_state, length)==1),
msg="Some sites have mutiple distinct s_state values")
assert_that(all(lapply(site_details_grouped$s_postcode, length)==1),
msg="Some sites have mutiple distinct s_postcode values")
# We assume ac and dc values can be converted to numeric without be turned
# into NAs
assert_that(all(!is.na(as.numeric(site_details$ac))))
#assert_that(all(!is.na(as.numeric(site_details$dc))))
#' Check incoming site data for conformance to data processing assumptions.
assert_raw_site_details_assumptions <- function(site_details) {
# Only possible s_state values are NSW, QLD, VIC, TAS, SA, WA, NT, ACT.
s_state <- site_details$s_state
assert_that(
all(s_state %in% c("NSW", "QLD", "VIC", "TAS", "SA" , "WA", "ACT")),
msg = "State values outside expected set NSW, ACT, SA etc."
)
# Only one distinct s_state and s_postcode value for each site_id.
site_details_grouped <- group_by(site_details, site_id) %>%
summarise(s_state = unique(s_state), s_postcode = unique(s_postcode))
assert_that(
all(count(site_details_grouped, site_id, s_state)$n == 1),
msg = "Some sites have mutiple distinct s_state values."
)
assert_that(
all(count(site_details_grouped, site_id, s_postcode)$n == 1),
msg = "Some sites have mutiple distinct s_postcode values."
)
# Assume AC values can be converted to numeric without be turned into NAs.
assert_that(all(!is.na(as.numeric(site_details$ac))))
}

perform_power_calculations <- function(master_data_table){
Expand Down

0 comments on commit fe7c642

Please sign in to comment.