-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_pi_folders_to_df.qmd
More file actions
103 lines (96 loc) · 4.42 KB
/
_pi_folders_to_df.qmd
File metadata and controls
103 lines (96 loc) · 4.42 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
```{r}
#| echo: false
#| message: false
#| eval: true
#|
library(flextable)
library(jsonlite)
library(tibble)
library(officer)
read_status <- function(esr_year,headervars){
json_data <- fromJSON(paste("data/uploader_status_",esr_year,".json",sep=""), simplifyVector = FALSE)
cols = c("PI","filename","updated","typechk","namechk",headervars)
last_updated <- json_data$statusupdate
status <- json_data$status
num_pis <- length(status)
df <- as.data.frame(matrix(nrow = 0, ncol = 11))
colnames(df) = cols
for(p in 1:num_pis){
pi= status[[p]]$name
pi_meta=pi
meta_updated <- status[[p]]$newmeta
if(meta_updated==1){pi_meta = paste0(pi," (Metadata updated: ",status[[p]]$newmetaupdate,")","")}
df1 <- as.data.frame(matrix(nrow = 0, ncol = 11))
if(length(status[[p]]$files)>0){
for (f in 1:length(status[[p]]$files)){
file=status[[p]]$files[[f]]
headerchk=file$headerchk
head_vec=c()
for (h in 1:length(headerchk)){
head_vec=c(head_vec,headerchk[h])
}
file_vec=c(pi_meta,file$name,file$updated,file$typechk,file$namechk,head_vec)
df1 <- rbind(df1,file_vec,stringsAsFactors=FALSE)
}
}
else{
file_vec <- vector(mode="character", length=11)
file_vec[1]=pi
df1 <- rbind(df1,file_vec,stringsAsFactors=FALSE)
}
colnames(df1) = cols
df <- rbind(df,df1,stringsAsFactors=FALSE)
}
df_grouped <- as_grouped_data(x = df, groups = c("PI"))
return(list(last_updated=last_updated,df_grouped=df_grouped))
}
make_table <- function(df_grouped){
std_border <- fp_border(color = "#7596b1", width = 1)
as_flextable(df_grouped, hide_grouplabel=TRUE)|>
fontsize(size = 8, part = "all")|>
fontsize(j= "updated",size = 7)|>
bold(j = 1, i = ~ !is.na(PI), bold = FALSE, part = "body") |>
bg(i = ~ !is.na(PI), bg = "#c8d5e0", part = "body") |>
add_header_row(values = c("","Header Columns"), colwidths = c(4, 6)) |>
add_header_row(values = c("","File Status"), colwidths = c(2, 8)) |>
align(i=2:3,align = "left", part = "header") |>
align(i=1,align="center", part = "header") |>
bold(part = "header", bold = TRUE) |>
line_spacing(space=1,part="all") |>
bg(i= ~ typechk == 1, ~ typechk, bg="#66b266") |>
bg(i= ~ namechk == 1, ~ namechk, bg="#66b266") |>
bg(i= ~ year == TRUE, ~ year, bg="#66b266") |>
bg(i= ~ index == TRUE, ~ index, bg="#66b266") |>
bg(i= ~ timeseries == TRUE, ~ timeseries, bg="#66b266") |>
bg(i= ~ namechk == 0, ~ namechk, bg="#ff6666") |>
bg(i= ~ year == FALSE, ~ year, bg="#ff6666") |>
bg(i= ~ index == FALSE, ~ index, bg="#ff6666") |>
bg(i= ~ timeseries == FALSE, ~ timeseries, bg="#ff6666") |>
border_remove() |>
vline(j=2,i=3,border=std_border,part="header") |>
vline(j=4,i=2:3,border=std_border,part="header") |>
hline(j=2:10,i=1,border=std_border,part="header") |>
border_inner(part="body",border=std_border) |>
border_outer(part="all",border=std_border) |>
padding(padding.top=1,padding.left=3,padding.bottom=1,padding.right=3,part = "all") |>
compose(j= "updated", value = as_paragraph(paste(substring(updated,1,10)," ",substring(updated,12,19)))) |>
compose(j= "typechk", value = as_paragraph(""))|>
compose(j= "typechk", value = as_paragraph(ifelse(typechk == 1, "yes", "no")))|>
compose(j= "namechk", value = as_paragraph(""))|>
compose(j= "namechk", value = as_paragraph(ifelse(namechk == 1, "yes", "no")))|>
compose(j= "year", value = as_paragraph(""))|>
compose(j= "year", value = as_paragraph(ifelse(year == TRUE, "yes", "no")))|>
compose(j= "index", value = as_paragraph("none"))|>
compose(j= "index", value = as_paragraph(ifelse(index == TRUE, "yes", "no")))|>
compose(j= "timeseries", value = as_paragraph(""))|>
compose(j= "timeseries", value = as_paragraph(ifelse(timeseries == TRUE, "yes", "no")))|>
compose(j= "metric", value = as_paragraph(""))|>
compose(j= "metric", value = as_paragraph(ifelse(metric == TRUE, "yes", "no")))|>
compose(j= "SEup", value = as_paragraph(""))|>
compose(j= "SEup", value = as_paragraph(ifelse(SEup == TRUE, "yes", "no")))|>
compose(j= "SElo", value = as_paragraph(""))|>
compose(j= "SElo", value = as_paragraph(ifelse(SElo == TRUE, "yes", "no")))|>
set_header_labels(filename = "File Name",updated = "Updated",typechk = "type check", namechk = "name check") |>
width(j= "updated",width=2)
}
```