RISE_FJ/T0_baseline/O3_T0_FJ-dailyqc.R

# OBJECTIVE 3 AND 4 BASELINE SURVEY IN FIJI - 20 JUNE 2019 to ??



library (tidyverse)
library (lubridate)
library (stringr)

rm(list = ls())

#setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/1. FJ/3/20190624_baseline/3. Data/1. raw data")
setwd("Z:/Data Files/Data Files Objective 3")
       
# DEFINE TODAY FOR DAILY QC - this is the date of data collection
date <- "2019-08-06"
day.qc <- ymd (date)
rm(date)

# HOUSE SURVEY
house <- read_csv (file="RISE_baseline_house_FJ_v1.csv")
# house.water <- read_csv(file="RISE_baseline_house_FJ_v1-house_survey-water_use-water_repeat.csv")

# HOUSEHOLD SURVEY
hhd <- read_csv (file = "RISE_baseline_hhd_FJ_v1.csv")
hhd.child <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-child_loop.csv")
# hhd.activity <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-demographics-activity.csv")
# hhd.daycare <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-demographics-daycare.csv")
# hhd.ethnicity <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-demographics-ethnicity_screen-ethnicity_repeat.csv")
# hhd.marital <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-demographics-marital_status1.csv")
# hhd.read <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-demographics-read.csv")
# hhd.religion <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-demographics-religion_screen-religion_repeat.csv")
# hhd.school <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-demographics-school.csv")
 hhd.person <- read_csv (file = "RISE_baseline_hhd_FJ_v1-hhd_survey-person_details1.csv")

 write_csv(hhd.child, path = "Z:/Data Files/Data Files Objective 3/Summary/hhd.child.csv")
 
# CONSENT SURVEY - do not include in daily QC
#consent <- read_csv (file = "consent_ID_final.csv")
consent <- read_csv (file = "consent_FJ_v1.csv")
# consent.form3 <- read_csv (file = "consent_ID_final-consent_form3.csv")
# consent.childname <- read_csv (file = "consent_ID_final-consent3_childname.csv")
#############################################

#############################################
##  Correct known errors in the data       ##
#############################################
# setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/1. FJ/3/20190624_baseline/3. Data/2. code")
setwd("Z:/R Script/R Script Obj 3")
source("O3_T0_FJ-consent_corrections.R")
setwd("Z:/Data Files/Data Files Objective 3/Summary")
# setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/1. FJ/3/20190624_baseline/3. Data")

setwd("Z:/R Script/R Script Obj 3")
 source("O3_T0_FJ-corrections.R")
setwd("Z:/Data Files/Data Files Objective 3/Summary")

##########
### DELETION OF FULL SURVEYS - BEST DONE AFTER MERGE
##########

#KINOYA house # 22 repetition house already done on the 20th form for house and household to be removed.
hhd <- hhd %>% 
  filter (!(settlement_barcode == "Kinoya" & extract_house_no == 22 & today == "2019-06-24"))
house <- house %>% 
  filter (!(settlement_barcode == "Kinoya" & extract_house_no == 22 & today == "2019-06-24"))
######

#KINOYA house # 67 repetition house incomplete on 24 redone and completed on 26th. Survey for house and household removed from the 24th.
hhd <- hhd %>% 
  filter (!(settlement_barcode == "Kinoya" & extract_house_no == 67 & today == "2019-06-24"))
house <- house %>% 
  filter (!(settlement_barcode == "Kinoya" & extract_house_no == 67 & today == "2019-06-24"))

######

#MUANIVATU house # 55 incorrect house number redone correct house # 89 consent done on 02/07/2019. Survey for house and household removed from the 01/07/2019.
hhd <- hhd %>% 
  filter (!(settlement_barcode == "Muanivatu" & extract_house_no == 55 & today == "2019-07-01"))
house <- house %>% 
  filter (!(settlement_barcode == "Muanivatu" & extract_house_no == 55 & today == "2019-07-01"))

######

#MATATA house # 40 incorrect house number redone correct house # 46 consent done on 04/07/2019. Survey for house removed from the 04/07/2019.
hhd <- hhd %>% 
  filter (!(settlement_barcode == "Matata" & extract_house_no == 40 & today == "2019-07-04"))
house <- house %>% 
  filter (!(settlement_barcode == "Matata" & extract_house_no == 40 & today == "2019-07-04"))


#############################################
#############################################
##  Clean variables                        ##
#############################################
#############################################
# setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/Current/RISE/4. Surveys/2.Consent and House ID/2. ID/2. Data/2. code")
# source("consentfj-clean.R")
# setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/Current/RISE/4. Surveys/2.Consent and House ID/2. ID/2. Data")

# need to fix dates to allow for return visits with survey left open (can't use "today")
fix_date <- function(x_date){
  x_date <- ifelse(!is.na(ymd_hms(x_date)), ymd_hms(x_date), 
                   ifelse(!is.na(dmy_hms(x_date)), dmy_hms(x_date), mdy_hms(x_date)))  # Check the format and return the correct integer-date
  x_date <- as.POSIXct(x_date, origin = "1970-01-01", tz = "UTC")  # Convert the integer-date to a consistent format
}

house$time <- date(fix_date(house$time9))
hhd$time <- date(fix_date(hhd$time9))


#############################################
#############################################
# SUBSET - ONLY DATA COLLECTED TODAY
#############################################
#############################################

subhouse <- subset (house, today == day.qc, 
                    select = c (extract_settlement, settlement_barcode, 
                                extract_house_no, survey_status))


subhhd <- subset (hhd, today == day.qc, 
                  select = c (extract_settlement, settlement_barcode,extract_house_no, 
                              survey_status))

#############################################
#############################################
# DAILY QC REPORT
#############################################
#############################################

#############################################
####### what settlements were visited ************

# need to merge settlements from both house and household surveys because there
# might not always be a house survey

settlement_house <-  subhouse %>%
  select (settlement_barcode)
settlement_hhd <-  subhhd %>%
  select (settlement_barcode)

# append
settlement_group <- rbind(settlement_house, settlement_hhd)

# then group
settlement <- settlement_group %>% 
  arrange (settlement_barcode) %>% 
  group_by (settlement_barcode) %>%
  summarize (count = n ())

settlement.list <- pull (settlement, var = settlement_barcode)


#############################################
# HOUSE SURVEYS

#number started
nrow(subhouse)

#number completed
house.complete <- subhouse %>% 
  filter (survey_status == 1)

house.incomplete <- subhouse %>% 
  filter (is.na(survey_status))

#############################################
# HOUSEHOLD SURVEYS

#number started
nrow(subhhd)

#number completed
hhd.complete <- subhhd %>% 
  filter (survey_status == 1)



#############################################
# HOUSE SURVEYS WITH NO HOUSEHOLD SURVEY?


#SURVEY DURATION
time_hhd <- hhd %>% 
  select (extract_settlement, settlement_barcode,  extract_house_no, house_status, time, duration, time1, duration1, time14, duration14, 
          survey_status, house_status, gift_yn) %>% 
  mutate (duration_min = duration/60) %>% 
  filter (time == day.qc)
time_hhd_avg <- mean(time_hhd$duration_min)
time_hhd_min <- min(time_hhd$duration_min)
time_hhd_max <- max(time_hhd$duration_min)
summary(time_hhd$duration_min)

time_house <- house %>% 
  select(extract_settlement, settlement_barcode,  extract_house_no, house_status, survey_continue_yes, survey_status, 
         time, duration, time1, duration1, time10, duration10, roofing) %>% 
  mutate (duration_min = duration/60) %>% 
  filter (time == day.qc)
time_house_avg <- mean(time_house$duration_min)
time_house_min <- min(time_house$duration_min)
time_house_max <- max(time_house$duration_min)
summary(time_house$duration_min)


#NUMBER OF SURVEYS COMPLETED PER CFW
cfw_house <- house %>% 
  filter (time == day.qc) %>% 
  select (settlement_barcode,  extract_house_no, name_surveyor, duration, house_status, survey_continue_yes, survey_status) %>% 
  mutate (duration_min = duration/60) %>% 
  filter (survey_continue_yes == 1)

cfw_house_count <- cfw_house %>% 
  group_by(name_surveyor) %>% 
  summarise (house= n())
cfw_house_count_avg <- mean(cfw_house_count$house)
cfw_house_count_min <- min(cfw_house_count$house)
cfw_house_count_max <- max(cfw_house_count$house)


cfw_hhd <- hhd %>% 
  filter (time == day.qc) %>% 
  select (settlement_barcode,  extract_house_no, name_surveyor, duration, survey_status, house_status, gift_yn) %>% 
  mutate (duration_min = duration/60)  %>% 
  filter (house_status == 1)

cfw_hhd_count <- cfw_hhd %>% 
  group_by(name_surveyor) %>% 
  summarise (hhd = n())
cfw_hhd_count_avg <- mean(cfw_hhd_count$hhd)
cfw_hhd_count_min <- min(cfw_hhd_count$hhd)
cfw_hhd_count_max <- max(cfw_hhd_count$hhd)






#CROSS CHECK WITH FULL LIST OF HHDS
Monash-RISE/riseR documentation built on Dec. 11, 2019, 9:49 a.m.