-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy path02-process_quality_control.R
More file actions
86 lines (67 loc) · 3.33 KB
/
02-process_quality_control.R
File metadata and controls
86 lines (67 loc) · 3.33 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
#' Downloading and processing the quality control worksheet
#' Downloads the quality control values from the google sheet and processes it into a tidy format
library(tidyverse)
library(googlesheets)
library(dynbenchmark)
experiment("03-methods")
## ............................................................................
## QC sheet processing ####
# Download qc & initial processing
tool_qc_sheet <- gs_key("1Mug0yz8BebzWt8cmEW306ie645SBh_tDHwjVw4OFhlE") %>%
gs_read(ws = "qc")
categories <- unique(tool_qc_sheet$category) %>% discard(is.na)
applications <- c("developer_friendly", "user_friendly", "future_proof")
tool_qc_converted <- tool_qc_sheet %>%
filter(active) %>%
tidyr::fill(aspect_id) %>%
mutate(aspect_id = factor(aspect_id, levels = tool_qc_sheet$aspect_id %>% unique() %>%
keep(~!is.na(.)))) %>%
group_by(aspect_id) %>%
tidyr::fill(name, category, weight, aspect, !!applications, references) %>%
mutate_at(vars(!!applications), ~ifelse(is.na(.), FALSE, TRUE)) %>%
ungroup()
tool_cols <- colnames(tool_qc_converted)[seq(which(colnames(tool_qc_converted) == "item")+1, ncol(tool_qc_converted))]
tool_qc_converted <- tool_qc_converted %>% mutate(check_id = row_number())
# create checks
checks <- tool_qc_converted[, colnames(tool_qc_converted) %>% keep(~!(. %in% tool_cols))]
tool_qc_molten <- tool_qc_converted %>%
gather("tool_id", "answer", !!tool_cols)
# process answer, NA coercion warnings are normal here due to check of
tool_qc_processed <- tool_qc_molten %>%
mutate(
answer = ifelse(is.na(answer), "0", answer),
answer_first_char = str_replace(answer, "([\\d\\.]*).*", "\\1"),
answer_description = str_replace(answer, "[\\d\\.]*(.*)", "\\1") %>% trimws()
) %>%
mutate(answer = as.numeric(ifelse(answer_first_char == "", "0", answer_first_char)))
tool_qc_processed <- tool_qc_processed %>%
group_by(tool_id) %>%
filter(!any(is.na(answer))) %>%
ungroup()
tool_qc_processed$answer <- ifelse(is.na(tool_qc_processed$answer), 0, tool_qc_processed$answer)
tool_qc <- tool_qc_processed
write_rds(tool_qc_processed, result_file("tool_qc.rds"))
write_rds(checks, result_file("qc_checks.rds"))
## ............................................................................
## Calculate final qc scores ####
# calculate average category scores
tool_qc_category_scores <- tool_qc %>%
group_by(tool_id, category) %>%
summarise(qc_score = sum(answer * item_weight * weight)/sum(item_weight * weight)) %>%
ungroup()
# use the average category scores to calculate the final qc_score
tool_qc_scores <- tool_qc_category_scores %>%
group_by(tool_id) %>%
summarise(qc_score = mean(qc_score)) %>%
arrange(-qc_score) %>%
ungroup()
# calculate the average application scores
tool_qc_application_scores <- tool_qc %>%
gather(application, application_applicable, !!qc_applications$application) %>%
filter(application_applicable) %>%
group_by(tool_id, application) %>%
summarise(score = sum(answer * item_weight * weight)/sum(item_weight * weight)) %>%
ungroup()
write_rds(tool_qc_scores, result_file("tool_qc_scores.rds"))
write_rds(tool_qc_category_scores, result_file("tool_qc_category_scores.rds"))
write_rds(tool_qc_application_scores, result_file("tool_qc_application_scores.rds"))