diff --git a/.Rbuildignore b/.Rbuildignore index e8fd69d..991cd61 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,5 +9,4 @@ ^docs$ ^pkgdown$ ^\.github$ -.*\.xlsx$ -.*\.code-workspace$ +^codecov\.yml$ diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..0ab748d --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,62 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + +name: test-coverage.yaml + +permissions: read-all + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr, any::xml2 + needs: coverage + + - name: Test coverage + run: | + cov <- covr::package_coverage( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + print(cov) + covr::to_cobertura(cov) + shell: Rscript {0} + + - uses: codecov/codecov-action@v5 + with: + # Fail if error if not on PR, or if on PR and token is given + fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} + files: ./cobertura.xml + plugins: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index 3a25cc4..ea9b519 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: SPCreporter Title: Creates Metric Reports using Statistical Process Control in the NHS style -Version: 0.2.0.9004 +Version: 0.2.1 Authors@R: c( person("Tom", "Smith",, "tomsmith_uk@hotmail.com", role = c("aut", "cre")), person("Fran", "Barton",, "fbarton@alwaysdata.net", role = "aut")) diff --git a/R/helper_functions.R b/R/helper_functions.R index cf44d85..80a6e08 100644 --- a/R/helper_functions.R +++ b/R/helper_functions.R @@ -236,9 +236,9 @@ align_rebase_dates <- function(input, measure_data) { #' @noRd get_assurance_type <- function(spc, improvement_direction) { imp_dir <- tolower(improvement_direction) - upl <- spc[["upl"]][1] - lpl <- spc[["lpl"]][1] - target <- spc[["target"]][1] + upl <- tail(spc[["upl"]], 1) + lpl <- tail(spc[["lpl"]], 1) + target <- tail(spc[["target"]], 1) a <- dplyr::case_when( imp_dir == "neutral" ~ "Neutral", diff --git a/README.Rmd b/README.Rmd index 80c80c5..b64c6aa 100644 --- a/README.Rmd +++ b/README.Rmd @@ -24,6 +24,10 @@ knitr::opts_chunk$set( # {SPCreporter} + +[![Codecov test coverage](https://codecov.io/gh/ThomUK/SPCreporter/graph/badge.svg)](https://app.codecov.io/gh/ThomUK/SPCreporter) + + {SPCreporter} is a simple way to add value to your performance reporting using statistical process control. It produces reports similar to this [**example report**](report_examples/My_Example_Report.html). **Help sort signals from noise, and ensure your leadership are talking about signals that matter.** diff --git a/README.md b/README.md index db54b7b..8d69537 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ # {SPCreporter} + + +[![Codecov test +coverage](https://codecov.io/gh/ThomUK/SPCreporter/graph/badge.svg)](https://app.codecov.io/gh/ThomUK/SPCreporter) + + {SPCreporter} is a simple way to add value to your performance reporting using statistical process control. It produces reports similar to this [**example report**](report_examples/My_Example_Report.html). diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true diff --git a/tests/testthat/test-get_assurance_type.R b/tests/testthat/test-get_assurance_type.R index 2b8548c..ee47658 100644 --- a/tests/testthat/test-get_assurance_type.R +++ b/tests/testthat/test-get_assurance_type.R @@ -103,3 +103,21 @@ test_that("it returns correct string in passing conditions", { "PASS_TARG" ) }) + +test_that("it uses the most recent row, not the first, for upl/lpl", { + # Simulates a real ptd_spc output where a single-point first rebase phase + # produces NA limits for that row, while the current (last) rows have valid + # limits. The target column is constant (as ptd_spc stores it) — only + # upl/lpl are NA early on. get_assurance_type must use tail(), not [1], + # matching get_variation_type. + spc <- data.frame( + upl = c(NA, NA, 3), + lpl = c(NA, NA, 1), + target = c(0.5, 0.5, 0.5) # constant target; 0.5 < lpl → PASS for "increase" + ) + + expect_equal( + get_assurance_type(spc, "increase"), + "PASS_TARG" + ) +})