-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtlf-qc.qmd
More file actions
208 lines (173 loc) · 5.91 KB
/
tlf-qc.qmd
File metadata and controls
208 lines (173 loc) · 5.91 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
---
title: "QC Report"
format: html
date: "`r Sys.Date()`"
editor: visual
execute:
keep-md: true
---
```{r, echo = FALSE}
library(waldo)
library(ellmer)
library(stringr)
```
This is the QC report dated `r Sys.Date()`. The report compares the datasets in the `pilot5-submission/pilot5-input/adamdata` directory with the datasets in the `~/GitHub/submissions-pilot3-adam/submission/adam` directory. The datasets are compared using the `diffdf` package.
This run was initiated by `r Sys.getenv("GITHUB_ACTOR")` on the `r Sys.getenv("GITHUB_REF")` Git ref.
```{r session_info}
#| echo: false
sessionInfo()
```
```{r path_setup}
pilot3_out_path <- "pilot5-submission/pilot5-output/pilot3-tlfs/out"
pilot5_out_path <- "pilot5-submission/pilot5-output/pilot5-tlfs/out"
pilot5_out_files <- list.files(pilot5_out_path, pattern = ".out")
pilot3_rtf_path <- "pilot5-submission/pilot5-output/pilot3-tlfs/rtf"
pilot5_rtf_path <- "pilot5-submission/pilot5-output/pilot5-tlfs/rtf"
pilot5_rtf_files <- list.files(pilot5_rtf_path, pattern = ".rtf")
pilot3_pdf_path <- "pilot5-submission/pilot5-output/pilot3-tlfs/pdf"
pilot5_pdf_path <- "pilot5-submission/pilot5-output/pilot5-tlfs/pdf"
pilot5_pdf_files <- list.files(pilot5_pdf_path, pattern = ".pdf")
chat <- chat_anthropic()
# nolint start: line_length_linter
prompt <- "compare these two images and provide a detailed list of any differences found between them? Also, please provide an overall assessment of whether these images appear to be similar enough where a human reviewer would draw the same general conclusion. Finally, give a score from 0-100 of how similar the images are, where 100 is an exact pixel-perfect match and 0 is they are completely different."
# nolint end
type_qc_diff <- type_object(
difference_list = type_string(),
same_conclusion = type_boolean(),
difference_score = type_integer()
)
type_qc_diffs <- type_array(items = type_qc_diff)
```
```{r sink_setup}
sink("qc-tlf.Rmd", append = TRUE)
cat("## TLF QC Check Complete!", "\n\n")
cat("Date: ", format(Sys.Date()), "\n")
cat("Run by: ", Sys.getenv("GITHUB_ACTOR"), "\n")
cat("Git Ref: ", Sys.getenv("GITHUB_REF"), "\n")
cat("BASE: ", "Pilot 5 Datasets", "\n")
cat("COMPARE: ", "Pilot 3 Datasets", "\n")
sink()
```
```{r out_compare}
sink("qc-tlf.Rmd", append = TRUE)
for (i in pilot5_out_files) {
new_tlf_path <- file.path(pilot5_out_path, i)
comp_tlf_path <- file.path(pilot3_out_path, sub("pilot5", "pilot3", i))
diffs <- waldo::compare(readLines(new_tlf_path), readLines(comp_tlf_path))
if (length(diffs) > 1) file.create("qc-tlf.fail", showWarnings = TRUE)
cat("<details>\n")
status_emoji <- if (length(diffs) <= 1) "✅" else "❌"
cat(str_glue("<summary>{status_emoji} Dataset: {i}</summary>\n\n"))
cat("\n\n```\n\n")
print(diffs)
cat("```\n\n")
cat("</details>")
cat("\n\n")
}
sink()
```
```{r pdf_compare}
sink("qc-tlf.Rmd", append = TRUE)
for (i in pilot5_pdf_files) {
new_tlf_path <- file.path(pilot5_pdf_path, i)
new_png_path <- sub(".pdf", ".png", new_tlf_path, fixed = TRUE)
comp_tlf_path <- file.path(pilot3_pdf_path, sub("pilot5", "pilot3", i))
comp_png_path <- sub(".pdf", ".png", comp_tlf_path, fixed = TRUE)
system(
paste0("convert -adjoin ", new_tlf_path, " ", new_png_path),
intern = TRUE,
ignore.stdout = TRUE,
ignore.stderr = TRUE,
wait = TRUE
)
system(
paste0("convert -adjoin ", comp_tlf_path, " ", comp_png_path),
intern = TRUE,
ignore.stdout = TRUE,
ignore.stderr = TRUE,
wait = TRUE
)
new_image <- content_image_file(new_png_path)
comp_image <- content_image_file(comp_png_path)
res <- chat$chat_structured(
prompt,
new_image,
comp_image,
type = type_qc_diffs
)
if (!res$same_conclusion) file.create("qc-tlf.fail", showWarnings = TRUE)
cat("<details>\n")
status_emoji <- if (res$same_conclusion) "✅" else "❌"
cat(str_glue("<summary>{status_emoji} TLF: {i} - Score: {res$difference_score}</summary>\n\n"))
cat("\n\n")
print(res$difference_list[[1]])
cat("\n\n")
cat("</details>")
cat("\n\n")
}
sink()
```
```{r rtf_compare}
sink("qc-tlf.Rmd", append = TRUE)
for (i in pilot5_rtf_files) {
new_tlf_path <- file.path(pilot5_rtf_path, i)
new_png_path <- sub(".rtf", ".png", new_tlf_path, fixed = TRUE)
new_pdf_path <- sub(".rtf", ".pdf", new_tlf_path, fixed = TRUE)
comp_tlf_path <- file.path(pilot3_rtf_path, sub("pilot5", "pilot3", i))
comp_png_path <- sub(".rtf", ".png", comp_tlf_path, fixed = TRUE)
comp_pdf_path <- sub(".rtf", ".pdf", comp_tlf_path, fixed = TRUE)
Sys.setenv("LD_LIBRARY_PATH" = paste0("/usr/lib/libreoffice/program:", Sys.getenv("LD_LIBRARY_PATH")))
system(
paste0(
"libreoffice --headless --convert-to pdf --outdir ",
pilot5_rtf_path, " ", new_tlf_path
),
intern = TRUE,
ignore.stdout = FALSE,
ignore.stderr = FALSE,
wait = TRUE
)
system(
paste0(
"libreoffice --headless --convert-to pdf --outdir ",
pilot3_rtf_path, " ", comp_tlf_path
),
intern = TRUE,
ignore.stdout = FALSE,
ignore.stderr = FALSE,
wait = TRUE
)
system(
paste0("convert -adjoin -append ", new_pdf_path, " ", new_png_path),
intern = TRUE,
ignore.stdout = FALSE,
ignore.stderr = FALSE,
wait = TRUE
)
system(
paste0("convert -adjoin -append ", comp_pdf_path, " ", comp_png_path),
intern = TRUE,
ignore.stdout = TRUE,
ignore.stderr = TRUE,
wait = TRUE
)
new_image <- content_image_file(new_png_path)
comp_image <- content_image_file(comp_png_path)
res <- chat$chat_structured(
prompt,
new_image,
comp_image,
type = type_qc_diffs
)
if (!res$same_conclusion) file.create("qc-tlf.fail", showWarnings = TRUE)
cat("<details>\n")
status_emoji <- if (res$same_conclusion) "✅" else "❌"
cat(str_glue("<summary>{status_emoji} TLF: {i} - Score: {res$difference_score}</summary>\n\n"))
cat("\n\n")
print(res$difference_list[[1]])
cat("\n\n")
cat("</details>")
cat("\n\n")
}
sink()
```