Skip to content

Commit

Permalink
Merge pull request #545 from USEPA/QCtable_test
Browse files Browse the repository at this point in the history
Q ctable test
  • Loading branch information
cristinamullin authored Nov 14, 2024
2 parents e88ccf3 + ebca872 commit 2d4bcf6
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 90 deletions.
29 changes: 29 additions & 0 deletions R/Maintenance.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,32 @@ TADA_UpdateExampleData <- function() {
# # [Mozilla Developer HTTP response status codes] (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
# # Replace the broken links with functional ones or remove if no acceptable substitute is available.
# # Rerun code above to verify that df_false contains zero rows.

# # Find Characteristic/Source/Value.Unit Combinations in "WQXcharValRef.csv" with more than one row

# # open unit.ref
# unit.ref <- utils::read.csv(system.file("extdata", "WQXcharValRef.csv", package = "EPATADA")) %>%
# dplyr::filter(
# Type == "CharacteristicUnit",
# Status == "Accepted"
# )
#
# # find Characteristic/Source/Value.Unit combinations with more than one row
# find.dups <- unit.ref %>%
# dplyr::filter(Type == "CharacteristicUnit") %>%
# dplyr::group_by(Characteristic, Source, Value.Unit) %>%
# dplyr::mutate(Min_n = length(unique(Minimum)),
# Max_n = length(unique(Maximum))) %>%
# dplyr::filter(Min_n > 1 |
# Max_n > 1)
#
# # create download path
# download.path <- file.path(Sys.getenv("USERPROFILE"), "Downloads", "WQXcharValRef_multiples.csv")
#
# # create csv to send to WQX team and save in test results folder
# readr::write_csv(find.dups, download.path)
#
# # review csv and send to WQX team to update the validation table
#


4 changes: 2 additions & 2 deletions R/ResultFlagsIndependent.R
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ TADA_FlagAboveThreshold <- function(.data, clean = FALSE, flaggedonly = FALSE) {
"TADA.ResultMeasure.MeasureUnitCode"
),
multiple = "all",
relationship = "many-to-many"
relationship = "many-to-one"
)

# Create flag column, flag rows where ResultMeasureValue > Maximum
Expand Down Expand Up @@ -666,7 +666,7 @@ TADA_FlagBelowThreshold <- function(.data, clean = FALSE, flaggedonly = FALSE) {
"TADA.ResultMeasure.MeasureUnitCode"
),
multiple = "all",
relationship = "many-to-many"
relationship = "many-to-one"
)

# Create flag column, flag rows where TADA.ResultMeasureValue < Minimum
Expand Down
Binary file modified inst/extdata/AKAllotments.dbf
Binary file not shown.
Binary file modified inst/extdata/AKVillages.dbf
Binary file not shown.
Binary file modified inst/extdata/AmericanIndian.dbf
Binary file not shown.
Binary file modified inst/extdata/OKTribe.dbf
Binary file not shown.
Binary file modified inst/extdata/OffReservation.dbf
Binary file not shown.
Binary file modified inst/extdata/VATribe.dbf
Binary file not shown.
162 changes: 81 additions & 81 deletions inst/extdata/WQXcharValRef.csv

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions tests/testthat/test-ResultFlagsIndependent.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ test_that("TADA_FindPotentialDuplicatsMultipleOrgs has non-NA values for each ro
expect_false(any(is.na(testdat$TADA.ResultSelectedMultipleOrgs)))
})

test_that("WQXcharValRef.csv contains only one row for each unique characteristic/source/unit combination for threshold functions", {

unit.ref <- utils::read.csv(system.file("extdata", "WQXcharValRef.csv", package = "EPATADA")) %>%
dplyr::filter(
Type == "CharacteristicUnit",
Status == "Accepted"
)

find.dups <- unit.ref %>%
dplyr::filter(Type == "CharacteristicUnit") %>%
dplyr::group_by(Characteristic, Source, Value.Unit) %>%
dplyr::mutate(Min_n = length(unique(Minimum)),
Max_n = length(unique(Maximum))) %>%
dplyr::filter(Min_n > 1 |
Max_n > 1)

expect_true(nrow(find.dups) == 0)
})

test_that("range flag functions work", {
# use random data
upper <- TADA_RandomTestingData()
Expand Down
7 changes: 0 additions & 7 deletions tests/testthat/test_TADAWaterSciConWorkshopDemo.Rmd

This file was deleted.

0 comments on commit 2d4bcf6

Please sign in to comment.