Skip to content

Commit

Permalink
cc license metrics moved from email template to separate functions + …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
njahn82 committed Feb 14, 2021
1 parent bde9e7a commit d47a256
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

export("%>%")
export(add_attachment_xlsx)
export(cc_compliance_metrics)
export(cc_metrics)
export(cr_compliance_overview)
export(cr_funder_df)
export(cr_license_ind)
Expand Down
51 changes: 51 additions & 0 deletions R/metrics_cc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#' CC license variants metrics overview
#'
#' Presents normalised CC licence variants like BY (absolute and relative)
#'
#' @inheritParams metrics_overview
#'
#' @importFrom dplyr count mutate rename
#'
#' @export
cc_metrics <- function(.md = NULL, .gt = TRUE, .color = "#F3A9BB") {
if(is.null(.md) || !"cc_license_check" %in% names(.md))
stop("No compliance overview data provided, get data using cr_compliance_overview()")
else
out <- .md$cc_license_check %>%
dplyr::count(cc_norm, name = "value") %>%
dplyr::mutate(prop = value /sum(value) * 100) %>%
dplyr::rename(name = cc_norm)
if(.gt == FALSE)
out
else
out %>%
dplyr::mutate(prop_bar = map(prop, ~bar_chart(value = .x, .color = .color))) %>%
ind_table_to_gt()
}

#' CC compliance metrics overview
#'
#' Presents the result of the CC compliance check (absolute and relative)
#'
#' @seealso [license_check()]
#'
#' @inheritParams metrics_overview
#'
#' @importFrom dplyr count mutate rename
#'
#' @export
cc_compliance_metrics <- function(.md = NULL, .gt = TRUE, .color = "#A0A5A9") {
if(is.null(.md) || !"cc_license_check" %in% names(.md))
stop("No compliance overview data provided, get data using cr_compliance_overview()")
else
out <- .md$cc_license_check %>%
dplyr::count(check_result, name = "value") %>%
dplyr::mutate(prop = value /sum(value) * 100) %>%
dplyr::rename(name = check_result)
if(.gt == FALSE)
out
else
out %>%
dplyr::mutate(prop_bar = map(prop, ~bar_chart(value = .x, .color = .color))) %>%
ind_table_to_gt()
}
2 changes: 1 addition & 1 deletion R/metrics_overview.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ metrics_overview <- function(.md = NULL, .gt = TRUE, .color = "#00A4A7") {
tidyr::pivot_longer(!n) %>%
dplyr::mutate(prop = value / n * 100) %>%
dplyr::select(-n)
if(.gt != TRUE)
if(.gt == FALSE)
return(out)
else
out %>%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ indexing_status(dois = params$dois, .md = params$cr_overview)

### Überblick: Crossref-Metadaten

```{r, echo=FALSE}
```{r metrics_overview}
metrics_overview(params$cr_overview)
```

Expand All @@ -41,24 +41,14 @@ metrics_overview(params$cr_overview)

#### Überblick Lizenzbedingungen

```{r}
my_df$cc_license_check %>%
count(cc_norm, name = "value") %>%
mutate(prop = value /sum(value) * 100) %>%
rename(name = cc_norm) %>%
mutate(prop_bar = map(prop, ~bar_chart(value = .x, .color = "#F3A9BB"))) %>%
ind_table_to_gt()
```{r cc_metrics}
cc_metrics(params$cr_overview)
```

#### Ergebnis Compliance Check

```{r}
my_df$cc_license_check %>%
count(check_result, name = "value") %>%
mutate(prop = value /sum(value) * 100) %>%
rename(name = check_result) %>%
mutate(prop_bar = map(prop, ~bar_chart(value = .x, .color = "#A0A5A9"))) %>%
ind_table_to_gt()
cc_compliance_metrics(params$cr_overview)
```

Im beigefügten Excel-Spreadsheet dokumentiert das Blatt **CC-Lizenzen** je Artikel das Ergebnis der Überprüfung.
Expand Down
22 changes: 22 additions & 0 deletions man/cc_compliance_metrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/cc_metrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions tests/testthat/test-metrics_indexing_status.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,37 @@ test_that("metrics_overview works", {
test_that("metrics_overview is reported", {
expect_is(metrics_overview(out), "gt_tbl")
})

# cc compliance

test_that("cc_metrics works", {
a <- cc_metrics(out, .gt = FALSE)

# dimensions and type
expect_equal(ncol(a), 3)
expect_s3_class(a, "data.frame")

expect_error(metrics_overview())
expect_error(metrics_overview("kdkd"))
})

test_that("cc_metrics are reported", {
expect_is(metrics_overview(out), "gt_tbl")
})

test_that("cc_compliance_metrics works", {
a <- cc_metrics(out, .gt = FALSE)

# dimensions and type
expect_equal(ncol(a), 3)
expect_s3_class(a, "data.frame")

expect_error(metrics_overview())
expect_error(metrics_overview("kdkd"))
})

test_that("cc_compliance_metrics are reported", {
expect_is(metrics_overview(out), "gt_tbl")
})


0 comments on commit d47a256

Please sign in to comment.