Skip to content

Commit

Permalink
Merge pull request #397 from PIP-Technical-Team/QA
Browse files Browse the repository at this point in the history
Merge QA
  • Loading branch information
tonyfujs authored Mar 26, 2024
2 parents e27a738 + ce1d08c commit 004f125
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pipapi
Title: API for the Poverty and Inequality Platform
Version: 1.3.4
Version: 1.3.5
Authors@R:
c(person(given = "Tony",
family = "Fujs",
Expand Down Expand Up @@ -35,7 +35,8 @@ Suggests:
jsonlite,
future.callr,
future.apply,
lintr
lintr,
joyn
Language: en-US
Imports:
data.table,
Expand All @@ -51,16 +52,15 @@ Imports:
methods,
qs,
collapse,
future,
promises,
yaml,
readr,
glue,
logger,
future,
promises,
joyn,
arrow
Remotes:
PIP-Technical-Team/wbpip@PROD
PIP-Technical-Team/wbpip@DEV
Depends:
R (>= 3.5.0)
VignetteBuilder: knitr
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# pipapi 1.3.5

# pipapi 1.3.4
## New features
- Add new SPR and SPL indicators

## Enhancements
- Address some linting issues
- Increase test coverage
- Improve caching for `ui_cp_ki_headcount` and `ui_cp_poverty_charts`

# pipapi 1.3.3
- Fix bug with ag_average_poverty_stats
Expand Down
50 changes: 33 additions & 17 deletions R/ui_country_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
#' @return list
#' @export
ui_cp_key_indicators <- function(country = "AGO",
povline = NULL,
lkup,
lkup_hash = lkup$cache_data_id$hash_ui_cp) {
povline = NULL,
lkup,
lkup_hash = lkup$cache_data_id$hash_ui_cp) {

# Select surveys to use for CP page
lkup$svy_lkup <- lkup$svy_lkup[display_cp == 1]

hc <- ui_cp_ki_headcount(country = country,
povline = povline,
lkup = lkup)
povline = povline,
lkup = lkup)

dl <- lapply(lkup[["cp_lkups"]]$key_indicators, function(x) {
x[country_code == country]
Expand All @@ -37,18 +37,32 @@ ui_cp_key_indicators <- function(country = "AGO",
#' @return data.table
#' @noRd
ui_cp_ki_headcount <- function(country,
year = "MRV",
povline,
lkup) {
year = "MRV",
povline,
lkup) {

# Fetch most recent year (for CP-display)
res <- pip(country = country,
year = year,
povline = povline,
lkup = lkup)
# Fetch data for all countries for caching purposes
res_all <- pip(country = "all",
year = year,
povline = povline,
lkup = lkup)

res <- res_all[res_all$country_code == country, ]
### TEMP FIX for reporting level
res <- cp_correct_reporting_level(res)
res <-
if (nrow(res) > 1) {
if (all(c("consumption", "income") %in% res$welfare_type)) {
# Get consumpton when both are available
res[welfare_type == "consumption"]
} else {
# get the first observations. this must be revised.
res[1]
}
} else {
res
}
### TEMP FIX END

out <- data.table::data.table(
Expand Down Expand Up @@ -122,13 +136,15 @@ ui_cp_poverty_charts <- function(country,
unique()

# STEP 2: Compute stats for all countries from the region ----
res_pov <- pip(country = countries,
year = "all",
povline = povline,
lkup = lkup)
# Query for all countries for caching purpose
res_pov_all <- pip(country = "all",
year = "all",
povline = povline,
lkup = lkup)

res_pov <- res_pov_all[res_pov_all$country_code %in% countries, ]
# STEP 3: Prepare data for poverty trend chart ----
res_pov_trend <- res_pov[res_pov$country_code == country, ]
res_pov_trend <- res_pov[res_pov$country_code == country, ]
if (nrow(res_pov_trend) == 0) {
return(pipapi::empty_response_cp_poverty)
}
Expand Down
5 changes: 2 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
pip <<- memoise::memoise(pip, cache = cd, omit_args = "lkup")
ui_hp_stacked <<- memoise::memoise(ui_hp_stacked, cache = cd, omit_args = "lkup")
pip_grp_logic <<- memoise::memoise(pip_grp_logic, cache = cd, omit_args = "lkup")
ui_cp_charts <<- memoise::memoise(ui_cp_charts, cache = cd, omit_args = "lkup")
#ui_cp_charts <<- memoise::memoise(ui_cp_charts, cache = cd, omit_args = "lkup")
ui_cp_download <<- memoise::memoise(ui_cp_download, cache = cd, omit_args = "lkup")
ui_cp_key_indicators <<- memoise::memoise(ui_cp_key_indicators, cache = cd, omit_args = "lkup")
#ui_cp_key_indicators <<- memoise::memoise(ui_cp_key_indicators, cache = cd, omit_args = "lkup")
assign("cd", cd, envir = .GlobalEnv)
packageStartupMessage("Info: Disk based caching is enabled.")
}
}


0 comments on commit 004f125

Please sign in to comment.