Skip to content

Commit

Permalink
finish working version of 'user_relation_matrices'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Dec 13, 2024
1 parent 08b635a commit b4b8331
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: repometrics
Title: Metrics for Your Code Repository
Version: 0.1.3.024
Version: 0.1.3.025
Authors@R:
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
56 changes: 47 additions & 9 deletions R/analyse-users.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,45 @@
#' \item issue_cmts Comments on issues
#' \item issues Issues opened by user.
#' }
#' @return A `data.frame` of pairwise user logins, and proportions of overlap
#' betwen repositories in the six variables described above.
#' @noRd
user_relation_matrices <- function (user_data) {

user_names <- names (user_data)
user_data <- add_user_login_cols (user_data) |>
combine_user_data ()

Check warning on line 22 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L20-L22

Added lines #L20 - L22 were not covered by tests

cmts <- user_relate_commits (user_data, user_names)
# Pre-processing to name grouping column "repo" and count column "n":
user_data$commit_cmt$repo <-
paste0 (user_data$commit_cmt$org, user_data$commit_cmt$repo)

Check warning on line 26 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L25-L26

Added lines #L25 - L26 were not covered by tests

user_data$followers <-
dplyr::rename (user_data$followers, repo = followers) |>
dplyr::mutate (n = 1L)
user_data$following <-
dplyr::rename (user_data$following, repo = following) |>
dplyr::mutate (n = 1L)

Check warning on line 33 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L28-L33

Added lines #L28 - L33 were not covered by tests

user_data$issue_cmts <-
dplyr::rename (user_data$issue_cmts, repo = org_repo) |>
dplyr::group_by (repo, login) |>
dplyr::summarise (n = sum (num_comments), .groups = "keep")
user_data$issues <- dplyr::rename (user_data$issues, repo = org_repo) |>
dplyr::group_by (repo, login) |>
dplyr::summarise (n = dplyr::n (), .groups = "keep")

Check warning on line 41 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L35-L41

Added lines #L35 - L41 were not covered by tests

overlap <- lapply (names (user_data), function (n) {
user_data [[n]] <- user_relate_fields (user_data, user_names, what = n)
})

Check warning on line 45 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L43-L45

Added lines #L43 - L45 were not covered by tests

res <- dplyr::left_join (overlap [[1]], overlap [[2]], by = c ("login1", "login2")) |>
dplyr::left_join (overlap [[3]], by = c ("login1", "login2")) |>
dplyr::left_join (overlap [[4]], by = c ("login1", "login2")) |>
dplyr::left_join (overlap [[5]], by = c ("login1", "login2")) |>
dplyr::left_join (overlap [[6]], by = c ("login1", "login2"))

Check warning on line 51 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L47-L51

Added lines #L47 - L51 were not covered by tests

return (res)

Check warning on line 53 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L53

Added line #L53 was not covered by tests
}

#' Add 'login' columns to all user data, so each element can be combined.
Expand Down Expand Up @@ -67,17 +98,22 @@ combine_user_data <- function (user_data) {
return (data)

Check warning on line 98 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L98

Added line #L98 was not covered by tests
}

user_relate_commits <- function (user_data, user_names) {
user_relate_fields <- function (user_data, user_names, what = "commits") {

user_combs <- t (combn (user_names, m = 2L))
if (what == "commits") {
user_data [[what]] <- dplyr::rename (user_data [[what]], n = num_commits)
} else if (what == "commit_cmt") {
user_data$commit_cmt$n <- 1L

Check warning on line 107 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L103-L107

Added lines #L103 - L107 were not covered by tests
}

res <- apply (user_combs, 1, function (i) {
cmt1 <- dplyr::filter (user_data$commits, login == i [1]) |>
cmt1 <- dplyr::filter (user_data [[what]], login == i [1]) |>
dplyr::group_by (repo) |>
dplyr::summarise (n1 = sum (num_commits))
cmt2 <- dplyr::filter (user_data$commits, login == i [2]) |>
dplyr::summarise (n1 = sum (n))
cmt2 <- dplyr::filter (user_data [[what]], login == i [2]) |>
dplyr::group_by (repo) |>
dplyr::summarise (n2 = sum (num_commits))
dplyr::summarise (n2 = sum (n))
overlap <- dplyr::inner_join (cmt1, cmt2, by = "repo")

Check warning on line 117 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L110-L117

Added lines #L110 - L117 were not covered by tests

res <- 0
Expand All @@ -88,10 +124,12 @@ user_relate_commits <- function (user_data, user_names) {
return (res)
})

Check warning on line 125 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L119-L125

Added lines #L119 - L125 were not covered by tests

data.frame (
res <- data.frame (
login1 = user_combs [, 1],
login2 = user_combs [, 2],
overlap = res,
what = "commits"
res
)
names (res) [3] <- what

Check warning on line 132 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L127-L132

Added lines #L127 - L132 were not covered by tests

return (res)

Check warning on line 134 in R/analyse-users.R

View check run for this annotation

Codecov / codecov/patch

R/analyse-users.R#L134

Added line #L134 was not covered by tests
}
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/repometrics",
"issueTracker": "https://github.com/ropensci-review-tools/repometrics/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.1.3.024",
"version": "0.1.3.025",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit b4b8331

Please sign in to comment.