Skip to content

Commit f253a2a

Browse files
committed
add 'models/metrics_over_end_dates fns for #87
1 parent ae55eae commit f253a2a

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: repometrics
22
Title: Metrics for Your Code Repository
3-
Version: 0.1.5.015
3+
Version: 0.1.5.016
44
Authors@R:
55
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2172-5265"))

R/cm-collate-all.R

+28
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,31 @@ collate_all_models <- function (path,
5757

5858
return (model_data)
5959
}
60+
61+
metrics_over_end_dates <- function (path, end_date = Sys.Date (), num_years = 3) {
62+
63+
end_dates <- get_end_date_seq (end_date = end_date, num_years = num_years)
64+
65+
metrics_data <- lapply (
66+
end_dates,
67+
function (d) collate_all_metrics (path, end_date = d)
68+
)
69+
names (metrics_data) <- as.character (end_dates)
70+
attr (metrics_data, "period") <- get_repometrics_period ()
71+
72+
return (metrics_data)
73+
}
74+
75+
models_over_end_dates <- function (path, end_date = Sys.Date (), num_years = 3) {
76+
77+
end_dates <- get_end_date_seq (end_date = end_date, num_years = num_years)
78+
79+
models_data <- lapply (
80+
end_dates,
81+
function (d) collate_all_models (path, end_date = d)
82+
)
83+
models_data <- data.frame (do.call (rbind, models_data)) |>
84+
dplyr::mutate (models_data, date = end_dates, .before = 1)
85+
86+
return (models_data)
87+
}

R/utils.R

+12
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ n_per_page_in_tests <- function (n_per_page) {
4747
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
4848
ifelse (is_test_env, 2L, n_per_page)
4949
}
50+
51+
# Fn used in collating all metrics over ranges of end dates:
52+
get_end_date_seq <- function (end_date = Sys.Date (),
53+
period = get_repometrics_period (),
54+
num_years = 3) {
55+
56+
num_periods <- num_years * 365.25 / period
57+
period_seq <- seq_len (num_periods) * period - period
58+
end_dates <- Sys.Date () - period_seq
59+
60+
return (end_dates)
61+
}

codemeta.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"codeRepository": "https://github.com/ropensci-review-tools/repometrics",
99
"issueTracker": "https://github.com/ropensci-review-tools/repometrics/issues",
1010
"license": "https://spdx.org/licenses/GPL-3.0",
11-
"version": "0.1.5.015",
11+
"version": "0.1.5.016",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",

0 commit comments

Comments
 (0)