Skip to content

Commit

Permalink
Merge pull request #50 from ropensci-review-tools/ctbs
Browse files Browse the repository at this point in the history
contributors dashboard plots
  • Loading branch information
mpadge authored Dec 4, 2024
2 parents c82f00d + e94c062 commit 3f7f2b3
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 8 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.2.007
Version: 0.1.2.026
Authors@R:
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
11 changes: 9 additions & 2 deletions R/quarto-dashboard.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ quarto_insert_pkg_name <- function (dir, pkg_name) {
index_qmd <- brio::read_lines (f_index)
i <- grep ("^title\\:", index_qmd)
index_qmd [i] <- paste0 ("title: The {", pkg_name, "} package")
index_qmd <- gsub (
"the XXX repository",
paste ("the", pkg_name, "repository"),
index_qmd,
fixed = TRUE
)
brio::write_lines (index_qmd, f_index)

f_yaml <- fs::path (dir, "_quarto.yml")
Expand All @@ -82,7 +88,7 @@ check_dashboard_arg <- function (data) {
"dependencies_downstream", "gh_repo_workflow", "gitlog",
"issue_comments_from_gh_api", "issues_from_gh_api", "libyears",
"prs_from_gh_api", "releases_from_gh_api", "repo_forks",
"repo_from_gh_api", "repo_stargazers"
"repo_from_gh_api", "repo_stargazers", "contributors"
)
checkmate::assert_names (names (data$cm), identical.to = nms)

Expand Down Expand Up @@ -123,7 +129,8 @@ check_dashboard_arg <- function (data) {
"releases_from_gh_api" = 10L,
"repo_forks" = 2L,
"repo_from_gh_api" = 18L,
"repo_stargazers" = 2L
"repo_stargazers" = 2L,
"contributors" = 3L
)
if (!identical (ncols, ncols_expected)) {
cli::cli_abort (paste0 (
Expand Down
1 change: 1 addition & 0 deletions R/repometrics-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repometrics_data <- function (path, step_days = 1L, num_cores = -1L) {
num_cores = num_cores
)
cm <- cm_data (path)
cm$contributors <- get_all_contribs (cm$contribs_from_log, cm$contribs_from_gh_api)

list (pkgstats = pkgstats, cm = cm)
}
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.2.007",
"version": "0.1.2.026",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
4 changes: 2 additions & 2 deletions inst/extdata/quarto/fn-stats.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Metrics from git commit history "
title: "Git history"
execute:
echo: false
format:
Expand Down Expand Up @@ -276,7 +276,7 @@ loc <- tidyr::pivot_longer (
"ndoc" ~ "doc"
)) |>
dplyr::group_by (date, dir, loc_measure) |>
dplyr::summarise (value = mean (value)) |>
dplyr::summarise (value = mean (value), .groups = "keep") |>
dplyr::ungroup () |>
dplyr::arrange (by = dplyr::desc (date))
Expand Down
221 changes: 220 additions & 1 deletion inst/extdata/quarto/github.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Metrics from GitHub "
title: "Contributors"
execute:
echo: false
format:
Expand All @@ -14,3 +14,222 @@ library (repometrics)
```
This page includes several graphs providing insight into the historical
development of the package.

```{r load-data}
dat <- readRDS ("results.Rds")
```
```{r ctbs-git-data}
ctbs <- dat$cm$contributors
log <- dat$cm$gitlog
log <- log [which (!log$aut_name == "GitHub"), ]
# Insert gh handles in git log:
log$gh_handle <- NA_character_
# Match by log$aut_name:
index <- match (log$aut_name, ctbs$name)
log$gh_handle <- ctbs$gh_handle [index]
# Match by log$aut_email:
index <- which (is.na (log$gh_handle))
index_email <- match (log$aut_email [index], ctbs$email)
log$gh_handle [index] <- ctbs$gh_handle [index_email]
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
if (is_test_env) {
log$gh_handle <- "mpadge"
}
log <- dplyr::mutate (log, date = as.Date (timestamp)) |>
dplyr::mutate (date = as.Date (gsub ("\\-[0-9]{2}$", "-01", date))) |>
dplyr::group_by (gh_handle, date) |>
dplyr::summarise (
nfiles_changed = sum (nfiles_changed),
lines_added = sum (lines_added) - sum (whitespace_added),
lines_removed = sum (lines_removed) - sum (whitespace_removed),
ncommits = dplyr::n (),
.groups = "keep"
) |>
dplyr::ungroup () |>
dplyr::filter (!is.na (gh_handle))
dates <- seq (min (log$date), max (log$date), by = "months")
log_reg <- dplyr::group_by (log, gh_handle) |>
tidyr::complete (date = dates) |>
tidyr::fill () |>
dplyr::arrange (by = date) |>
dplyr::ungroup () |>
tidyr::replace_na (list (
nfiles_changed = 0L,
lines_added = 0L,
lines_removed = 0L,
ncommits = 0L
)) |>
dplyr::group_by (gh_handle) |>
dplyr::mutate (
nfiles_changed = cumsum (nfiles_changed),
lines_added = cumsum (lines_added),
lines_removed = cumsum (lines_removed),
ncommits = cumsum (ncommits),
date = as.Date (date)
) |>
dplyr::ungroup ()
log_reg <- tidyr::pivot_longer (
log_reg,
c ("nfiles_changed", "lines_added", "lines_removed", "ncommits")
)
```

```{r ojs-in-log, echo = FALSE}
ojs_define (log_in = log_reg)
```
```{ojs log-transpose-and-filter}
log = {
return transpose(log_in).map(row => ({
...row,
date: new Date(row.date)
}));
}
viewof varName = Inputs.radio(
new Map([
["Nr. files changed", "nfiles_changed"],
["Lines added", "lines_added"],
["Lines removed", "lines_removed"],
["Nr. commits", "ncommits"],
]),
{
label: "Variable:",
value: "ncommits"
}
)
logFiltered = log.filter(function(row) {
return varName.includes(row.name)
})
```

```{ojs count-contributors}
function getMaxValues(log, varName) {
const ctbs = log.map((item) => item.gh_handle);
const uniqueCtbs = [... new Set(ctbs)];
const maxValues = {};
uniqueCtbs.forEach(handle => {
const logHandle = log.filter(item => item.gh_handle === handle);
if (logHandle.some(item => item.name === varName)) {
maxValues[handle] = Math.max(...logHandle
.filter(item => item.name === varName)
.map(item => item.value));
} else {
console.warn(`No entry found with name ${varName} for handle: ${handle}`);
}
})
const sortedMaxValues = Object.fromEntries(
Object.entries(maxValues).sort((a, b) => b[1] - a[1])
);
return sortedMaxValues;
}
maxValues = getMaxValues(log, varName);
numUniqueCtbs = Object.keys(maxValues).length;
```

```{ojs num-contribs-selector}
viewof numContribs = Inputs.range(
[1, numUniqueCtbs],
{
step: 1,
label: "Num. of Top Contributors",
value: 5
}
)
function reduceLogToCtbs(log, maxValues, numContribs) {
const topCtbs = Object.keys(maxValues).slice(0, numContribs);
const logReduced = log.filter(row => topCtbs.includes(row.gh_handle));
return logReduced;
}
logReduced = reduceLogToCtbs(logFiltered, maxValues, numContribs);
```

```{ojs log-scale-checkbox}
viewof logScale = Inputs.radio(["true", "false"],
{
value: "true",
label: "Log Scale:"
}
)
logType = logScale === "true" ? "log" : "linear";
```



```{ojs log-plot}
Plot.plot({
style: `
overflow: visible;
`,
marginLeft: 90,
marginBottom: 50,
x: { grid: true },
y: { grid: true, type: logType },
marks: [
Plot.ruleY([0]),
Plot.lineY(
logReduced,
{
x: "date",
y: "value",
stroke: "gh_handle",
fontSize: 18,
curve: "basis-open"
},
),
Plot.text(
logReduced,
Plot.selectLast({
x: "date",
y: "value",
z: "gh_handle",
text: "gh_handle",
textAnchor: "start",
dx: 3,
fontSize: 18
})
),
Plot.axisX(
{
fontSize: 14,
label: "",
labelArrow: false
}
),
Plot.axisX(
{
fontSize: 20,
label: "Date",
labelAnchor: "center",
labelOffset: 40,
ticks: []
}
),
Plot.axisY(
{
fontSize: 14,
label: "",
labelArrow: false
}
),
Plot.axisY(
{
fontSize: 24,
label: "Value",
labelAnchor: "center",
labelOffset: 85,
ticks: []
}
),
]
})
```
2 changes: 1 addition & 1 deletion inst/extdata/quarto/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: "Historical Package Development"
---

This site contains stuff.
This is a dashboard for the XXX repository.
4 changes: 4 additions & 0 deletions tests/testthat/helper-cm-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ mock_cm_data <- function () {
do.call (i, list (path = path))
})
names (res) <- gsub ("^cm\\_data\\_", "", data_fns)
res$contributors <- get_all_contribs (
res$contribs_from_log,
res$contribs_from_gh_api
)

fs::dir_delete (path)

Expand Down

0 comments on commit 3f7f2b3

Please sign in to comment.