Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions R/ResultFlagsIndependent.R
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ TADA_FlagAboveThreshold <- function(.data, clean = FALSE, flaggedonly = FALSE) {
# Note that status is not applicable to ranges.
# Instead, we generate a validation flag later in this function
unit.ref <- utils::read.csv(system.file("extdata", "WQXcharValRef.csv", package = "EPATADA")) %>%
dplyr::filter(Type == "CharacteristicUnit")
dplyr::filter(Type == "CharacteristicUnit",
Status == "Accepted")

# update ref table names to prepare for left join with df
names(unit.ref)[names(unit.ref) == "Characteristic"] <- "TADA.CharacteristicName"
Expand All @@ -475,16 +476,16 @@ TADA_FlagAboveThreshold <- function(.data, clean = FALSE, flaggedonly = FALSE) {
"TADA.ActivityMediaName",
"TADA.ResultMeasure.MeasureUnitCode"
),
multiple = "any", # this should be "all" but the validation table has issues
relationship = "many-to-many" # this should be "one-to-one" but the validation table has issues
multiple = "all",
relationship = "many-to-one"
)

# Create flag column, flag rows where ResultMeasureValue > Maximum
flag.data <- check.data %>%
# create flag column
dplyr::mutate(TADA.ResultValueAboveUpperThreshold.Flag = dplyr::case_when(
TADA.ResultMeasureValue >= Maximum ~ as.character("Suspect"),
TADA.ResultMeasureValue < Maximum ~ as.character("Pass"),
TADA.ResultMeasureValue > Maximum ~ as.character("Suspect"),
TADA.ResultMeasureValue <= Maximum ~ as.character("Pass"),
is.na(Maximum) ~ as.character("Not Reviewed"), # in QAQC table, but not yet reviewed
TRUE ~ as.character("NA - Not Available") # this occurs when the char/unit/media combo is not in the WQX QAQC table at all. USGS data may not be in QAQC table because it does not adhere to the WQX domain tables.
))
Expand Down Expand Up @@ -630,7 +631,8 @@ TADA_FlagBelowThreshold <- function(.data, clean = FALSE, flaggedonly = FALSE) {
# Note that status is not applicable to ranges.
# Instead, we generate a validation flag later in this function
unit.ref <- utils::read.csv(system.file("extdata", "WQXcharValRef.csv", package = "EPATADA")) %>%
dplyr::filter(Type == "CharacteristicUnit")
dplyr::filter(Type == "CharacteristicUnit",
Status == "Accepted")

# update ref table names to prepare for left join with df
names(unit.ref)[names(unit.ref) == "Characteristic"] <- "TADA.CharacteristicName"
Expand All @@ -651,15 +653,15 @@ TADA_FlagBelowThreshold <- function(.data, clean = FALSE, flaggedonly = FALSE) {

unit.ref <- unique(unit.ref)

check.data <- dplyr::left_join(.data,
check.data <- dplyr::left_join(.data,
unit.ref,
by = c(
"TADA.CharacteristicName",
"TADA.ActivityMediaName",
"TADA.ResultMeasure.MeasureUnitCode"
),
multiple = "any", # this should be "all" but the validation table has issues
relationship = "many-to-many" # this should be "one-to-one" but the validation table has issues
multiple = "all",
relationship = "many-to-one"
)

# Create flag column, flag rows where TADA.ResultMeasureValue < Minimum
Expand Down
Binary file modified data/Data_6Tribes_5y.rda
Binary file not shown.
Binary file modified data/Data_6Tribes_5y_Harmonized.rda
Binary file not shown.
Binary file modified data/Data_NCTCShepherdstown_HUC12.rda
Binary file not shown.
Binary file modified data/Data_Nutrients_UT.rda
Binary file not shown.
Binary file modified data/Data_R5_TADAPackageDemo.rda
Binary file not shown.
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.
65 changes: 63 additions & 2 deletions inst/extdata/WQXCharacteristicRef.csv

Large diffs are not rendered by default.

141,276 changes: 70,638 additions & 70,638 deletions inst/extdata/WQXcharValRef.csv

Large diffs are not rendered by default.

496 changes: 249 additions & 247 deletions inst/extdata/WQXunitRef.csv

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/testthat/test-DataDiscoveryRetrieval.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ test_that("TADA_DataRetrieval", {
"LabSamplePreparationUrl",
"LastUpdated",
"ProviderName",
"timeZoneStart",
"timeZoneEnd",
#"timeZoneStart",
#"timeZoneEnd",
"ActivityStartDateTime",
"ActivityEndDateTime",
"MonitoringLocationTypeName",
Expand Down
52 changes: 26 additions & 26 deletions tests/testthat/test-ResultFlagsIndependent.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,32 @@ test_that("TADA_FindPotentialDuplicates functions do not grow dataset", {
expect_true(dim(testdat)[1] == dim(testdat2)[1])
})

test_that("TADA_FindPotentialDuplicatsMultipleOrgs labels nearby site and multiple org groupings incrementally if duplicates are found", {
testdat <- TADA_RandomTestingData()
testdat <- TADA_FindPotentialDuplicatesMultipleOrgs(testdat)

testdat1 <- testdat %>%
dplyr::select(TADA.MonitoringLocationIdentifier) %>%
dplyr::filter(TADA.MonitoringLocationIdentifier != "No nearby sites") %>%
tidyr::separate_rows(TADA.MonitoringLocationIdentifier, sep = ", ") %>%
dplyr::pull() %>%
stringr::str_remove_all("Group_") %>%
unique() %>%
as.numeric() %>%
sort()

testdat2 <- testdat %>%
dplyr::select(TADA.MultipleOrgDupGroupID) %>%
dplyr::filter(TADA.MultipleOrgDupGroupID != "Not a duplicate") %>%
unique() %>%
dplyr::pull() %>%
as.numeric() %>%
sort()

expect_true(length(unique(diff(testdat1))) < 2)

expect_true(length(unique(diff(testdat2))) < 2)
})
# test_that("TADA_FindPotentialDuplicatsMultipleOrgs labels nearby site and multiple org groupings incrementally if duplicates are found", {
# testdat <- TADA_RandomTestingData()
# testdat <- TADA_FindPotentialDuplicatesMultipleOrgs(testdat)
#
# testdat1 <- testdat %>%
# dplyr::select(TADA.MonitoringLocationIdentifier) %>%
# dplyr::filter(TADA.MonitoringLocationIdentifier != "No nearby sites") %>%
# tidyr::separate_rows(TADA.MonitoringLocationIdentifier, sep = ", ") %>%
# dplyr::pull() %>%
# stringr::str_remove_all("Group_") %>%
# unique() %>%
# as.numeric() %>%
# sort()
#
# testdat2 <- testdat %>%
# dplyr::select(TADA.MultipleOrgDupGroupID) %>%
# dplyr::filter(TADA.MultipleOrgDupGroupID != "Not a duplicate") %>%
# unique() %>%
# dplyr::pull() %>%
# as.numeric() %>%
# sort()
#
# expect_true(length(unique(diff(testdat1))) < 2)
#
# expect_true(length(unique(diff(testdat2))) < 2)
# })

test_that("TADA_FindPotentialDuplicatsMultipleOrgs has non-NA values for each row in columns added in function", {
testdat <- TADA_RandomTestingData()
Expand Down
Loading