1
- # ' Start quarto dashboard with results of main \link{repometrics_data_pkg }
1
+ # ' Start quarto dashboard with results of main \link{repometrics_data_repo }
2
2
# ' function.
3
3
# '
4
- # ' @param data Results of main \link{repometrics_data_pkg} function applied to
5
- # ' one package.
4
+ # ' @param data_repo Data on repository as returned from
5
+ # ' \link{repometrics_data_repo} function applied to one package.
6
+ # ' @param data_users Data on repository developers ("users" in GitHub terms), as
7
+ # ' returned from \link{repometrics_data_user} function applied to one package.
6
8
# ' @param action One of "preview", to start and open a live preview of the
7
9
# ' dashboard website, or "render" to render a static version without previewing
8
10
# ' or opening.
9
11
# ' @return (Invisibly) Path to main "index.html" document of quarto site. Note
10
12
# ' that the site must be served with `action = "preview"`, and will not work by
11
13
# ' simply opening this "index.html" file.
12
14
# ' @export
13
- repometrics_dashboard <- function (data , action = " preview" ) {
15
+ repometrics_dashboard <- function (data_repo , data_users , action = " preview" ) {
14
16
15
- check_dashboard_arg (data )
16
- data $ pkgstats <- timestamps_to_dates (data $ pkgstats )
17
+ check_dashboard_arg (data_repo )
18
+ data_repo $ pkgstats <- timestamps_to_dates (data_repo $ pkgstats )
17
19
18
20
requireNamespace (" brio" )
21
+ requireNamespace (" jsonlite" )
19
22
requireNamespace (" quarto" )
20
23
requireNamespace (" withr" )
21
24
@@ -25,16 +28,44 @@ repometrics_dashboard <- function (data, action = "preview") {
25
28
path_src <- system.file (" extdata" , " quarto" , package = " repometrics" )
26
29
path_dest <- fs :: path (fs :: path_temp (), " quarto" )
27
30
dir <- fs :: dir_copy (path_src , path_dest , overwrite = TRUE )
28
- saveRDS (data , fs :: path (dir , " results-pkg.Rds" ))
31
+ saveRDS (data_repo , fs :: path (dir , " results-repo.Rds" ))
32
+ saveRDS (data_users , fs :: path (dir , " results-users.Rds" ))
29
33
30
- pkg_name <- data $ pkgstats $ desc_data $ package [1 ]
34
+ dat_user_network <- get_user_network (data_users )
35
+ jsonlite :: write_json (dat_user_network , fs :: path (dir , " results-user-network.json" ))
36
+
37
+ pkg_name <- data_repo $ pkgstats $ desc_data $ package [1 ]
31
38
quarto_insert_pkg_name (dir , pkg_name )
32
39
33
40
withr :: with_dir (dir , {
34
41
do.call (eval (parse (text = quarto_action )), list ())
35
42
})
36
43
}
37
44
45
+ get_user_network <- function (data_users ) {
46
+
47
+ rels <- user_relation_matrices (data_users )
48
+ index <- which (! grepl (" ^login" , names (rels )))
49
+ relmat <- apply (as.matrix (rels [, index ]), 2 , function (i ) i / sum (i ))
50
+ if (! is.matrix (relmat )) {
51
+ relmat <- matrix (relmat , nrow = 1L )
52
+ }
53
+ relmat [which (is.na (relmat ))] <- 0
54
+ relvec <- 20 * rowSums (relmat ) / ncol (relmat )
55
+ reldf <- cbind (rels [, 1 : 2 ], value = relvec )
56
+ names (reldf ) <- c (" source" , " target" , " value" )
57
+
58
+ netdat <- list (
59
+ nodes = data.frame (
60
+ id = unique (c (rels $ login1 , rels $ login2 )),
61
+ group = 1L
62
+ ),
63
+ links = reldf
64
+ )
65
+
66
+ return (netdat )
67
+ }
68
+
38
69
timestamps_to_dates <- function (data ) {
39
70
40
71
lapply (data , function (i ) {
0 commit comments