Skip to content

Commit

Permalink
[#106] added function populationExport
Browse files Browse the repository at this point in the history
This function exports population data by agegroup and gender for each district.
  • Loading branch information
DavidSoSiZoch committed Dec 10, 2021
1 parent f829ef2 commit 5641a7f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
6 changes: 3 additions & 3 deletions sormas-stats-sitrep/sitrep-app/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ toDate = as.character(Sys.Date() + 1) # or toDate = as.character("yyyy-mm-dd"),


# Defining connection to db
DB_USER = "sormas_user"
DB_PASS = "password"
DB_HOST = "127.0.0.1"
DB_USER = "postgres" #"sormas_user"
DB_PASS = "HZIsormas" #"password"
DB_HOST = "localhost" #"127.0.0.1"
DB_PORT = "5432"
DB_NAME = "sormas"
## end of configuratiion
Expand Down
2 changes: 1 addition & 1 deletion sormas-stats-sitrep/sitrep-app/loading_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sormas_db = DBI::dbConnect(RPostgres::Postgres(),
caseData = caseExportLineList(sormas_db = sormas_db, fromDate = fromDate, toDate = toDate)

# Import population data

populationData = populationExport(sormas_db = sormas_db)

# Import shape files

Expand Down
2 changes: 1 addition & 1 deletion sormas-stats-sitrep/sitrep-app/loading_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Functions to export data from sormas ----
# base::source(file.path("./utils", "function_name.R"))
base::source("utils/caseExportLineList.R")

base::source("utils/populationExport.R")

## Functions for data analysis ----

Expand Down
33 changes: 33 additions & 0 deletions sormas-stats-sitrep/sitrep-app/utils/populationExport.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
populationExport <- function(sormas_db){
# This function outputs a table containing population data.
# It contains data on the population by agegroup and gender in each district.

# District table SQL query
queryDistrict <- paste0("SELECT DISTINCT id AS district_id,
name AS district_name
FROM public.district
WHERE archived = FALSE
")
districts <- DBI::dbGetQuery(sormas_db, queryDistrict)

# Populationdata table SQL query
queryPopulation <- paste0("SELECT DISTINCT id AS population_id,

This comment has been minimized.

Copy link
@bernardsilenou

bernardsilenou Jan 14, 2022

Collaborator

Population in sormas has regionname and district name, so we would need to find a way to merge by name

district_id,
region_id,
sex AS sex_population,
agegroup AS agegroup_population,
population
FROM public.populationdata
")
population_data <- DBI::dbGetQuery(sormas_db, queryPopulation)

# Merging population data with district names
population_data <- population_data %>%
dplyr::left_join(., districts, by = 'district_id' )

#return output table
return(population_data)
}

0 comments on commit 5641a7f

Please sign in to comment.