-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweekly.qmd
More file actions
183 lines (151 loc) · 4.7 KB
/
Copy pathweekly.qmd
File metadata and controls
183 lines (151 loc) · 4.7 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
---
title: "Weekly"
format: html
params:
refresh_stats: true
csv_save_path: "private"
save_volumes_sharing_status_info: false
---
## About
These data are collected and reported on roughly a weekly basis.
```{r weekly-setup}
#| echo: FALSE
#| message: FALSE
#| warning: FALSE
knitr::opts_chunk$set(echo = FALSE,
message = FALSE,
warning = FALSE)
suppressPackageStartupMessages(library(databraryr))
suppressPackageStartupMessages(library(tidyverse))
# Source functions (quietly)
fl <- list.files(file.path(here::here(), "R"), "*.R",
full.names = TRUE)
p <- purrr::map(fl, suppressPackageStartupMessages(source)) |>
purrr::quietly()
# Login to Databrary
x <- login_db(email = Sys.getenv("DATABRARY_LOGIN"),
password = Sys.getenv("DATABRARY_PASSWORD"),
client_id = Sys.getenv("DATABRARY_CLIENT_ID"),
client_secret = Sys.getenv("DATABRARY_CLIENT_SECRET"),
store = FALSE,
overwrite = FALSE,
vb = TRUE)
# Graphic theme elements
ln_size <- 3
base_size <- 14
color_orange <- "#ec7751"
color_teal <- "#4CAE99"
color_purple <- "#AB00FF"
databrary_theme <-
ggplot2::theme_classic(base_size = base_size) +
ggplot2::theme(axis.title.x = ggplot2::element_blank()) +
ggplot2::theme(
legend.position = "none",
axis.text = ggplot2::element_text(size = ggplot2::rel(0.8),
colour = "black")
) +
ggplot2::theme(axis.line = ggplot2::element_blank()) +
ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5))
```
## Institutions & Authorized Users {-}
<!-- ```{r weekly-load-inst-invest} -->
<!-- # targets::tar_load(inst_invest_csv, store = '../_targets/') -->
<!-- # updated_stats <- inst_invest_csv -->
<!-- targets::tar_load(inst_invest_df, store = '../_targets/') -->
<!-- updated_stats <- inst_invest_df -->
<!-- ``` -->
```{r}
#| label: update-db-stats
#| message: false
#| warning: false
#| results: hide
#|
assertthat::is.string(params$csv_save_path)
assertthat::is.writeable(params$csv_save_path)
fn_inst_invest <- file.path(params$csv_save_path, "institutions-investigators.csv")
x <- assertthat::is.readable(fn_inst_invest)
# Don't refresh data by default; change default in params_weekly.yml
if (params$refresh_stats) {
db_stats_new <- databraryr::get_db_stats()
db_stats_old <- readr::read_csv(fn_inst_invest)
n_rows <- dim(db_stats_old)[1]
updated_stats <- rbind(db_stats_old, db_stats_new[, 1:4])
readr::write_csv(updated_stats, file = fn_inst_invest)
} else {
updated_stats <- readr::read_csv(fn_inst_invest)
}
```
```{r }
#| label: weekly-calculate-delta
n_rows <- dim(updated_stats)[1]
delta_investigators <- updated_stats$investigators[n_rows] - updated_stats$investigators[n_rows - 1]
delta_institutions <- updated_stats$institutions[n_rows] - updated_stats$institutions[n_rows - 1]
# filter NAs
updated_stats <- updated_stats |>
dplyr::filter(!is.na(affiliates),!is.na(investigators),!is.na(affiliates),!is.na(date))
```
<!-- Now, we plot the data. -->
```{r}
#| label: fig-databrary-inst-invest-timeseries
#| fig-cap: "Change over time in authorized investigators and authorizing institutions"
gathered_stats <- updated_stats |>
tidyr::gather(key = "type", value = "count", -date) |>
dplyr::mutate(date = lubridate::as_date(date)) |>
dplyr::select(date, count, type) |>
dplyr::filter(type %in% c('institutions', 'investigators')) |>
dplyr::filter(!is.na(count))
ratio.display <- 550/250
ratio.values <- 3757/max(gathered_stats$count)
# Plot
users_plot <- gathered_stats |>
ggplot(aes(
x = date,
y = count,
color = type,
group = type
)) +
scale_x_date(date_labels = "%Y", date_breaks = '1 year') +
geom_point() +
geom_line(linewidth = ln_size) +
scale_colour_manual(values = c(color_orange, color_teal)) +
ggtitle(paste("Authorizations as of", Sys.Date())) +
ylab("Authorizations") +
databrary_theme +
scale_y_continuous(breaks = c(0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400)) +
coord_fixed(ratio = ratio.values / ratio.display) +
theme(axis.text.x = element_text(angle = 90))
# ggsave("include/img/invest-inst-for-hnds-i.png", width=11, height=6.5, dpi=300)
p <- cowplot::ggdraw(users_plot) +
cowplot::draw_label(
paste0(
"Investigators: ",
updated_stats$investigators[n_rows],
" (+",
delta_investigators,
")"
),
colour = color_teal,
.3,
.6
) +
cowplot::draw_label(
paste0(
"Institutions: ",
updated_stats$institutions[n_rows],
" (+",
delta_institutions,
")"
),
colour = color_orange,
.7,
.3
)
p
```
## Clean up
Logout from Databrary.
```{r}
#| label: clean-up-logout
#| message: false
x <- logout_db()
```