-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMetabase Analysis Setup.R
More file actions
674 lines (585 loc) · 46.9 KB
/
Metabase Analysis Setup.R
File metadata and controls
674 lines (585 loc) · 46.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
##################################
##################################
####### User Data Analysis #######
##################################
##################################
country <- "Tanzania"
#study <- "RCT"
additional_week_order <- c("Srh", "Svp", "Grief", "Learn")
ltp_activites <- c("chores", "bao", "walk", "cook_traditional", "garden", "charades", "role_play",
"find_pair", "mystery_box", "memory_game", "cook", "tell_stories", "dance",
"short_term_goal", "long_term_goal", "clean", "reflect_positive", "check_in_chat",
"dream_travel", "famous_party","two_truths", "time_machine", "superpowers",
"friendly_chat", "interrupter", "three_options", "yes_no_maybe",
"invent_story")
ltp_activites_name <- naming_conventions(ltp_activites)
### Set up UIC data
# add in start dates for clusters
# create a data frame with the lookup values
lookup_df <- data.frame(opt_cluster = c(1, 3, 4, 6, 7, 11, 13, 14),
whatsapp_start_date = as.Date(c("2022-11-27", "2022-12-17", "2023-01-10",
"2022-11-24", "2022-11-26", "2023-01-10",
"2022-12-24", "2022-12-24")))
# use left_join to add the lookup values to the main data frame
#UIC_Tracker_Tanzania <- UIC_Tracker_Tanzania %>%
# left_join(lookup_df, by = "opt_cluster")
### extract data ----------------------------------------------------------------------
# to get user data
if (study %in% c("Optimisation", "Pilot")){
UIC_Tracker_Use <- UIC_Tracker_Tanzania
} else {
UIC_Tracker_Use <- UIC_Tracker_RCT[!duplicated(UIC_Tracker_RCT$Code), ]
UIC_Tracker_Use$ClusterName <- toupper(UIC_Tracker_Use$ClusterName)
}
if (study == "RCT"){
UIC_onboarding_dates <- readxl::read_excel("data/UIC_onboarding_dates.xlsx")
UIC_onboarding_dates <- UIC_onboarding_dates %>%
mutate(#date_first_chat = lubridate::as_date(`Date of onboarding`),
#date_data_bundle = lubridate::as_date(`Date first data bundle received`),
date_first_chat = lubridate::as_date(`Date of first WhatsApp Live Chat`) - 6,
# `Date of first WhatsApp Live Chat` is day SEVEN
`Cluster name` = toupper(`Cluster name`))
# do based on first live chat
UIC_onboarding_dates <- UIC_onboarding_dates %>% dplyr::select(c(ClusterNumber = `Cluster Number`, date_first_chat))
UIC_Tracker_Use_cn <- UIC_Tracker_Use %>%
dplyr::filter(Study == "RCT") %>%
dplyr::mutate(ClusterName = toupper(ClusterName)) %>%
dplyr::select(ClusterName, ClusterNumber)
UIC_Tracker_Use_cn <- unique(UIC_Tracker_Use_cn)
UIC_Tracker_Use_cn$ClusterNumber <- as.numeric(UIC_Tracker_Use_cn$ClusterNumber)
UIC_onboarding_dates <- full_join(UIC_Tracker_Use_cn, UIC_onboarding_dates, by = "ClusterNumber") %>% dplyr::select(-"ClusterNumber") %>%
dplyr::filter(!is.na(ClusterName)) %>%
mutate(`Weeks completed` = as.integer(floor(as.numeric(Sys.Date() - date_first_chat)/7))) %>%
dplyr::select(-c("date_first_chat"))
}
if (study == "RCT"){
x <- which(UIC_Tracker_Use$YourParentAppCode == "a4085690410bCa24")
UIC_Tracker_Use$YourParentAppCode[x] <- "a4085690410bca24"
}
if (study == "WASH"){
x <- which(UIC_Tracker_Use$YourParentAppCode == "428918439401398")
UIC_Tracker_Use$YourParentAppCode[x] <- "0428918439401398"
y <- which(UIC_Tracker_Use$YourParentAppCode == "0c1d200d9caf6096")
UIC_Tracker_Use$YourParentAppCode[y] <- "0c1d200d9eaf6096"
z <- which(UIC_Tracker_Use$YourParentAppCode == "187C0a36b7c1803c")
UIC_Tracker_Use$YourParentAppCode[z] <- "187c0a36b7c1803c"
}
#UIC_Tracker_Use <- UIC_Tracker_Use %>% filter(Study == "Pilot")
plhdata_org <- get_user_data(site = plh_con, merge_check = FALSE, filter = TRUE,
UIC_Tracker = UIC_Tracker_Use,
country = country, study = study)
names(plhdata_org) <- gsub(x = names(plhdata_org), pattern = "\\-", replacement = ".")
#plhdata_org <- get_user_data(site = plh_con, merge_check = FALSE, filter = FALSE)
plhdata_org$app_user_id
# app_deployment_name == early_family_math
# plhdata_org_efm <- plhdata_org %>%
# filter(app_deployment_name == "early_family_math")
# View(plhdata_org_efm)
#
# plhdata_org_efm
#
# plhdata_org_efm1 <- plhdata_org_efm[,colSums(is.na(plhdata_org_efm))<nrow(plhdata_org_efm)]
# names(plhdata_org_efm1) <- gsub(x = names(plhdata_org_efm1), pattern = "\\-", replacement = ".")
#plhdata_org <- readRDS("plhdata_org_RCT_20230525.RDS")
if (nrow(plhdata_org) == 0){
plhdata_org <- get_user_data(site = plh_con, merge_check = FALSE, filter = TRUE, UIC_Tracker = UIC_Tracker_Tanzania,
country = country, study = "Pilot")
names(plhdata_org) <- gsub(x = names(plhdata_org), pattern = "\\-", replacement = ".")
plhdata_org <- plhdata_org %>% mutate(across(everything(), as.numeric))
plhdata_org <- naniar::replace_with_na_all(plhdata_org, ~.x)
plhdata_org <- plhdata_org[0,]
}
# Create Optimisation Group Data for Optimisation Study - Tanzania
if (study == "Optimisation"){
valid_ids <- UIC_Tracker_Tanzania %>%
filter(complete.cases(YourParentAppCode)) %>%
filter(Study == study) %>%
select(c(YourParentAppCode, opt_cluster, experimental_condition, OnboardingDate))
plhdata_org <- full_join(plhdata_org, valid_ids, by = c("app_user_id" = "YourParentAppCode"))
plhdata_org <- plhdata_org %>%
mutate(Cluster = opt_cluster,
Support = ifelse(experimental_condition < 5, "Self-guided", "WhatsApp"),
Skin = ifelse(experimental_condition %in% c(1, 2, 5, 6), "Module", "Workshop"),
`Digital Literacy` = ifelse(experimental_condition %in% c(1, 3, 5, 7), "On", "Off"))
} else if (study == "Pilot") {
valid_ids <- UIC_Tracker_Tanzania %>%
filter(complete.cases(YourParentAppCode)) %>%
filter(Study == "Pilot") %>%
select(c(YourParentAppCode, PilotSite))
plhdata_org <- fuzzyjoin::stringdist_full_join(x = plhdata_org, y = valid_ids, by = c("app_user_id" = "YourParentAppCode"), max_dist = 5)
#plhdata_org_ics_fuzzy <- fuzzyjoin::stringdist_full_join(x = plhdata_org, y = valid_ids, by = c("app_user_id" = "YourParentAppCode"), max_dist = 5)
# valid_app_user_id_TZ <- (plhdata_org_ics_fuzzy %>% filter(organisation_full == "ICS") %>% filter(!is.na(YourParentAppCode)))$app_user_id
# plhdata_org <- plhdata_org %>%
# mutate(valid_ics = ifelse(organisation_full != "ICS", TRUE,
# ifelse(app_user_id %in% valid_app_user_id_TZ, TRUE, FALSE))) %>%
# filter(valid_ics)
# plhdata_org <- plhdata_org %>%
# mutate(organisation_full = ifelse(app_user_id %in% c("2c5bfeb1c97cffdf", "0e5824bd19aae8c4",
# "48621962b0612b7c", "d5faa072c966ea8d",
# "df1088af5f3d4c87", "5b2ba92c32c6a3e2",
# "f3aff268263b1d62", "a05a0fe6cd3cb52d",
# "7f56c4c0a8a2f36f", "fab4ae58ac03f920"),
# "ICS",
# as.character(organisation_full)))
# Create Pilot Group Data for Pilot Study - Tanzania
# add in new row containing ICS, and app_user_id - 08/09/22
#fab4ne58ac03f920
#oe5824bd19aa8c4
#plhdata_org[(nrow(plhdata_org)+1):(nrow(plhdata_org)+2),] <- NA
#plhdata_org$app_user_id[(last(nrow(plhdata_org))-1):last(nrow(plhdata_org))] <- c("fab4ne58ac03f920", "oe5824bd19aa8c4")
#plhdata_org$organisation_full[(last(nrow(plhdata_org))-1):last(nrow(plhdata_org))] <- c("ICS", "ICS")
#plhdata_org$app_version[(last(nrow(plhdata_org))-1):last(nrow(plhdata_org))] <- c("0.0", "0.0")
# get unique cases only
#View(plhdata_org_ics_fuzzy %>% filter(app_user_id == "a60b902a430aaec2"))
# plhdata_org_ics_fuzzy <- unique(plhdata_org_ics_fuzzy %>% dplyr::select(-c("YourParentAppCode")))
# plhdata_org_pilot_site <- plhdata_org_ics_fuzzy %>% dplyr::select(c(app_user_id, PilotSite)) %>% filter(!is.na(PilotSite))
# nrow((plhdata_org_pilot_site))
# plhdata_org <- full_join(plhdata_org, plhdata_org_pilot_site, by = c("app_user_id" = "app_user_id"))
} else if (study == "RCT") {
valid_ids <- UIC_Tracker_Use %>%
filter(complete.cases(YourParentAppCode)) %>%
filter(Study == "RCT") %>%
mutate(ClusterName = toupper(ClusterName)) %>%
select(c(YourParentAppCode, Ward, ClusterName, OnboardingDateShort))
plhdata_org <- fuzzyjoin::stringdist_full_join(x = plhdata_org, y = valid_ids, by = c("app_user_id" = "YourParentAppCode"), max_dist = 5)
} else if (study == "WASH") {
valid_ids <- UIC_Tracker_Use %>%
filter(complete.cases(YourParentAppCode)) %>%
filter(Study == "WASH") %>%
select(c(YourParentAppCode, Ward, ClusterName, OnboardingDateShort))
plhdata_org <- fuzzyjoin::stringdist_full_join(x = plhdata_org, y = valid_ids, by = c("app_user_id" = "YourParentAppCode"), max_dist = 5)
}
plhdata_org <- plhdata_org %>% filter(ClusterName != "https://wa.me/qr/5KAUP4HXZHGXP1")
# For SA:
if (country == "South Africa"){
plhdata_org$Org <- plyr::revalue(x=plhdata_org$organisation_full,
replace=c(`ICS` = "ICS", `Optimisation Study` = "Optimisation Study", `Miss.Miss` = "Other", `Miss.baba` = "Other", `Miss.w` = "Other", `Miss.idems` = "Other", `Miss.hillcrest` = "Other", `Miss.aqujhk,jafvh` = "Other", `Miss.ParentApp_dev` = "Other", `Miss.CWBSA` = "Other",
`Miss.idems Margherita` = "Other", `Miss.IDEMS Ohad` = "Other", `Miss.983aba50330cf24c` ="Other", `Miss.sdfds`="Other", `Miss.friend` ="Other", `Miss.myself` ="Other", `Miss.undefined` ="Other",
`Miss.other` ="Other", `Miss.zlto` ="Other", `Miss.hpccc` ="Other", `Miss.seven_passes` ="Other", `Miss.Hillcrest facilitator` ="Other", `Miss.Hillcrest Facilitator ` ="Other", `Miss.a00af0c3b3887330` ="Other",
`Nontobeko.Miss` = "Nontobeko", `Nontobeko.Nontobeko M` = "Nontobeko", `Nontobeko.bbe9ca70c78f7384` = "Nontobeko", `Nontobeko.nontobekoM` = "Nontobeko",
`Nontobeko.NontobekoM` = "Nontobeko", `Nontobeko.null` ="Nontobeko", `Miss.NontobekoM` = "Nontobeko",
`Joy.Miss` = "Joy", `Joy.c9097349f34b364c` ="Joy", `Joy.null` ="Joy",
`Dlalanathi.Miss` = "Dlalanathi", `Dlalanathi.null` = "Dlalanathi", `Miss.dlalanathiThandeka` = "Dlalanathi", `Dlalanathi.dlanathiThandeka` ="Dlalanathi",
`Dlalanathi.dlalanathThandeka` ="Dlalanathi", `Dlalanathi.dlalanathiThandeka` ="Dlalanathi", `Dlalanathi.dlalanathi` ="Dlalanathi", `Dlalanathi.dlalanithi Thandeka` ="Dlalanathi",
`Amathuba Collective.Miss` ="Amathuba", `Miss.Amathuba Mzi` ="Amathuba", `Miss.Amathuba Mzi ` ="Amathuba", `Miss.amathuba` ="Amathuba", `Miss.dlalanathi`="Dlalanathi",
`Miss.organisation_1` = "Other", `Miss.organisation_2` = "Other",`Miss.organisation_6` = "Other"))
#plhdata_org_ics_fuzzy %>% filter(!is.na(YourParentAppCode)) %>% dplyr::select(organisation_full, app_user_id, YourParentAppCode)
# Note: "2c5bfeb1c97cffdf" "oe5824bd19aa8c4" are in "Miss.Miss"
}
#####Create a subset for cleaned organisations ####
plhdata_org_clean <- plhdata_org # %>% filter(Org != "Other")%>% mutate(Org = factor(Org))
if ("ClusterName" %in% names(plhdata_org_clean)) {
plhdata_org_clean$ClusterName <- toupper(plhdata_org_clean$ClusterName)
}
# RCT TODO HERE
# plhdata_org_clean <- plhdata_org_clean %>%
# dplyr::mutate(rp.contact.field.user_age = as.numeric(rp.contact.field.user_age)) %>%
# dplyr::mutate(rp.contact.field.user_age = replace(rp.contact.field.user_age,
# rp.contact.field.user_age %in% c(-29, 2, 1794, 5655),
# NA)) %>%
# dplyr::mutate(rp.contact.field.user_age = ifelse(rp.contact.field.user_age > 1960,
# 2023 - rp.contact.field.user_age, #todo: fix more pernamently
# ifelse(rp.contact.field.user_age < 0, NA, rp.contact.field.user_age)))
# Create subsets of the data based on valid app user ID's
#plhdata_org_clean <- plhdata_org_clean %>% dplyr::filter(!is.na(app_version))
# add in country variable
plhdata_org_clean <- plhdata_org_clean %>% mutate(country = country)
if (country == "Tanzania"){
if (study == "Optimisation"){
plhdata_org_clean <- plhdata_org_clean #%>% filter(Org == "Optimisation Study")
} else if (study == "Pilot") {
plhdata_org_clean <- plhdata_org_clean %>% mutate(PilotSite = replace_na(PilotSite, "Unknown"))
# plhdata_org_clean <- plhdata_org_clean %>% filter(Org == "ICS")
} else {
plhdata_org_clean <- plhdata_org_clean %>% mutate(ClusterName = replace_na(ClusterName, "Unknown"))
}
} else if (country == "South Africa"){
plhdata_org_clean <- plhdata_org_clean %>% filter(Org %in% c("Amathuba", "Joy", "Dlalanathi", "Nontobeko"))
}
# Sorting Name Changes --------------------------------------------------
# v_all <- c()
# if (length(grep("0.16.2", unique(plhdata_org_clean$app_version))) !=0) { v_all <- c(v_all, "0.16.2")}
# if (length(grep("0.16.3", unique(plhdata_org_clean$app_version))) !=0) { v_all <- c(v_all, "0.16.3")}
# if (length(grep("0.16.4", unique(plhdata_org_clean$app_version))) !=0) { v_all <- c(v_all, "0.16.4")}
# if (length(v_all) > 0){
# old_names <- c("a_1_final", "a_2_final", "a_3_final", "a_4_final", "a_5_part_1_final", "a_5_part_2_final", "a_6_final", "a_7_part_1_final")
# new_names <- c("ppf", "ppp", "ps", "cme", "fs", "fi", "cmp", "cs")
# df_names <- data.frame(old_names, new_names)
# for (v in v_all){
# for (i in 1:nrow(df_names)){
# old_name = df_names[i,1]
# new_name = df_names[i,2]
# plhdata_org_clean <- plhdata_org_clean %>%
# map_df(.x = v, #c("v0.16.2", "v0.16.3", "v0.16.4"),
# .f = ~version_variables_rename(old_name = old_name, new_name = new_name, new_name_v = .x, old_system_replacement = TRUE))
# # todo: doesn't work for v?? Should explore that. But for now, in this extra loop
# }
# }
#
# for (v in c("v0.16.4")){ # and other versions?
# for (i in 1:nrow(df_names)){
# old_name = df_names[i,1]
# new_name = df_names[i,2]
# plhdata_org_clean <- plhdata_org_clean %>%
# map_df(.x = v, #c("v0.16.2", "v0.16.3", "v0.16.4"),
# .f = ~version_variables_rename(old_name = old_name, new_name = new_name, new_name_v = .x, old_system_replacement = TRUE, survey = "final"))
# # todo: doesn't work for v?? Should explore that. But for now, in this extra loop
# }
# }
# }
# We first rename the _v system into the old system of a_1 etc
# We then rename into the new naming system, where it can be directly renamed. However, some cannot.
# Which cannot:
# rp.contact.field.survey_welcome_a_3_final, rp.contact.field.survey_welcome_a_4_final, rp.contact.field.survey_welcome_a_6_final, rp.contact.field.survey_welcome_a_7_part_1_final
# any after a7p1?
# Next steps here:
# did the question change for any of these. Need to check.
# p7a2, a3, 8, 9 - what were those questions before? what are they now? Check and update.
# what to do where the question changed?
# display differently for optimisation than for pilot if optimisation has different questions? Discuss.
if (!is.null(plhdata_org_clean$rp.contact.field.survey_welcome_a_1_final)){
plhdata_org_clean <- plhdata_org_clean %>%
mutate(rp.contact.field.survey_welcome_ppf = ifelse(!is.na(rp.contact.field.survey_welcome_ppf), rp.contact.field.survey_welcome_ppf, rp.contact.field.survey_welcome_a_1_final),
rp.contact.field.survey_welcome_ppp = ifelse(!is.na(rp.contact.field.survey_welcome_ppp), rp.contact.field.survey_welcome_ppp, rp.contact.field.survey_welcome_a_2_final),
rp.contact.field.survey_welcome_fin_s = ifelse(!is.na(rp.contact.field.survey_welcome_fin_s), rp.contact.field.survey_welcome_fin_s, rp.contact.field.survey_welcome_a_5_part_1_final),
rp.contact.field.survey_welcome_fin_fi = ifelse(!is.na(rp.contact.field.survey_welcome_fin_fi), rp.contact.field.survey_welcome_fin_fi, rp.contact.field.survey_welcome_a_5_part_2_final)) %>%
mutate(rp.contact.field.survey_final_ppf = ifelse(!is.na(rp.contact.field.survey_final_ppf), rp.contact.field.survey_final_ppf, rp.contact.field.survey_final_a_1_final),
rp.contact.field.survey_final_ppp = ifelse(!is.na(rp.contact.field.survey_final_ppp), rp.contact.field.survey_final_ppp, rp.contact.field.survey_final_a_2_final),
rp.contact.field.survey_final_fin_s = ifelse(!is.na(rp.contact.field.survey_final_fin_s), rp.contact.field.survey_final_fin_s, rp.contact.field.survey_final_a_5_part_1_final),
rp.contact.field.survey_final_fin_fi = ifelse(!is.na(rp.contact.field.survey_final_fin_fi), rp.contact.field.survey_final_fin_fi, rp.contact.field.survey_final_a_5_part_2_final))
}
plhdata_org_clean <- plhdata_org_clean %>%
mutate(rp.contact.field.user_gender = ifelse(is.na(rp.contact.field.user_gender), "undefined",
rp.contact.field.user_gender))
# todo: following not working
#plhdata_org_clean <- plhdata_org_clean %>%
# map2_df(.x = c("a_1_final", "a_2_final", "a_3_final"),
# .y = c("ppf", "ppp", "ps"),
# .f = ~version_variables_rename(old_name = .x, new_name = .y))
##plhdata_org_clean$rp.contact.field.survey_welcome_a_1_final[281:290]
##plhdata_org_clean$rp.contact.field.survey_welcome_ppf_v0.16.2[281:290]
#
#plhdata_org_clean$rp.contact.field.survey_welcome_a_2_final[281:290]
#plhdata_org_clean$rp.contact.field.survey_welcome_ppp_v0.16.2[281:290]##
#
#plhdata_org_clean$rp.contact.field.survey_welcome_a_3_final[281:290]
#plhdata_org_clean$rp.contact.field.survey_welcome_ps_v0.16.2[281:290]
# Tidying up for together/individual and modular/workshop skins
# json_data <- NULL
# for (i in c("self_care", "1on1", "praise", "instruct", "stress", "money", "rules", "consequence", "solve", "safe", "crisis", "celebrate")){
# # which variables to select?
# json_data[[i]] <- data.frame(jsonlite::fromJSON(paste0("~/GitHub/parenting-app-ui/packages/app-data/sheets/data_list/generated/w_", i, "_task_gs.json")))
# } # w_srh_task_gs.json
# saveRDS(json_data, file = "data/json_data.RDS")
json_data <- readRDS(file = "data/json_data.RDS")
#json_data_af <- NULL
#for (i in c("srh", "svp", "learn", "grief")){
# json_data_todo <- jsonlite::fromJSON(paste0("~/GitHub/plh-teens-app-tz-content/app_data/sheets/data_list/generated/w_", i, "_task_gs.json"))
# json_data_todo <- json_data_todo$rows
# json_data_todo <- json_data_todo %>% filter(individual == TRUE)
# json_data_af[[i]] <- json_data_todo$completed_field
#}
#saveRDS(json_data_af, file = "data/json_data_af.RDS")
json_data_af <- readRDS(file = "data/json_data_af.RDS")
if (study %in% c("Optimisation", "RCT")){
plhdata_org_clean_mod <- plhdata_org_clean %>% filter(rp.contact.field._app_skin %in% c("modular", "default"))
# Esmee - what is the definition of completion at the moment for workshop skin?
# which rows.id do they have to have == true in in these to say they've completed?
total_completed_ind <- NULL
total_completed_tog <- NULL
j = 0
for (i in c("self_care", "1on1", "praise", "instruct", "stress", "solve", "money", "rules", "consequence", "safe", "crisis", "celebrate")){
# which variables to select?
json_data_i <- json_data[[i]]
# rows.id, rows.individual, rows.together, rows.completed_field
json_data_i <- json_data_i %>% dplyr::select(c(rows.id, rows.individual, rows.together, rows.completed_field)) %>%
filter(!rows.id %in% c("home_practice", "hp_review"))
if (i == "self_care" && study %in% c("RCT", "WASH")) {
json_data_i$rows.individual[which(json_data_i$rows.completed_field %in% c("task_gp_w_self_care_welcome_individual_completed", "task_gp_w_self_care_survey_completed"))] <- FALSE
}
if (i == "celebrate" && study %in% c("RCT", "WASH")) {
json_data_i$rows.individual[which(json_data_i$rows.completed_field %in% c("task_gp_w_celebrate_survey_activity_completed"))] <- FALSE
}
json_data_i_ind <- json_data_i %>% filter(rows.individual == TRUE)
completed_rows_ind <- paste0("rp.contact.field.", json_data_i_ind$rows.completed_field)
json_data_i_tog <- json_data_i %>% filter(rows.together == TRUE)
completed_rows_tog <- paste0("rp.contact.field.", json_data_i_tog$rows.completed_field)
plhdata_org_clean_mod_inds <- add_na_variable(plhdata_org_clean_mod, completed_rows_ind)
plhdata_org_clean_mod_inds <- plhdata_org_clean_mod_inds %>%
filter(rp.contact.field.workshop_path != "together") %>%
dplyr::select(completed_rows_ind) %>%
dplyr::mutate(across(everything(), ~as.numeric(as.logical(.))))
plhdata_org_clean_mod_inds <- plhdata_org_clean_mod_inds %>%
dplyr::mutate(total_completed := rowSums(., na.rm = TRUE)/length(.) * 100)
plhdata_org_clean_mod_tog <- add_na_variable(plhdata_org_clean_mod, completed_rows_tog)
plhdata_org_clean_mod_tog <- plhdata_org_clean_mod_tog %>%
filter(rp.contact.field.workshop_path == "together") %>%
dplyr::select(completed_rows_tog) %>%
dplyr::mutate(across(everything(), ~as.numeric(as.logical(.))))
plhdata_org_clean_mod_tog <- plhdata_org_clean_mod_tog %>%
dplyr::mutate(total_completed := rowSums(., na.rm = TRUE)/length(.) * 100)
j = j + 1
total_completed_ind[[j]] <- plhdata_org_clean_mod_inds$total_completed
total_completed_tog[[j]] <- plhdata_org_clean_mod_tog$total_completed
}
names(total_completed_ind) <- data_completion_level
names(total_completed_tog) <- data_completion_level
plhdata_org_clean_mod_ind <- plhdata_org_clean_mod %>% filter(rp.contact.field.workshop_path != "together")
plhdata_org_clean_mod_tog <- plhdata_org_clean_mod %>% filter(rp.contact.field.workshop_path == "together")
total_completed_ind <- data.frame(app_user_id = plhdata_org_clean_mod_ind$app_user_id, total_completed_ind)
total_completed_tog <- data.frame(app_user_id = plhdata_org_clean_mod_tog$app_user_id, total_completed_tog)
modular_completion <- rbind(total_completed_ind, total_completed_tog)
plhdata_org_clean <- dplyr::full_join(plhdata_org_clean, modular_completion, by = "app_user_id", suffix = c("", ".mod"))
plhdata_org_clean <- plhdata_org_clean %>% mutate(rp.contact.field.w_self_care_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_self_care_completion_level.mod, rp.contact.field.w_self_care_completion_level),
rp.contact.field.w_1on1_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_1on1_completion_level.mod, rp.contact.field.w_1on1_completion_level),
rp.contact.field.w_praise_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_praise_completion_level.mod, rp.contact.field.w_praise_completion_level),
rp.contact.field.w_instruct_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_instruct_completion_level.mod, rp.contact.field.w_instruct_completion_level),
rp.contact.field.w_stress_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_stress_completion_level.mod, rp.contact.field.w_stress_completion_level),
rp.contact.field.w_solve_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_solve_completion_level.mod, rp.contact.field.w_solve_completion_level),
rp.contact.field.w_money_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_money_completion_level.mod, rp.contact.field.w_money_completion_level),
rp.contact.field.w_rules_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_rules_completion_level.mod, rp.contact.field.w_rules_completion_level),
rp.contact.field.w_consequence_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_consequence_completion_level.mod, rp.contact.field.w_consequence_completion_level),
rp.contact.field.w_safe_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_safe_completion_level.mod, rp.contact.field.w_safe_completion_level),
rp.contact.field.w_crisis_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_crisis_completion_level.mod, rp.contact.field.w_crisis_completion_level),
rp.contact.field.w_celebrate_completion_level = ifelse(rp.contact.field._app_skin == "modular", rp.contact.field.w_celebrate_completion_level.mod, rp.contact.field.w_celebrate_completion_level))
}
# and for our new modules
if (study == "RCT"){
var_names <- names(plhdata_org_clean)
completion_var <- NULL
new_modules <- c("learn", "svp", "grief", "srh")
for (module_name in new_modules){
completed_mods <- paste0("rp.contact.field.", json_data_af[[module_name]])
plhdata_org_clean <- add_na_variable(plhdata_org_clean, variable = completed_mods)
selected_var_x <- plhdata_org_clean %>% dplyr::select(all_of(c("app_user_id", completed_mods)))
selected_var_x <- selected_var_x %>%
dplyr::mutate(across(completed_mods, ~as.numeric(as.logical(.)))) %>%
dplyr::select(-c(paste0("rp.contact.field.task_gp_w_", module_name, "_home_practice_completed")))
completion_var[[which(new_modules == module_name)]] <- selected_var_x %>%
dplyr::mutate("rp.contact.field.w_{module_name}_completion_level" := rowSums(.[2:length(selected_var_x)], na.rm = TRUE)/length(.[2:length(selected_var_x)]) * 100) %>%
dplyr::select("app_user_id", paste0("rp.contact.field.w_", module_name, "_completion_level"))
}
completion_var <- full_join(full_join(full_join(completion_var[[1]], completion_var[[2]]), completion_var[[3]]), completion_var[[4]])
plhdata_org_clean <- full_join(plhdata_org_clean, completion_var)
new_modules_completion_level <- c("rp.contact.field.w_learn_completion_level", "rp.contact.field.w_svp_completion_level",
"rp.contact.field.w_grief_completion_level", "rp.contact.field.w_srh_completion_level")
}
#head(plhdata_org_clean$rp.contact.field._app_skin)
#head(plhdata_org_clean$rp.contact.field.w_self_care_completion_level)
#head(xx$rp.contact.field.w_self_care_completion_level)
# More cleaning
# RCT TODO here
if (study != "RCT"){
if (study != "WASH"){
plhdata_org_clean$rp.contact.field.survey_welcome_and_setup_completion_level <- as.numeric(plhdata_org_clean$rp.contact.field.survey_welcome_and_setup_completion_level)
plhdata_org_clean$rp.contact.field.user_age <- as.numeric(plhdata_org_clean$rp.contact.field.user_age)
plhdata_org_clean$rp.contact.field.household_adults <- as.numeric(plhdata_org_clean$rp.contact.field.household_adults)
plhdata_org_clean$rp.contact.field.household_teens <- as.numeric(plhdata_org_clean$rp.contact.field.household_teens)
plhdata_org_clean$rp.contact.field.household_babies <- as.numeric(plhdata_org_clean$rp.contact.field.household_babies)
plhdata_org_clean$rp.contact.field.household_children <- as.numeric(plhdata_org_clean$rp.contact.field.household_children)
plhdata_org_clean$rp.contact.field.w_1on1_diff_started_completed <- as.numeric(plhdata_org_clean$rp.contact.field.w_1on1_diff_started_completed)
plhdata_org_clean$rp.contact.field.w_self_care_diff_started_completed <- as.numeric(plhdata_org_clean$rp.contact.field.w_self_care_diff_started_completed)
}
}
if (study != "WASH"){
plhdata_org_clean$rp.contact.field.parent_point_count_relax_w_self_care <- as.numeric(plhdata_org_clean$rp.contact.field.parent_point_count_relax_w_self_care)
}
plhdata_org_clean <- plhdata_org_clean %>%
mutate(across(ends_with("_completion_level"), ~as.numeric(.)))
plhdata_org_clean <- plhdata_org_clean %>%
mutate(across(starts_with("rp.contact.field.parent_point"), ~as.numeric(.)))
plhdata_org_clean$rp.contact.field.app_launch_count <- as.numeric(plhdata_org_clean$rp.contact.field.app_launch_count)
# plhdata_org_clean$rp.contact.field.first_app_open <- as.Date(plhdata_org_clean$rp.contact.field.first_app_open)
plhdata_org_clean <- plhdata_org_clean %>%
mutate(across(starts_with("rp.contact.field.app_launch_count"), ~as.numeric(.)))
## Data Analysis ## --------------------------------------------------------
# workshop_path edits ----------
plhdata_org_clean <- add_na_variable(plhdata_org_clean, c("rp.contact.field.workshop_path_user_choice",
"rp.contact.field.workshop_path"))
plhdata_org_clean <- plhdata_org_clean %>%
mutate(rp.contact.field.workshop_path = ifelse(is.na(rp.contact.field.workshop_path_user_choice),
rp.contact.field.workshop_path,
ifelse(rp.contact.field.workshop_path_user_choice == "false",
"default",
rp.contact.field.workshop_path)))
# Variables Set up ---------------------------------------
#completion_vars <- c("Self Care", "One-on-one Time", "Praise", "Positive Instructions", "Managing Stress", "Family Budgets", "Rules", "Calm Consequences", "Problem Solving", "Teen Safety", "Dealing with Crisis","Celebration & Next Steps")
# TODO: add summary plot completion level in
#summary_plot_completion_level <- multiple_plot_output(columns_to_summarise = data_completion_level,
# replace = "rp.contact.field.w_", replace_after = "_completion_level")
#names(summary_plot_completion_level) <- completion_vars
#summary_plot_completion_level$`One-on-one Time`
# TAB 3 - PP -------------------------
# HABITS by workshop week ------------------------------------------------------------------------------------
##Priority 20
#App-opens
data_app_opens <- c("rp.contact.field.app_launch_count","rp.contact.field.app_launch_count_w_1on1", "rp.contact.field.app_launch_count_w_self_care",
"rp.contact.field.app_launch_count_w_praise","rp.contact.field.app_launch_count_w_instruct",
"rp.contact.field.app_launch_count_w_stress", "rp.contact.field.app_launch_count_w_solve",
"rp.contact.field.app_launch_count_w_money",
"rp.contact.field.app_launch_count_w_rules", "rp.contact.field.app_launch_count_w_consequence",
"rp.contact.field.app_launch_count_w_safe",
"rp.contact.field.app_launch_count_w_crisis", "rp.contact.field.app_launch_count_w_celebrate")
if (study == "RCT"){
data_app_opens_neat <- c("Overall", "1on1 (2)", "Self Care (1)", "Praise (3)", "Positive Instructions(4)",
"Managing Stress(5)", "Family Budget(6)","Rules(7)", "Calm Consequences(8)",
"Problem Solving(9)", "Teen Safety(10)", "Crisis(11)", "Celebration & Next Steps(12)")
} else {
data_app_opens_neat <- c("Overall", "1on1 (2)", "Self Care (1)", "Praise (3)", "Positive Instructions(4)",
"Managing Stress(5)", "Problem Solving(6)", "Family Budget(7)","Rules(8)", "Calm Consequences(9)",
"Teen Safety(10)", "Crisis(11)", "Celebration & Next Steps(12)")
}
# Tab ?? ----------
#Define workshop week order
# if (study == "RCT"){
week_order <- c("Self care", "1on1", "Praise", "Instruct", "Stress", "Solve", "Money", "Rules", "Consequence", "Safe",
"Crisis", "Celebrate" )
# } else {
# week_order <- c("Self care", "1on1", "Praise", "Instruct", "Stress", "Money", "Rules", "Consequence", "Solve", "Safe",
# "Crisis", "Celebrate" )
# }
#Each habit across workshop weeks
#relax points in each week
relax_workshop_vars <- c( "rp.contact.field.parent_point_count_relax_w_self_care", "rp.contact.field.parent_point_count_relax_w_1on1",
"rp.contact.field.parent_point_count_relax_w_praise", "rp.contact.field.parent_point_count_relax_w_instruct",
"rp.contact.field.parent_point_count_relax_w_stress", "rp.contact.field.parent_point_count_relax_w_solve",
"rp.contact.field.parent_point_count_relax_w_money",
"rp.contact.field.parent_point_count_relax_w_rules", "rp.contact.field.parent_point_count_relax_w_consequence",
"rp.contact.field.parent_point_count_relax_w_safe",
"rp.contact.field.parent_point_count_relax_w_crisis","rp.contact.field.parent_point_count_relax_w_celebrate")
# treat_yourself points in each week
treat_yourself_workshop_vars <- c( "rp.contact.field.parent_point_count_treat_yourself_w_self_care", "rp.contact.field.parent_point_count_treat_yourself_w_1on1",
"rp.contact.field.parent_point_count_treat_yourself_w_praise", "rp.contact.field.parent_point_count_treat_yourself_w_instruct",
"rp.contact.field.parent_point_count_treat_yourself_w_stress", "rp.contact.field.parent_point_count_treat_yourself_w_solve",
"rp.contact.field.parent_point_count_treat_yourself_w_money",
"rp.contact.field.parent_point_count_treat_yourself_w_rules", "rp.contact.field.parent_point_count_treat_yourself_w_consequence",
"rp.contact.field.parent_point_count_treat_yourself_w_safe",
"rp.contact.field.parent_point_count_treat_yourself_w_crisis","rp.contact.field.parent_point_count_treat_yourself_w_celebrate")
# praise_yourself points in each week
praise_yourself_workshop_vars <- c( "rp.contact.field.parent_point_count_praise_yourself_w_self_care", "rp.contact.field.parent_point_count_praise_yourself_w_1on1",
"rp.contact.field.parent_point_count_praise_yourself_w_praise", "rp.contact.field.parent_point_count_praise_yourself_w_instruct",
"rp.contact.field.parent_point_count_praise_yourself_w_stress", "rp.contact.field.parent_point_count_praise_yourself_w_solve",
"rp.contact.field.parent_point_count_praise_yourself_w_money",
"rp.contact.field.parent_point_count_praise_yourself_w_rules", "rp.contact.field.parent_point_count_praise_yourself_w_consequence",
"rp.contact.field.parent_point_count_praise_yourself_w_safe",
"rp.contact.field.parent_point_count_praise_yourself_w_crisis","rp.contact.field.parent_point_count_praise_yourself_w_celebrate")
# spend_time points in each week
spend_time_workshop_vars <- c( "rp.contact.field.parent_point_count_spend_time_w_self_care", "rp.contact.field.parent_point_count_spend_time_w_1on1",
"rp.contact.field.parent_point_count_spend_time_w_praise", "rp.contact.field.parent_point_count_spend_time_w_instruct",
"rp.contact.field.parent_point_count_spend_time_w_stress", "rp.contact.field.parent_point_count_spend_time_w_solve",
"rp.contact.field.parent_point_count_spend_time_w_money",
"rp.contact.field.parent_point_count_spend_time_w_rules", "rp.contact.field.parent_point_count_spend_time_w_consequence",
"rp.contact.field.parent_point_count_spend_time_w_safe",
"rp.contact.field.parent_point_count_spend_time_w_crisis","rp.contact.field.parent_point_count_spend_time_w_celebrate")
# praise_teen in each week
praise_teen_workshop_vars <- c( "rp.contact.field.parent_point_count_praise_teen_w_self_care", "rp.contact.field.parent_point_count_praise_teen_w_1on1",
"rp.contact.field.parent_point_count_praise_teen_w_praise", "rp.contact.field.parent_point_count_praise_teen_w_instruct",
"rp.contact.field.parent_point_count_praise_teen_w_stress","rp.contact.field.parent_point_count_praise_teen_w_solve",
"rp.contact.field.parent_point_count_praise_teen_w_money",
"rp.contact.field.parent_point_count_praise_teen_w_rules", "rp.contact.field.parent_point_count_praise_teen_w_consequence",
"rp.contact.field.parent_point_count_praise_teen_w_safe",
"rp.contact.field.parent_point_count_praise_teen_w_crisis","rp.contact.field.parent_point_count_praise_teen_w_celebrate")
# instruct_positively points in each week
instruct_positively_workshop_vars <- c( "rp.contact.field.parent_point_count_instruct_positively_w_self_care", "rp.contact.field.parent_point_count_instruct_positively_w_1on1",
"rp.contact.field.parent_point_count_instruct_positively_w_praise", "rp.contact.field.parent_point_count_instruct_positively_w_instruct",
"rp.contact.field.parent_point_count_instruct_positively_w_stress", "rp.contact.field.parent_point_count_instruct_positively_w_solve",
"rp.contact.field.parent_point_count_instruct_positively_w_money",
"rp.contact.field.parent_point_count_instruct_positively_w_rules", "rp.contact.field.parent_point_count_instruct_positively_w_consequence",
"rp.contact.field.parent_point_count_instruct_positively_w_safe",
"rp.contact.field.parent_point_count_instruct_positively_w_crisis","rp.contact.field.parent_point_count_instruct_positively_w_celebrate")
# breathe points in each week
breathe_workshop_vars <- c( "rp.contact.field.parent_point_count_breathe_w_self_care", "rp.contact.field.parent_point_count_breathe_w_1on1",
"rp.contact.field.parent_point_count_breathe_w_praise", "rp.contact.field.parent_point_count_breathe_w_instruct",
"rp.contact.field.parent_point_count_breathe_w_stress", "rp.contact.field.parent_point_count_breathe_w_solve",
"rp.contact.field.parent_point_count_breathe_w_money",
"rp.contact.field.parent_point_count_breathe_w_rules", "rp.contact.field.parent_point_count_breathe_w_consequence",
"rp.contact.field.parent_point_count_breathe_w_safe",
"rp.contact.field.parent_point_count_breathe_w_crisis","rp.contact.field.parent_point_count_breathe_w_celebrate")
# money points in each week
money_workshop_vars <- c( "rp.contact.field.parent_point_count_money_w_self_care", "rp.contact.field.parent_point_count_money_w_1on1",
"rp.contact.field.parent_point_count_money_w_praise", "rp.contact.field.parent_point_count_money_w_instruct",
"rp.contact.field.parent_point_count_money_w_stress", "rp.contact.field.parent_point_count_money_w_solve",
"rp.contact.field.parent_point_count_money_w_money",
"rp.contact.field.parent_point_count_money_w_rules", #"rp.contact.field.parent_point_count_money_w_consequence",
"rp.contact.field.parent_point_count_money_w_safe",
#"rp.contact.field.parent_point_count_money_w_crisis",
"rp.contact.field.parent_point_count_money_w_celebrate")
# consequence points in each week
consequence_workshop_vars <- c( "rp.contact.field.parent_point_count_consequence_w_self_care", "rp.contact.field.parent_point_count_consequence_w_1on1",
"rp.contact.field.parent_point_count_consequence_w_praise", "rp.contact.field.parent_point_count_consequence_w_instruct",
"rp.contact.field.parent_point_count_consequence_w_stress", "rp.contact.field.parent_point_count_consequence_w_solve",
"rp.contact.field.parent_point_count_consequence_w_money",
#"rp.contact.field.parent_point_count_consequence_w_rules", "rp.contact.field.parent_point_count_consequence_w_crisis",
"rp.contact.field.parent_point_count_consequence_w_consequence",
"rp.contact.field.parent_point_count_consequence_w_safe",
"rp.contact.field.parent_point_count_consequence_w_celebrate")
# safe points in each week
safe_workshop_vars <- c( "rp.contact.field.parent_point_count_safe_w_self_care", "rp.contact.field.parent_point_count_safe_w_1on1",
"rp.contact.field.parent_point_count_safe_w_praise", "rp.contact.field.parent_point_count_safe_w_instruct",
"rp.contact.field.parent_point_count_safe_w_stress", "rp.contact.field.parent_point_count_safe_w_solve",
"rp.contact.field.parent_point_count_safe_w_money",
"rp.contact.field.parent_point_count_safe_w_rules", "rp.contact.field.parent_point_count_safe_w_consequence",
"rp.contact.field.parent_point_count_safe_w_safe",
"rp.contact.field.parent_point_count_safe_w_crisis","rp.contact.field.parent_point_count_safe_w_celebrate")
## Home Practice ------------------------------------------------------------------
data_hp_started <- c("rp.contact.field.w_1on1_hp_review_started", "rp.contact.field.w_praise_hp_review_started",
"rp.contact.field.w_instruct_hp_review_started", "rp.contact.field.w_stress_hp_review_started",
"rp.contact.field.w_solve_hp_review_started",
"rp.contact.field.w_money_hp_review_started", "rp.contact.field.w_rules_hp_review_started",
"rp.contact.field.w_consequence_hp_review_started", "rp.contact.field.w_safe_hp_review_started",
"rp.contact.field.w_crisis_hp_review_started")
# RCT TODO
# plhdata_org_clean <- plhdata_org_clean %>%
# dplyr::mutate(rp.contact.field.w_stress_hp_done = ifelse(rp.contact.field.w_stress_hp_talk_done == "yes" &
# rp.contact.field.w_stress_hp_breathe_done == "yes",
# "yes",
# "no"))
data_hp_done <- c("rp.contact.field.w_1on1_hp_done", "rp.contact.field.w_praise_hp_done", "rp.contact.field.w_instruct_hp_done", "rp.contact.field.w_stress_hp_talk_done", "rp.contact.field.w_solve_hp_done",
"rp.contact.field.w_stress_hp_breathe_done","rp.contact.field.w_money_hp_done", "rp.contact.field.w_rules_hp_done", "rp.contact.field.w_consequence_hp_done",
"rp.contact.field.w_safe_hp_done", "rp.contact.field.w_crisis_hp_done")
# NB No mood 'review' for week 3 home practice (praise)
data_hp_mood <- c("rp.contact.field.w_1on1_hp_mood", "rp.contact.field.w_instruct_hp_mood", "rp.contact.field.w_stress_hp_breathe_mood", "rp.contact.field.w_stress_hp_talk_mood",
"rp.contact.field.w_solve_hp_mood", "rp.contact.field.w_money_hp_mood", "rp.contact.field.w_rules_hp_mood", "rp.contact.field.w_consequence_hp_mood",
"rp.contact.field.w_safe_hp_mood", "rp.contact.field.w_crisis_hp_mood")
# TODO: this should work in function
# plhdata_org_clean <- add_na_variable(variable = data_hp_started)
# plhdata_org_clean <- add_na_variable(variable = data_hp_done)
# plhdata_org_clean <- add_na_variable(variable = data_hp_mood)
challenge_vars <- c("rp.contact.field.w_1on1_hp_challenge_list", "rp.contact.field.w_instruct_hp_challenge_list",
"rp.contact.field.w_stress_hp_challenge_list", "rp.contact.field.w_solve_hp_challenge_list", "rp.contact.field.w_money_hp_challenge_list",
"rp.contact.field.w_rules_hp_challenge_list", "rp.contact.field.w_consequence_hp_challenge_list",
"rp.contact.field.w_safe_hp_challenge_list",
"rp.contact.field.w_crisis_hp_challenge_list")
chall_ap_vars <- c("rp.contact.field.w_1on1_hp_challenge", "rp.contact.field.w_instruct_hp_challenge",
"rp.contact.field.w_stress_hp_challenge", "rp.contact.field.w_solve_hp_challenge", "rp.contact.field.w_money_hp_challenge",
"rp.contact.field.w_rules_hp_challenge", "rp.contact.field.w_consequence_hp_challenge",
"rp.contact.field.w_safe_hp_challenge",
"rp.contact.field.w_crisis_hp_challenge")
# NB No challenge for week 3 home practice (praise)
data_hp_chall <- c("hp_list_challenges_1on1", "hp_list_challenges_instruct", "hp_list_challenges_stress", "hp_list_challenges_solve", "hp_list_challenges_money", "hp_list_challenges_rules",
"hp_list_challenges_consequence", "hp_list_challenges_safe", "hp_list_challenges_crisis")
# parent library ------------------------------------------------------------------
data_library <- c("rp.contact.field.click_hs_parent_centre_count", "rp.contact.field.click_pc_help_count",
"rp.contact.field.click_pc_my_tips_count", "rp.contact.field.click_pc_essential_tools_count",
"rp.contact.field.click_pc_covid_count", "rp.contact.field.click_pc_customisation_count",
"rp.contact.field.click_pc_relax_and_activities_count", "rp.contact.field.click_pc_support_contacts_count",
"rp.contact.field.click_pc_evidence_base_count", "rp.contact.field.click_pc_technical_support_count",
"rp.contact.field.click_pc_message_archive_count","rp.contact.field.click_pc_bereavement_count")
# Down to data_library
# Completion status of baseline survey ------------------------------------------------
# plhdata_org_clean %>%
# split(.$Org) %>%
# map(~summary_table(data = .x, factor = NULL, columns_to_summarise = rp.contact.field.survey_welcome_complppplheted, replace = "rp.contact.field.survey"))
plhdata_org_clean1 <- plhdata_org_clean %>% dplyr::filter(is.na(app_user_id))
if (nrow(plhdata_org_clean1)>1) stop("NA app user ID. Check YourParentAppCode is correct.")
plhdata_org_clean <- plhdata_org_clean %>% dplyr::filter(app_user_id != "2d0badbfbfe07360")
##################################
##################################
### Notification Data Analysis ###
##################################
##################################
# download push notification data
if (study != "WASH"){
nf_data <- get_nf_data(site = plh_con, UIC_Tracker = UIC_Tracker_Use, filter = TRUE,
study = study, country = country, app_user_id = "app_user_id")
}