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

Create data comparing aggregated Naomi and national Spectrum programme data #443

Merged
merged 12 commits into from
Nov 8, 2024

Conversation

rtesra
Copy link
Collaborator

@rtesra rtesra commented Oct 28, 2024

To do:

  • Change group in ANC data to females 15-49
  • Update warning message to reference correct name of table /plot
  • Add wrapper function to output both ART and ANC and only reads in pjnz and shape file once
  • Add endpoint for warning to be displayed at upload inputs
  • Fix tests

@rtesra rtesra requested review from r-ash, jeffeaton and M-Kusumgar and removed request for r-ash October 28, 2024 15:18
Copy link
Contributor

@r-ash r-ash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, a few comments. Mainly about need to potentially run this with one of anc or art missing.

I also wonder if we should move this out of input-time-series.R that is getting quite long and this is data aggregation for a different plot.

R/input-time-series.R Outdated Show resolved Hide resolved
# Get spectrum level to select correct area names
spectrum_region_code <- unique(shape$spectrum_region_code)

if(length(spectrum_region_code) > 1){spectrum_level <- 1}else{spectrum_level <- 0}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also do

spectrum_level <- as.integer(length(spectrum_region_code) > 1))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup much better - thanks!

##' @param pjnz Path to zip file containing spectrum pjnz file/s
##' @keywords internal

prepare_spectrum_naomi_comparison <- function(art, anc, shape, pjnz){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to handle the case when either anc or art is missing? Users could upload 1 but not the other.

I'd change signature to

prepare_spectrum_naomi_comparison(shape, pjnz, art = NULL, anc = NULL)

Then have a check,

if (!is.null(art)) {
  if(!inherits(art, c("spec_tbl_df","tbl_df","tbl","data.frame" ))) {
    art <- read_art_number(art, all_columns = TRUE)
  }
  art_comparison <- prepare_art_spectrum_comparison(art, shape, pjnz)
}

and similar for ART. Then only need to bind if both present.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a quick test for this too please? You can mock our prepare_art_spectrum_comparison and prepare_anc_spectrum_comparison to just test that it reads the data and that handles case above if ANC or ART are missing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have added both and to produce an empt table when user provides no programme data. Kept rbind in to be able to bind empty df.

art_comparison <- prepare_art_spectrum_comparison(art, shape, pjnz)
anc_comparison <- prepare_anc_spectrum_comparison(anc, shape, pjnz)

rbind(art_comparison, anc_comparison)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly worth using dplyr::bind_rows here. I think it should generally be faster for large data frames (makes a big difference with a list of data frames) but seems to even with test data here

Browse[1]> bench::mark(rbind(art_comparison, anc_comparison), dplyr::bind_rows(art_comparison, anc_comparison))
# A tibble: 2 × 13
  expression           min median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time result   memory     time       gc      
  <bch:expr>        <bch:> <bch:>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm> <list>   <list>     <list>     <list>  
1 rbind(art_compar… 68.9µs 89.9µs    10047.    4.31KB     4.32  4648     2      463ms <tibble> <Rprofmem> <bench_tm> <tibble>
2 dplyr::bind_rows… 47.5µs 63.3µs    13903.    4.01KB     4.74  5867     2      422ms <tibble> <Rprofmem> <bench_tm> <tibble>

@r-ash r-ash force-pushed the spectrum-naomi-comparison-data-prep branch from 1c788e5 to f13a307 Compare November 7, 2024 11:34
@r-ash r-ash self-requested a review November 8, 2024 16:01
@r-ash r-ash merged commit 2b9a760 into master Nov 8, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants